-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCar_rental.C++
100 lines (92 loc) · 1.85 KB
/
Car_rental.C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
using namespace std;
int reg[5]={123,234,345,456,567};
string comp[5]={"Suzuki","Honda","Toyota","MG","BMW"};
int rent[5]={2000,2500,3000,3500,5000};
char avail[5]={'y','y','y','y','y'};
int size= sizeof(reg)/sizeof(reg[0]);
void showFun(){
for(int i=0;i<size; i++){
if(avail[i]=='y'){
cout<<"Car "<<comp[i]<<" with Reg "<<reg[i]<<
" and with Rent "<<rent[i]<<endl;
}
}
}
void reserveFun(){
int regNo,days;
cout<<"Enter Registration No: ";
cin>>regNo;
cout<<"Enter Total Days: ";
cin>>days;
bool found=false;
for(int i=0;i<size; i++){
if(regNo==reg[i] && avail[i]=='y'){
found=true;
avail[i]='n';
int bill = rent[i] * days;
cout<<"Your Rent For "<<comp[i]<<" with Reg"<<
reg[i]<<" is: "<<bill<<endl;
}
}
if(!found){
cout<<"This car is unavailable"<<endl;
}
}
void returnFun(){
cout<<"Enter Registration No: ";
int regNo;
cin>>regNo;
bool found=false;
for(int i=0;i<size;i++ ){
if(regNo==reg[i]){
found=true;
avail[i]='y';
cout<<"Car is Returned"<<endl;
}
}
if(!found){
cout<<"Incorrect Registration No!"<<endl;
}
}
int main(){
while(true){
cout<<"Car Rental Management System"<<endl;
cout<<"----------------------------"<<endl;
cout<<"1.Show Available Cars"<<endl;
cout<<"2.Reserve a Car."<<endl;
cout<<"3.Return A Car."<<endl;
cout<<"4.Exit."<<endl;
int choice;
cout<<"Enter Your Choice: ";
cin>>choice;
if(choice==1){
//available cars
system("cls");
showFun();
cout<<" "<<endl;
}
else if(choice==2){
//reserve a car
system("cls");
reserveFun();
cout<<" "<<endl;
}
else if(choice==3){
//return a car
system("cls");
returnFun();
cout<<" "<<endl;
}
else if(choice==4){
system("cls");
cout<<"Best of Luck!"<<endl;
cout<<" "<<endl;
break;
}
else {
system("cls");
cout<<" Invalid input!"<<endl;
}
}
}