Advertisements
Home > Cpp > C++ Program to implement Toll Tax Problem by using CLASS Access Specifiers and SWITCH CASE – Q12

C++ Program to implement Toll Tax Problem by using CLASS Access Specifiers and SWITCH CASE – Q12


Q12. Program to implement Toll Tax Problem by using CLASS Access Specifiers and SWITCH CASE:

Calculate the toll tax for cars passing by a toll bridge @ Rs 5 per car (use the concept static data members). Calculate and Print the following details:
– Total no of cars passed with paying the tax
– Total amount of tax paid
– Total no of cars passed without paying tax.

… from College notes (BCA/MCA assignments):

#include <iostream.h>
#include <conio.h>
#include <stdlib.h>

class TollBridge{
	private:
		static int car_yes, car_no;
		static int amt;
	public:
		static void GetCar();
		static void PutCar();
	};

int TollBridge::car_yes = 0;
int TollBridge::car_no = 0;
int TollBridge::amt = 0;

void TollBridge :: GetCar(){
	char ch;
	cout<<"\n Total Cars Passed: "<<car_yes+car_no;
	cout<<"\n This Car:- ";
	cout<<"\n Paid Tax (y/n) ?: ";
	cin>>ch;
	if(ch == 'y'){
		car_yes++;
		amt += 5;
		}
	else
		car_no++;
	}

void TollBridge :: PutCar(){
	cout<<"\n Total Car Passed: "<<car_yes+car_no<<endl;
	cout<<"\n\t Car Passed by giving Tax: "<<car_yes;
	cout<<"\n\t\t Amount Recieved: "<<amt<<endl;
	cout<<"\n Car Passed by not giving Tax: "<<car_no;
	}

void main(){
	int ch;
	char choice;
	while(1){
		clrscr();
		cout<<"\n TOLL TAX PLAZA";
		cout<<"\n ~~~~~~~~~~~~~~";
		cout<<"\n 1 -> Entry of CARS.";
		cout<<"\n 2 -> Report of CARS.";
		cout<<"\n 3 -> Exit.";
		cout<<"\n Enter your choice: ";
		cin>>ch;
		switch(ch){
			case 1:
				while(1){
					TollBridge::GetCar();
					cout<<"\n Do you want to continue 
  (y/n) ?: ";
					cin>>choice;
					if(choice =='n') break;
					}
				break;
			case 2:
				TollBridge::PutCar();
				getch();
				break;
			default:
				exit(1);
			} // end of switch.
		} // end of while.
	} // end of main.

 

Output:

TOLL TAX PLAZA
1 -> Entry of CARS.
2 -> Report of CARS.
3 -> Exit.
Enter your choice: 1

Total Cars Passed: 0
This Car:-
Paid Tax (y/n) ?: y

Do you want to continue (y/n) ?: y

Total Cars Passed: 1
This Car:-
Paid Tax (y/n) ?: y

Do you want to continue (y/n) ?: y

Total Cars Passed: 2
This Car:-
Paid Tax (y/n) ?: y

Do you want to continue (y/n) ?: y

Total Cars Passed: 3
This Car:-
Paid Tax (y/n) ?: n

Do you want to continue (y/n) ?: y

Total Cars Passed: 4
This Car:-
Paid Tax (y/n) ?: n

Do you want to continue (y/n) ?: y

Do you want to continue (y/n) ?: n

TOLL TAX PLAZA
1 -> Entry of CARS.
2 -> Report of CARS.
3 -> Exit.
Enter your choice: 2

Total Car Passed: 5
Car Passed by giving Tax: 3
Amount Recieved: 15
Car Passed by not giving Tax: 2


Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: