You are tasked with creating a program for a pizza shop –however, as this is a comparative languages course,.you will be creating the same application in the following programming languages:
C,
Python,
Java and
Lisp.
Answer:
Code Description Document C:
Our C code is a combination of two files
- main.c
This file is the class having the main function. It uses the other file “Pizza.c” for its functionality. We have added an import for this Pizza.c file in this.
The main function contains a loop which asks the user for one of three choices and then passes the control to Pizza.c file for the functionality of that function.
main.c
#include "Pizza.c"
while(1)
printf("nnPizza Choices n");
printf("1. New Ordern");
printf("2. Display list of ordersn");
printf("3. Exitn");
printf("Enter your choice : ");
char val[5];
fgets(val, 5, stdin);
int value=atoi(val);
if(value==1)
newOrder();
else if(value==2)
dislayAll();
else if(value==3)
printf("nExiting...nn");
return 0;
else
printf("Please enter a valid choice.");
return 0;
Pizza.c
This is the main file which performs various functionalities related to this application.
It has two structures:
1.Pizza struct
typedef struct pizza
char size[10];
char toppings[5][10];
int tsize;
Pizza;
This Pizza structure denotes a Pizza.
It has three attributes:
size: size of pizza (small/medium/large
toppings : it can contain 5 toppings
tsize: it contains the number of toppings this pizza have
PizzaOrder struct
typedef struct pizzaorder
Pizza ** pizzas;
char status[20];
char name[20];
char phone[20];
char address[20];
int size;
PizzaOrder;
This structure have various attributes like:
pizzas: an array of pizza pointers
status: status of the order
name : name of the person
phone: phone number
address: address of the person
size: size of the pizza array
There are a number of functions like:
- printPizza
void printPizza(Pizza *pizza)
printf("Size : %sn",pizza->size);
printf("Toppings : n" );
int i=0;
for(i=0;i<pizza->tsize;i++)
printf("%st",pizza->toppings[i]);
printf("n");
This function prints the passed pizza pointer with its size and all other details
- pizzaCost
double pizzaCost(Pizza* pizza)
double tot=0.0;
if(strcmp(pizza->size,"small")==0)
tot=5;
else if(strcmp(pizza->size,"medium")==0)
tot=8;
else if(strcmp(pizza->size,"large")==0)
if(size==1)
orders=(PizzaOrder**)malloc(size*sizeof(PizzaOrder));
orders=(PizzaOrder**)realloc(orders,size*sizeof(PizzaOrder));
orders[size-1]=order;
printOrder(order);
This function makes a Pizza Order. Read various pizzas for this order and add this order to the list of orders.
- displayAll
void dislayAll()
printf("nList of Orders: n");
int i;
for(i=0;i<size;i++)
printOrder(orders[i]);
printf(
This function prints all the orders with the brief details about each order.