Question
#include #include #include #define MAXS 20 int front = 0,rear= -1,top=-1; struct Node{ char car[20]; struct Node *ptr; int n; }; struct stack1{ char soldCar[20];
#include #include #include #define MAXS 20
int front = 0,rear= -1,top=-1; struct Node{ char car[20]; struct Node *ptr; int n; };
struct stack1{ char soldCar[20]; };
struct stack1 sold[20];
struct Node *insCar(struct Node *head){ struct Node *NewNode; struct Node *temp; temp = head;
NewNode = (struct Node*)malloc(sizeof(struct Node)); if(NewNode == NULL){ printf("Sorry Malloc didn't work. "); }
printf("Araba Markalari Giriniz : "); scanf("%s",(NewNode->car));
printf("How many cars do you have? : ",NewNode->car); scanf("%d",&(NewNode->n)); printf(" ");
NewNode->ptr = NULL; if(temp == NULL){ head = NewNode; }else{ while(temp->ptr != NULL) temp = temp->ptr; temp->ptr = NewNode; }
return head;
} void push(char c[]){ strcpy(sold[++top].soldCar,c); }
void Buy(struct Node *head){ printf(" "); printf("Musteri %d : ",top+2); printf("Which car do you want to buy? : "); char costumerCar[20]; scanf("%s",costumerCar); struct Node *temp; temp = head; while(strcmp(temp->car,costumerCar)){ temp = temp->ptr; if(temp == NULL){ break; } } if(temp == NULL){ printf("The car brand you entered is not available. "); Buy(head);
}else{ if(temp->n == 0){ printf("Sorry, the car you want is out of stock. "); Buy(head); } else{ (temp->n)--; push(costumerCar);
} }
}
void display(struct Node *head){ struct Node *temp; temp = head; printf(" ");
while(temp != NULL){ printf("Araba : %s | Miktar : %d ", temp->car,temp->n); temp = temp->ptr; } } int main(){ struct Node *Head; Head = NULL; printf("********************************** \tWelcome to the Car Gallery **********************************"); int b,i; printf(" How many car brands do you want to add? : "); scanf("%d",&b); printf(" "); for(i=0;i Head = insCar(Head); } printf(" "); printf("Kac musteri? : "); int c; scanf("%d",&c); printf(" "); for(i=0;i Buy(Head); }
display(Head); printf(" Last sold car: %s ",sold[top].soldCar); }
C is the programming language. Can you explain what the code means line by line? What are the functions of each code?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started