Professional Documents
Culture Documents
Workshop7 Program3.c
Workshop7 Program3.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int menu()
{
int choice;
printf("\n==================================== M
E N U ======================================");
printf("\n| 1- Add a new soft drink. Press: 1
|");
printf("\n| 2- Printing out items which belong to a same origin.
(Country) Press: 2 |");
printf("\n| 3- Printing out items whose volumes are between
[(ml)__and__(ml)]. Press: 3 |");
printf("\n| 4- Printing the list in ascending order based on volumes then
prices. Press: 4 |");
printf("\n| 5- Quit. Press: 5 |");
printf("\n=========================================
==========================================\n");
printf("\nEnter Your Choice: ");
scanf("%d", &choice);
fflush(stdin);
return choice;
}
int isFull(int n)
{
return n == MAXN;
}
int isEmpty(int n)
{
return n == 0;
}
This study source was downloaded by 100000848085910 from CourseHero.com on 06-27-2022 01:48:47 GMT -05:00
https://www.coursehero.com/file/84158257/Workshop7-Program3c/
char* lTrim(char s[])
{
int i = 0;
while (s[i] == ' ') i++;
if (i > 0) strcpy(&s[0], &s[i]);
return s;
}
This study source was downloaded by 100000848085910 from CourseHero.com on 06-27-2022 01:48:47 GMT -05:00
https://www.coursehero.com/file/84158257/Workshop7-Program3c/
printf("Name: ");
scanf("%[^\n]", names);
fflush(stdin);
printf("Made in: ");
scanf("%[^\n]", makes);
fflush(stdin);
printf("Volume (ml): ");
scanf("%d", &volumes);
printf("Price (VND): ");
scanf("%d", &prices);
printf("Duration (Days): ");
scanf("%d", &durations);
printf("\nAdded!\n");
nameStr(names);
nameStr(makes);
strcpy(name[*pn], names);
strcpy(make[*pn], makes);
volume[*pn] = volumes;
price[*pn] = prices;
duration[*pn] = durations;
(*pn)++;
}
This study source was downloaded by 100000848085910 from CourseHero.com on 06-27-2022 01:48:47 GMT -05:00
https://www.coursehero.com/file/84158257/Workshop7-Program3c/
{
printf("\n>>List of Soft Drink base on %s:\n", make[i]);
printList(name, make, volume, price, duration, i);
check = 1;
}
}
if (check == 0)
printf("\nThere are not any soft drinks on the list based on
%s!!!\n", makes);
}
This study source was downloaded by 100000848085910 from CourseHero.com on 06-27-2022 01:48:47 GMT -05:00
https://www.coursehero.com/file/84158257/Workshop7-Program3c/
{
if (price[j]+duration[j] < price[j-1]+duration[j-1])
{
char transName[MAXL];
strcpy(transName, name[j-1]);
strcpy(name[j-1], name[j]);
strcpy(name[j], transName);
char transMake[MAXL];
strcpy(transMake, make[j-1]);
strcpy(make[j-1], make[j]);
strcpy(make[j], transMake);
int transVol;
transVol = volume[j-1];
volume[j-1] = volume[j];
volume[j] = transVol;
int transPri;
transPri = price[j-1];
price[j-1] = price[j];
price[j] = transPri;
int transDur;
transDur = duration[j-1];
duration[j-1] = duration[j];
duration[j] = transDur;
}
}
}
for (i = 0; i < *pn; i++)
printList(name, make, volume, price, duration, i);
}
int main()
{
int userChoice, check = 1;
char name[MAXN][MAXL];
char make[MAXN][MAXL];
int volume[MAXN];
int price[MAXN];
int duration[MAXN];
int n = 0;
do
{
userChoice = menu();
This study source was downloaded by 100000848085910 from CourseHero.com on 06-27-2022 01:48:47 GMT -05:00
https://www.coursehero.com/file/84158257/Workshop7-Program3c/
switch(userChoice)
{
case 1:
if (isFull(n))
printf("\nSorry! The List is full!\n");
else
addSoftDrink(name, make, volume, price,
duration, &n);
break;
case 2:
if (isEmpty(n))
printf("\nSorry! The List is empty!\n");
else
printBaseMake(name, make, volume, price,
duration, n);
break;
case 3:
if (isEmpty(n))
printf("\nSorry! The List is empty!\n");
else
printBaseVol(name, make, volume, price,
duration, n);
break;
case 4:
if (isEmpty(n))
printf("\nSorry! The List is empty!\n");
else
printAsc(name, make, volume, price, duration,
&n);
break;
default:
if (userChoice == 5)
check = 0;
else
printf("\n>>Wrong Input!!!\n");
}
}
while (check == 1);
printf("\nGood Bye!");
getch();
}
This study source was downloaded by 100000848085910 from CourseHero.com on 06-27-2022 01:48:47 GMT -05:00
https://www.coursehero.com/file/84158257/Workshop7-Program3c/
Powered by TCPDF (www.tcpdf.org)