Answer To: ITECH5403 – Comparative Programming Languages School of Engineering, Information Technology and...
Neha answered on Oct 07 2021
67573 - pizza parallel/C Language/orders.txt
67573 - pizza parallel/C Language/PizzaShop.c
#include
#include
#include
#include
#include
const char *creds = "pizzaorders.txt";
char sizes[4][8] = {"None", "Small", "Medium", "Large"};
int price[4] = {0, 5, 8, 12};
char toppings[8][10] = {"None", "Bacon", "Olives", "Ham", "Mushrooms", "pineapple", "Salami", "Anchovies"};
char ortype[3][8] = {"None", "Collect", "Deliver"};
int order[10][8]= {{0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}};
void start0();
void main(){
start0();
}
void start1();
void start0(){
printf("\n-------------------------------------------------------------------------");
printf("\n--------------------- Welcome to Pizza Shop ---------------------");
printf("\n-------------------------------------------------------------------------");
printf("\nMain Menu - ");
printf("\n Option 1.) Add Order.");
printf("\n Option 2.) View Orders.");
printf("\n Option 3.) Exit.");
start1();
}
void start3();
void views();
void endprog();
void start1() {
printf("\nPlease Enter an Option: ");
int ip0a;
scanf("%d", &ip0a);
if (ip0a == 1) {
start3();
} else if (ip0a == 2){
views();
} else if ( ip0a == 3){
endprog();
} else {
printf("\n\nPlease Enter the Correct Option.");
start1();
}
}
void endprog() {
printf("\nDo you really want to QUIT ?");
printf("\n[Y]es / [N]o : ");
char aq5[3];
gets(aq5);
if (strcmp(strupr(aq5), "Y")==0){
printf("\n Thanks for using Pizza Shop Application...!\n");
exit(0);
}
else if (strcmp(strupr(aq5), "N")==0){
printf(" ");
system("cls");
start0();
} else {
printf("\n\nPlease Enter Correct Option...");
endprog();
}
}
void start3();
void start2(){
printf("\nAdd a new Order...");
start3();
}
void sizeselect();
void start3(){
printf("\nPlease Select an Option for pizza Size from below: ");
printf("\n Option 1.) Small pizza - $5 ");
printf("\n Option 2.) Medium pizza - $8 ");
printf("\n Option 3.) Large pizza - $12 ");
sizeselect();
}
int psize=0;
void sizesave();
void sizeselect(){
printf("\nPlease Enter an Option for pizza Size : ");
int ip1a;
scanf("%d", &ip1a);
switch (ip1a) {
case 1:
psize = 1;
sizesave();
break;
case 2:
psize = 2;
sizesave();
break;
case 3:
psize = 3;
sizesave();
break;
default:
printf("\nPlease Enter the Correct Option.");
sizeselect();
break;
}
}
int i;
void toppingselect();
void sizesave() {
for (int j = 0; j<9; j++) {
int s = order[j][0];
if (s != 0) {
i++;
}
}
order[i][0] = psize;
printf("\n\nAll pizzas come on a 'Tomato base'(for our pizza Shop this is the only option),");
printf("\nand have the topping 'Cheese' by default, at no Extra cost.");
printf("\nYou may Choose up to a Maximum of '4' additional toppings from the following list :- ");
printf("\n(Each topping adds an additional $1 to the price of the pizza.)");
printf("\nPlease Select an Option for Toppings from below: ");
printf("\n Option 0.) No Topping");
printf("\n Option 1.) Bacon");
printf("\n Option 2.) Olives");
printf("\n Option 3.) Hum");
printf("\n Option 4.) Mushrooms");
printf("\n Option 5.) pineapple");
printf("\n Option 6.) Salami");
printf("\n Option 7.) Anchovies\n");
toppingselect();
}
void showpizza();
void toppingselect() {
printf("\nPlease Enter an Option between '0' and '7' : ");
printf("\nPlease Enter First topping : ");
int topping1;
scanf("%d", &topping1);
printf("\nPlease Enter Second topping : ");
int topping2;
scanf("%d", &topping2);
printf("\nPlease Enter Third topping : ");
int topping3;
scanf("%d", &topping3);
printf("\nPlease Enter Fourth topping : ");
int topping4;
scanf("%d", &topping4);
if (((topping1 >= 0) && (topping1 <= 7)) && ((topping2 >= 0) && (topping2 <= 7)) &&
((topping3 >= 0) && (topping3 <= 7)) && ((topping4 >= 0) && (topping4 <= 7))){
order[i][1] = topping1;
order[i][2] = topping2;
order[i][3] = topping3;
order[i][4] = topping4;
showpizza();
} else {
printf("\nPlease Enter Valid Toppings Options...");
toppingselect();
}
}
void pizzacount();
void showpizza() {
printf("\nYour Customized pizzas are: ");
for(int j = 0;j < 9; j++){
int s = order[j][0];
if (s != 0) {
printf("\n\n Pizza Size: %s, Toppings: %s, %s, %s, %s.\n", sizes[order[j][0]], toppings[order[j][1]],
toppings[order[j][2]], toppings[order[j][3]], toppings[order[j][4]]);
}
if (order[j][5] != 0) {
printf(" Quantity: %d.", order[j][5]);
}
}
pizzacount();
}
void check0();
void pizzacount(){
printf("\nPlease Enter number of Pizzas: ");
int pizzano;
scanf("%d", &pizzano);
order[i][5] = pizzano;
check0();
}
void ordertype();
void check0() {
printf("\nWould you like to Add another Pizza in your Order ? \n([Y]es/[N]o)");
char ans[3];
gets(ans);
if (strcmp(strupr(ans), "Y")==0) {
start3();
} else if (strcmp(strupr(ans), "N")==0){
ordertype();
} else {
printf("\n\nPlease Enter Valid Option...");
check0();
}
}
void enterdetails();
void ordertype() {
printf("\nWill you [C]ollect your Order from Shop or want to get [D]elivered to you ?");
char ans[3];
gets(ans);
for (int j=0; j<9; j++){
int s = order[j][0];
if (s != 0) {
if (strcmp(strupr(ans), "C")==0){
order[j][6] = 1;
order[j][7] = 0;
} else if (strcmp(strupr(ans), "D")==0){
order[j][6] = 2;
order[j][7] = 8;
} else {
printf("\n\nPlease Enter Valid Option.");
ordertype();
}
}
}
enterdetails();
}
char name[50], address[100] = "Not Applicable";
char phoneno[17];
void showorder();
void enterdetails() {
printf("\nPlease enter your Name: ");
gets(name);
printf("\nPlease enter your phone Number: ");
gets(phoneno);
if(order[0][6] == 2){
printf("\nPlease enter delivery Address: ");
gets(address);
}
showorder();
}
void question();
void showorder() {
printf("\n--------------------- Order Invoice ---------------------");
printf("\nName: %s\nPhone Number: %s \nAddress: %s.", name, phoneno, address);
char invoicep1[300];
sprintf(invoicep1, "Name: %s\nPhone Number: %s\nAddress: %s.", name, phoneno, address);
int totalprice = 0;
int k = 1;
char invoicep2[10][500];
for (int j=0; j<9; j++ ) {
int s = order[j][0];
if (s != 0) {
for (int k=1; k<=4; k++) {
if (order[j][k] != 0) {
totalprice = totalprice + order[j][5];
}
}
totalprice = totalprice + (price[order[j][0]] * order[j][5]);
sprintf(invoicep2[j], "\n%d.) Pizza size: %s, Price: $%d, Number of Pizzas: %d, \n Toppings: %s, %s, %s, %s.",
k, sizes[order[j][0]], price[order[j][0]], order[j][5], toppings[order[j][1]],
toppings[order[j][2]], toppings[order[j][3]], toppings[order[j][4]]);
printf("\n\n%d.) Pizza size: %s, Price: $%d, Number of Pizzas: %d, \n Toppings: %s, %s, %s, %s.",
k, sizes[order[j][0]], price[order[j][0]], order[j][5], toppings[order[j][1]],
toppings[order[j][2]], toppings[order[j][3]], toppings[order[j][4]]);
k++;
}
}
printf("\n\n1$ charged for Each Topping on each pizza.\nOrder Type: %s.", ortype[order[0][6]]);
char invoicep3[80];
sprintf(invoicep3, "\n1$ charged for Each Topping on each pizza.\nOrder Type: %s.", ortype[order[0][6]]);
char invoicep4[50];
sprintf(invoicep4, " ");
printf(" ");
if ((totalprice <= 30) && order[0][6]==2){
totalprice = totalprice + 8;
printf("\n\n(Additional $8 Delivery Charge for Total Amount below $30.)");
sprintf(invoicep4, "\n(Additional $8 Delivery Charge for Total Amount below $30.)");
}
char invoicep5[30];
sprintf(invoicep5, "\nTotal Amount: $%d.\n", totalprice);
printf("\n\nTotal Amount: $%d.\n\n", totalprice);
char save[5000];
sprintf(save, strcat(save, invoicep1));
for (int j=0; j<9; j++){
if (invoicep2[j] != NULL ){
sprintf(save, strcat(save, invoicep2[j]));
}
}
sprintf(save, strcat(save, invoicep3));
sprintf(save, strcat(save, invoicep4));
sprintf(save, strcat(save, invoicep5));
FILE* fp;
fp = fopen(creds, "a");
fprintf(fp, "\n");
fprintf(fp, save);
fprintf(fp, "\n");
fclose(fp);
for (int j = 0; j<9; j++) {
for (int k = 0; k<8; k++){
order[j][k] = 0;
}
}
strcpy(save, " ");
strcpy(name, " ");
strcpy(phoneno, " ");
strcpy(address, " ");
strcpy(invoicep1, " ");
strcpy(*invoicep2, " ");
strcpy(invoicep3, " ");
strcpy(invoicep4, " ");
strcpy(invoicep5, " ");
question();
}
void question() {
printf("Do you want to [A]dd another Order or [R]eturn to main Menu ?");
char ans[3] ;
gets(ans);
if (strcmp(strupr(ans), "A")==0){
start2();
} else if (strcmp(strupr(ans), "R")==0){
system("cls");
start0();
} else {
printf("\n\nPlease Enter a Valid Option...");
question();
}
}
void question2();
#define maxchar 5000
void views(){
FILE * fp;
char str[maxchar];
fp = fopen(creds, "r");
if (fp == NULL){
printf("\n\nCould not open file %s", creds);
}
int ordno = 1;
while (fgets(str, maxchar, fp) != NULL) {
printf("%s", str);
ordno = ordno + 1;
}
fclose(fp);
question2();
}
void question2() {
printf("\n\nDo you want to [R]eturn to main Menu or [Q]uit ?");
char ans[3] ;
gets(ans);
if (strcmp(strupr(ans), "Q")==0){
endprog();
} else if (strcmp(strupr(ans), "R")==0){
system("cls");
start0();
} else {
printf("\n\nPlease Enter a Valid Option...");
question2();
}
}
67573 - pizza parallel/Java Code/orders.txt
67573 - pizza parallel/Java Code/PizzaShop.java
67573 - pizza parallel/Java...