Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- #include <stdlib.h>
- #include <string.h>
- #define f fflush(stdin);
- struct data{
- char name[100];
- int qty;
- int ctr;
- struct data *next, *prev;
- };
- struct data *head=NULL, *tail, *curr, *temp;
- void add(char name[], int qty, int ctr){
- curr = (struct data*) malloc(sizeof(struct data));
- strcpy(curr->name, name);
- curr->qty = qty;
- curr->ctr = ctr;
- curr->next = NULL;
- curr->prev = NULL;
- if(head == NULL){
- head = tail = curr;
- }else{
- curr->next = head;
- head = curr;
- }
- }
- void display(char name[], int qty){
- int ctr=0;
- temp = head;
- printf("-------+--------------------------------+-----------\n");
- printf("| No. | Name of Parts | Quantity |\n");
- printf("-------+--------------------------------+-----------\n");
- while(temp != NULL){
- ctr++;
- printf("| %2d. | %-31s| %-9d|\n", ctr, temp->name, temp->qty);
- temp = temp->next;
- }
- printf("-------+--------------------------------+-----------");
- getchar();
- }
- void apus(int ctr){
- temp = head;
- int num;
- if(temp == NULL){
- printf("\n\n\n--- There is No Order in The List ---");
- getchar();
- }else{
- printf("\n\n Input Number of The Order [1..%d]: ", ctr);
- scanf("%d", &num); fflush(stdin);
- while(temp != NULL){
- if(temp->ctr == num) break;
- temp = temp->next;
- }
- system("cls");
- if(temp == head){
- head = head->next;
- free(temp);
- if(head != NULL){
- head->prev = NULL;
- }
- }else if(temp == tail){
- tail = tail->prev;
- free(temp);
- tail->next = NULL;
- }else{
- temp->prev->next = temp->next;
- temp->next->prev = temp->prev;
- free(temp);
- }
- }
- }
- int main(){
- int menu;
- char name[100];
- int qty;
- int ctr=0;
- do{
- system("cls");
- puts("BLUE MOTORCYCLE PARTS");
- puts(".....................\n");
- puts("1. View Order List");
- puts("2. Add New Order");
- puts("3. Take Order");
- puts("4. Exit\n");
- do{
- printf(">> Input choice :");
- scanf("%d", &menu);fflush(stdin);
- }while(menu<1 || menu>4);
- if(menu ==1){
- system("cls");
- display(name,ctr);
- getchar();
- }
- if(menu ==2){
- do{
- printf("\nInput Name of Motorcycle's Part [3..30]: ");
- gets(name);
- }while(strlen(name)<3 || strlen(name)>30);
- do{
- printf("\nInput Quantity of The Motorcycle's Part [1..20]: ");
- scanf("%d", &qty);f
- }while(qty<1 || qty>20);
- ++ctr;
- add(name, qty, ctr);
- printf("\n\n\n--- Add New Order Success ---");
- getchar();
- }
- if(menu ==3){
- display(name,ctr);
- apus(ctr);
- }
- }while(menu != 4);
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement