Skip to content

Commit 64dc84c

Browse files
Add files via upload
1 parent 337e527 commit 64dc84c

File tree

2 files changed

+176
-0
lines changed

2 files changed

+176
-0
lines changed

Car_Shop/Car_Shop.c

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#include<stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#define MAXS 20
5+
6+
7+
int front = 0,rear= -1,top=-1;
8+
struct Node{
9+
char car[20];
10+
struct Node *ptr;
11+
int n;
12+
};
13+
14+
struct stack1{
15+
char soldCar[20];
16+
};
17+
18+
struct stack1 sold[20];
19+
20+
struct Node *insCar(struct Node *head){
21+
struct Node *NewNode;
22+
struct Node *temp;
23+
temp = head;
24+
25+
NewNode = (struct Node*)malloc(sizeof(struct Node));
26+
if(NewNode == NULL){
27+
printf("SORRY MALLOC FAILD\n");
28+
}
29+
30+
printf("enter the car brand name :");
31+
scanf("%s",(NewNode->car));
32+
33+
printf("How many %s car u have :",NewNode->car);
34+
scanf("%d",&(NewNode->n));
35+
printf("\n");
36+
37+
NewNode->ptr = NULL;
38+
if(temp == NULL){
39+
head = NewNode;
40+
}else{
41+
while(temp->ptr != NULL)
42+
temp = temp->ptr;
43+
temp->ptr = NewNode;
44+
}
45+
46+
return head;
47+
48+
}
49+
void push(char c[]){
50+
strcpy(sold[++top].soldCar,c);
51+
}
52+
53+
void Buy(struct Node *head){
54+
printf("\n");
55+
printf("costumer %d :\n",top+2);
56+
printf("which car u Want to Buy :");
57+
char costumerCar[20];
58+
scanf("%s",costumerCar);
59+
struct Node *temp;
60+
temp = head;
61+
while(strcmp(temp->car,costumerCar)){
62+
temp = temp->ptr;
63+
if(temp == NULL){
64+
break;
65+
}
66+
}
67+
if(temp == NULL){
68+
printf("that car Brand is not available\n");
69+
Buy(head);
70+
71+
}else{
72+
if(temp->n == 0){
73+
printf("Sorry Out of stock\n");
74+
Buy(head);
75+
}
76+
else{
77+
(temp->n)--;
78+
push(costumerCar);
79+
80+
}
81+
}
82+
83+
}
84+
85+
86+
void display(struct Node *head){
87+
struct Node *temp;
88+
temp = head;
89+
printf("\n\n");
90+
91+
while(temp != NULL){
92+
printf("car : %s | amount : %d\n", temp->car,temp->n);
93+
temp = temp->ptr;
94+
}
95+
}
96+
int main(){
97+
struct Node *Head;
98+
Head = NULL;
99+
printf("**********************************\n\tWelcome to car shop\n**********************************");
100+
int b,i;
101+
printf("\nHow many car Brand u Want to add :");
102+
scanf("%d",&b);
103+
printf("\n");
104+
for(i=0;i<b;i++){
105+
Head = insCar(Head);
106+
}
107+
printf("\n");
108+
printf("How many costumers :");
109+
int c;
110+
scanf("%d",&c);
111+
printf("\n");
112+
for(i=0;i<c;i++){
113+
Buy(Head);
114+
}
115+
116+
display(Head);
117+
printf("\n\nlast sold car is %s\n\n",sold[top].soldCar);
118+
}

Car_Shop/Car_Shop_Output.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
**********************************
2+
Welcome to car shop
3+
**********************************
4+
How many car Brand u Want to add :4
5+
6+
enter the car brand name :BMW
7+
How many BMW car u have :3
8+
9+
enter the car brand name :Audi
10+
How many Audi car u have :2
11+
12+
enter the car brand name :Bugatti
13+
How many Bugatti car u have :1
14+
15+
enter the car brand name :Ford
16+
How many Ford car u have :6
17+
18+
19+
How many costumers :7
20+
21+
22+
costumer 1 :
23+
which car u Want to Buy :Audi
24+
25+
costumer 2 :
26+
which car u Want to Buy :BMW
27+
28+
costumer 3 :
29+
which car u Want to Buy :Bugatti
30+
31+
costumer 4 :
32+
which car u Want to Buy :Ford
33+
34+
costumer 5 :
35+
which car u Want to Buy :Ford
36+
37+
costumer 6 :
38+
which car u Want to Buy :Bugatti
39+
Sorry Out of stock
40+
41+
costumer 6 :
42+
which car u Want to Buy :Audi
43+
44+
costumer 7 :
45+
which car u Want to Buy :Ford
46+
47+
48+
car : BMW | amount : 2
49+
car : Audi | amount : 0
50+
car : Bugatti | amount : 0
51+
car : Ford | amount : 3
52+
53+
54+
last sold car is Ford
55+
56+
57+
Process returned 0 (0x0) execution time : 168.662 s
58+
Press any key to continue.

0 commit comments

Comments
 (0)