0% found this document useful (0 votes)
134 views

Oops-Program 11-Mdu

This document describes a C++ program that models a toll booth using a class. The toll booth class has data members to count the total number of cars and total money collected. Member functions increment the car count for paying or non-paying cars, and add $0.50 to the total for paying cars. The main function displays a menu and calls the member functions based on user input, then displays the final totals.

Uploaded by

Atul Malhotra
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views

Oops-Program 11-Mdu

This document describes a C++ program that models a toll booth using a class. The toll booth class has data members to count the total number of cars and total money collected. Member functions increment the car count for paying or non-paying cars, and add $0.50 to the total for paying cars. The main function displays a menu and calls the member functions based on user input, then displays the final totals.

Uploaded by

Atul Malhotra
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

C++ programing Lab

File name: program11.cpp

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

//header file //class

//class declaration

CSE/10/409

C++ programing Lab

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

C++ programing Lab

SBIT/CSE/IV/C++ PROGRAMING/CSE-206-F

CSE/10/409

You might also like