Oops-Program 11-Mdu
Oops-Program 11-Mdu
PROGRAM NO. 11
Objective: Imagine a tollbooth with a class called toll Booth. The two data items are a type unsigned int to hold the total number of cars, and a type double to hold the total amount of money collected. A constructor initializes both these to 0. A member function called payingCar ( ) increments thecar total and adds 0.50 to the cash total. Another function, called nopayCar ( ), increments the car total but adds nothing to the cash total. Finally, a member function called displays the two totals. Include a program to test this class. This program should allow the user to push one key to count a paying car, and another to count a nonpaying car. Pushing the ESC key should cause the program to print out the total cars and total cash and then exit. #include<iostream> using namespace std; class tollbooth { int car; double total; public: tollbooth() { car=0; total=0; } void payingcar(); void nopaycar(); void display(); }t1,t2; void tollbooth::payingcar() { t1.car++; t1.total=0.50+t1.total; cout<<"The total are "<<t1.car<<" & "<<t1.total; } void tollbooth::nopaycar() { t1.car++; cout<<"the total is : "<<t1.car; } void tollbooth::display() { int ch; cout<<"***MENU***"; cout<<"\n1.paying car"; cout<<"\n2.no pay car"; cout<<"\nEnter your choice : "; cin>>ch; if(ch==1)
SBIT/CSE/IV/C++ PROGRAMING/CSE-206-F
//class declaration
CSE/10/409
t1.payingcar(); else t1.nopaycar(); } int main() { int ch; tollbooth t2; t2.display(); return 0; }
//main() function
//end of main()
OUTPUT
SBIT/CSE/IV/C++ PROGRAMING/CSE-206-F
CSE/10/409
SBIT/CSE/IV/C++ PROGRAMING/CSE-206-F
CSE/10/409