Source Code :
#include<iostream.h>
class TollTax {
int bike,car,truck,amt_bike,amt_car,amt_truck,count_bike,
count_car,count_truck;
public:
TollTax() {
bike=20;
car=40;
truck=60;
amt_bike=0;
amt_car=0;
amt_truck=0;
count_bike=0;
count_car=0;
count_truck=0;
}
void receive() {
int ch;
cout<<endl<<"RECEIVE TOLL MENU";
cout<<endl<<"1. Bike";
cout<<endl<<"2. Car";
cout<<endl<<"3. Trucks";
cout<<endl<<"Enter Category : ";
cin>>ch;
switch(ch) {
case 1: {
amt_bike=amt_bike+bike;
count_bike++;
}break;
case 2: {
amt_car=amt_car+car;
count_car++;
}break;
case 3: {
amt_truck=amt_truck+truck;
count_truck++;
}break;
default:
cout<<endl<<"INVALID CHOICE";
}
}
void disp_vehicles() {
cout<<endl<<"VEHICLES DETAILS";
cout<<endl<<"No. of Bikes that crossed the Bridge \t\t : \t"
<<count_bike;
cout<<endl<<"No. of Cars that crossed the Bridge \t\t : \t"
<<count_car;
cout<<endl<<"No. of Trucks that crossed the Bridge \t\t : \t"
<<count_truck;
cout<<endl<<"==================================================
========";
cout<<endl<<"Total No. of Vehicles that crossed the bridge \t :
\t"<<(count_bike+count_car+count_truck)<<endl;
}
void disp_toll() {
cout<<endl<<"TOLL COLLECTION DETAILS";
cout<<endl<<"Toll collected from Bikes \t: \t"<<amt_bike;
cout<<endl<<"Toll collected from Cars \t: \t"<<amt_car;
cout<<endl<<"Toll collected from Trucks \t: \t"<<amt_truck;
cout<<endl<<"=============================================";
cout<<endl<<"Total Toll collected \t\t: \t"
<<(amt_bike+amt_car+amt_truck)<<endl;
}
};
int main() {
int ch;
TollTax ob;
while(true) {
cout<<endl<<"MAIN MENU";
cout<<endl<<"1. Receive Toll";
cout<<endl<<"2. Display No. of Vehicles Passed";
cout<<endl<<"3. Display Amount of Toll Collected";
cout<<endl<<"4. Exit";
cout<<endl<<"Enter Choice : ";
cin>>ch;
switch(ch) {
case 1: {
ob.receive();
}break;
case 2: {
ob.disp_vehicles();
}break;
case 3: {
ob.disp_toll();
}break;
case 4: {
exit(0);
}
default: {
cout<<endl<<"INVALID CHOICE";
}
}
}
}
Output :
MAIN MENU
1. Receive Toll
2. Display No. of Vehicles Passed
3. Display Amount of Toll Collected
4. Exit
Enter Choice : 1
RECEIVE TOLL MENU
1. Bike
2. Car
3. Truck
Enter Category : 2
MAIN MENU
1. Receive Toll
2. Display No. of Vehicles Passed
3. Display Amount of Toll Collected
4. Exit
Enter Choice : 2
VEHICLES DETAILS
No. of Bikes that crossed the Bridge : 0
No. of Cars that crossed the Bridge : 1
No. of Trucks that crossed the Bridge : 0
===========================================================
Total No. of Vehicles that crossed the Bridge : 1
MAIN MENU
1. Receive Toll
2. Display No. of Vehicles Passed
3. Display Amount of Toll Collected
4. Exit
Enter Choice : 3
TOLL COLLECTION DETAILS
Toll collected from Bikes : 0
Toll collected from Cars : 40
Toll collected from Trucks : 0
==========================================
Total Toll Collected : 40
No comments:
Post a Comment