/******************************************* * Section : 15 * Machine No. : N * Roll No. : 18CS100XY * Name : Soumyajit Dey, Aritra Hazra * Assignment No : 7 * Description : Restaurent Order and Service ********************************************/ #include #include #define MAX_CUSTOMER 50 #define MAX_ITEM 5 #define MAX_NAME 11 #define PRECISION 0.000001 struct order{ char name[MAX_NAME]; int item[MAX_ITEM]; }; int main() { char choice = ' ', delReq, deleteCustName[MAX_NAME]; int custID = 0, i, j, k, deleteCustID, itemReq; struct order custOrder[MAX_CUSTOMER], tempCustOrder; double itemRevenue[MAX_ITEM], orderRevenue[MAX_CUSTOMER], targetAvgRevenue, tempOrderRevenue; printf("\n===== Welcome to PDS Restaurant! =====\n"); printf("-- There are FIVE Items in MENU: Item-1, Item-2, Item-3, Item-4 and Item-5\n"); printf("-- Enter Per-Plate Revenue (Profit) for these Five Items: "); for(i=0; i 1) && ( (targetAvgRevenue - (orderRevenue[custID]+orderRevenue[custID-1]+orderRevenue[custID-2])/3) > PRECISION ) ){ j = custID - 3; while(j>=0){ if(j > 1){ if( (targetAvgRevenue - (orderRevenue[custID]+orderRevenue[j-1]+orderRevenue[j-2])/3) > PRECISION ){ j = j-3; } else if( (targetAvgRevenue - (orderRevenue[custID]+orderRevenue[j]+orderRevenue[j-1])/3) > PRECISION ){ j = j-2; } else if( (targetAvgRevenue - (orderRevenue[custID]+orderRevenue[j]+orderRevenue[j+1])/3) > PRECISION ){ j = j-1; } else{ break; } } else if(j == 1){ if( (targetAvgRevenue - (orderRevenue[custID]+orderRevenue[j]+orderRevenue[j-1])/3) > PRECISION ){ j = j-2; } else if( (targetAvgRevenue - (orderRevenue[custID]+orderRevenue[j]+orderRevenue[j+1])/3) > PRECISION ){ j = j-1; } else{ break; } } else if(j == 0){ if( (targetAvgRevenue - (orderRevenue[custID]+orderRevenue[j]+orderRevenue[j+1])/3) > PRECISION ){ j = j-1; } else{ break; } } } /* Inserting the Order in Proper Loaction keeping Target Average Revenue */ if(j>=0){ tempCustOrder = custOrder[custID]; tempOrderRevenue = orderRevenue[custID]; for(k=custID-1; k>=j; k--){ custOrder[k+1] = custOrder[k]; orderRevenue[k+1] = orderRevenue[k]; } custOrder[j] = tempCustOrder; orderRevenue[j] = tempOrderRevenue; custID++; } else{ //customer order not considered printf("*** Target Revenue NOT Met ... Order Cancelled! ***\n");; } } else{ // first two customer request always entered custID++; } printf("+++ Pending Order List +++\n"); for(j=0; j 0) printf("\tItem %d --> Quantity = %d\n", i+1, custOrder[j].item[i]); else printf("\tItem %d --> NOT Ordered\n", i+1); } } break; case 'b': /* Deleting Order */ case 'B': printf("*** Deleting Order for Customer ***\n"); if(custID > 0){ printf("-- Enter Customer ID (enter any negative number, if forgotten): "); scanf("%d", &deleteCustID); if(deleteCustID < 0){ printf("-- Enter Customer Name: "); scanf("%s", deleteCustName); for(j=0; j 0) printf("\tItem %d --> Quantity = %d\n", i+1, custOrder[deleteCustID].item[i]); else printf("\tItem %d --> NOT Ordered\n", i+1); } printf("-- Want to delete for sure (press Y/N)? "); scanf(" %c", &delReq); if(delReq == 'Y' || delReq == 'y'){ for(j=deleteCustID; j 0) printf("\tItem %d --> Quantity = %d\n", i+1, custOrder[j].item[i]); else printf("\tItem %d --> NOT Ordered\n", i+1); } } } else{ printf("*** NO Pending Order Exists! ***\n"); } break; case 'c': /* Serve Order */ case 'C': printf("*** Served Order Details ***\n"); if(custID > 0){ printf("-- Customer Name: %s\n", custOrder[0].name); for(i=0; i 0) printf("\tItem %d --> Quantity = %d\n", i+1, custOrder[0].item[i]); else printf("\tItem %d --> NOT Ordered\n", i+1); } for(j=0; j 0) printf("\tItem %d --> Quantity = %d\n", i+1, custOrder[j].item[i]); else printf("\tItem %d --> NOT Ordered\n", i+1); } } } else{ printf("*** NO Order Remains to Serve! ***\n"); } break; case 'd': /* Display Statistics */ case 'D': printf("*** Item Requirement Statistics ***\n"); for(i=0; i Requirement = %d\n", i+1, itemReq); } break; case 'e': /* Exit or Terminate */ case 'E': printf("\n===== Good-Bye! Have a Nice Day! =====\n"); break; default: /* Wrong Choice */ printf("*** Wrong Choice Entered! ***\n"); break; } } return 0; }