/********************************************* * Section : 15 * Machine No. : N * Roll No. : 19CS100XY * Name : Aritra Hazra * Assignment No : 7 * Description : Transactions in Medical Store *********************************************/ #include #include #include //#include #define MAX 10000 #define MAXID 10 #define MAXNAME 100 #define MAXDAY 2 #define MAXMONTH 2 #define MAXYEAR 4 #define MAXDATE (MAXDAY + MAXMONTH + MAXYEAR + 3) typedef struct medicine { char medID[MAXID]; char medName[MAXNAME]; char medMaker[MAXNAME]; char mfgDate[MAXDATE], expDate[MAXDATE]; unsigned int quantity; double pricePerQuantity; int type; /* 0 --> liquid, 1 --> tablet, 2-> capsule, 3 --> injection, 4 --> inhale, 5 --> external-use */ } medInfo; void printMedicineType (int t) { switch(t) { case 0: printf("Liquid"); break; case 1: printf("Tablet"); break; case 2: printf("Capsule"); break; case 3: printf("Injection"); break; case 4: printf("Inhale"); break; case 5: printf("External"); break; default: printf("Unknown"); break; } } int main () { medInfo med[MAX], buyMed[MAX]; int medCount = 0, i, j, k, q, t, yearInt, monthInt, dayInt, discardFlag; double total, billTotal; char day[MAXDAY+1], month[MAXMONTH+1], year[MAXYEAR+1], name[MAXNAME]; char choice = ' ', refill, buy, discard; while(choice != 'e'){ printf("\n===== !! Welcome to Wonderland Medical Store !! =====\n"); printf("-- Options:\n\t(a) Order/Refill Medicine,\n\t(b) Buy Medicine,\n\t(c) In-store Medicine Statistics,\n\t(d) Discard Medicines,\n\t(e) Exit.\n"); printf("-- Enter a Choice: "); scanf(" %c", &choice); refill = 'y'; buy = 'y'; discard = ' '; switch(choice){ case 'a': /* Order/Refill Medicine */ case 'A': while (refill == 'y') { printf("++ Enter Medicine Details ++\n"); printf("\t-- Enter Medicine ID: "); scanf("%s", med[medCount].medID); printf("\t-- Enter Medicine Name: "); scanf("%s", med[medCount].medName); printf("\t-- Enter Medicine Maker's Name: "); scanf("%s", med[medCount].medMaker); printf("\t-- Enter Manufacturing Date (in DD/MM/YYYY Format): "); scanf("%s/%s/%s", day, month, year); strcpy(med[medCount].mfgDate, day); strcat(med[medCount].mfgDate, "/"); strcat(med[medCount].mfgDate, month); strcat(med[medCount].mfgDate, "/"); strcat(med[medCount].mfgDate, year); med[medCount].mfgDate[MAXDATE-1] = '\0'; printf("\t-- Enter Expiry Date (in DD/MM/YYYY Format): "); scanf("%s/%s/%s", day, month, year); strcpy(med[medCount].expDate, day); strcat(med[medCount].expDate, "/"); strcat(med[medCount].expDate, month); strcat(med[medCount].expDate, "/"); strcat(med[medCount].expDate, year); med[medCount].expDate[MAXDATE-1] = '\0'; printf("\t-- Enter Quantity (Number of Medicines): "); scanf("%u", &(med[medCount].quantity)); printf("\t-- Enter Price Per Quantity (in INR): "); scanf("%lf", &(med[medCount].pricePerQuantity)); printf("\t-- Enter Medicine Type (0: Liquid, 1: Tablet, 2: Capsule, 3: Injection, 4: Inhale, 5: External): "); scanf("%d", &(med[medCount].type)); medCount ++; printf("Want to Add more Medicine in Wonderland-Store? (Type 'y' for YES)? "); scanf(" %c", &refill); } break; case 'b': /* Buy Medicine */ case 'B': billTotal = 0; j=0; while (buy == 'y') { printf("\t-- Enter Medicine Name: "); scanf("%s", name); printf("\t-- Enter Quantity (Number of Medicines to Buy): "); scanf("%u", &q); printf("\t-- Enter Medicine Type (0: Liquid, 1: Tablet, 2: Capsule, 3: Injection, 4: Inhale, 5: External): "); scanf("%d", &t); for (i=0; i= q) { buyMed[j] = med[i]; buyMed[j].quantity = q; med[i].quantity = med[i].quantity - q; if(med[i].quantity == 0) { for (k=i+1; k