Answer To: ITECH5403 – Comparative Programming Languages School of Engineering, Information Technology and...
Neha answered on Oct 08 2021
66745 - pizza parallel/C Language/pizza_order.txt
66745 - pizza parallel/C Language/PizzaShop.c
#include
#include
#include
#include
#include
const char *creds = "pizza_order.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 mainMenu();
void start0(){
printf("\n--------------------- Welcome to Pizza Shop ---------------------");
printf("\n**************************************************************************");
printf("\nMain Menu : ");
printf("\n 1.) Add Order.");
printf("\n 2.) View Orders.");
printf("\n 3.) Exit.");
mainMenu();
}
void new_Order();
void views();
void endprog();
void mainMenu() {
printf("\nPlease select (1,2 or 3):");
int ip0a;
scanf("%d", &ip0a);
if (ip0a == 1) {
new_Order();
} else if (ip0a == 2){
views();
} else if ( ip0a == 3){
endprog();
} else {
printf("\n\nPlease select valid Option.");
mainMenu();
}
}
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 Thank You! See you soon. \n");
exit(0);
}
else if (strcmp(strupr(aq5), "N")==0){
printf(" ");
system("cls");
start0();
} else {
printf("\n\nPlease select valid Option.");
endprog();
}
}
void new_Order();
void addOrder(){
printf("\nAdd a new Order...");
new_Order();
}
void sizeselect();
void new_Order(){
printf("\nPlease Select an Option for pizza Size from below: ");
printf("\n 1.) Small pizza - $5 ");
printf("\n 2.) Medium pizza - $8 ");
printf("\n 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 selectToppings();
void sizesave() {
for (int j = 0; j<9; j++) {
int s = order[j][0];
if (s != 0) {
i++;
}
}
order[i][0] = psize;
printf("\n\nPizza Base : Tomato");
printf("\nToppings : Cheese"");
printf("\nExtra Toppings : Maximum 4");
printf("\nExtra $1 for each toppings");
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");
selectToppings();
}
void showpizza();
void selectToppings() {
printf("\nPlease Enter an Option between '0' and '7' : ");
printf("\nPlease enter value for First topping : ");
int topping1;
scanf("%d", &topping1);
printf("\nPlease enter value for Second topping : ");
int topping2;
scanf("%d", &topping2);
printf("\nPlease enter value for Third topping : ");
int topping3;
scanf("%d", &topping3);
printf("\nPlease enter value for 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...");
selectToppings();
}
}
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 addNewPizza();
void pizzacount(){
printf("\nPlease Enter number of Pizzas: ");
int pizzano;
scanf("%d", &pizzano);
order[i][5] = pizzano;
addNewPizza();
}
void ordertype();
void addNewPizza() {
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) {
new_Order();
} else if (strcmp(strupr(ans), "N")==0){
ordertype();
} else {
printf("\n\nPlease Enter Valid Option...");
addNewPizza();
}
}
void customerdetails();
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();
}
}
}
customerdetails();
}
char name[50], address[100] = "Not Applicable";
char phoneno[17];
void showorder();
void customerdetails() {
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){
addOrder();
} else if (strcmp(strupr(ans), "R")==0){
system("cls");
start0();
} else {
printf("\n\nPlease Enter a Valid Option...");
question();
}
}
void menuSelection();
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);
menuSelection();
}
void menuSelection() {
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...");
menuSelection();
}
}
66745 - pizza parallel/Java Code/pizza_order.txt
66745 - pizza parallel/Java Code/PizzaShop.java
66745 - pizza parallel/Java...