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

Class Object Exercise

1) The document describes modeling a toll booth using a TollBooth class with unsigned int and double data members to track the total number of cars and total cash amount. Member functions payingCar() and nopayCar() increment the car count and update the cash total appropriately. display() outputs the totals. A test program allows the user to count paying and nonpaying cars until escape is pressed, then prints the results. 2) A Time class is described with separate int data members for hours, minutes, and seconds. Constructors initialize to 0 or fixed values. A display() function outputs in HH:MM:SS format. add() adds two Time objects. A main() program initializes two Time objects, adds

Uploaded by

MAHESH V
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views

Class Object Exercise

1) The document describes modeling a toll booth using a TollBooth class with unsigned int and double data members to track the total number of cars and total cash amount. Member functions payingCar() and nopayCar() increment the car count and update the cash total appropriately. display() outputs the totals. A test program allows the user to count paying and nonpaying cars until escape is pressed, then prints the results. 2) A Time class is described with separate int data members for hours, minutes, and seconds. Constructors initialize to 0 or fixed values. A display() function outputs in HH:MM:SS format. add() adds two Time objects. A main() program initializes two Time objects, adds

Uploaded by

MAHESH V
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

1) Imagine a tollbooth at a bridge.

Cars passing by the booth are expected to pay


50 cent toll. Mostly they do , but sometimes a car goes by without paying.
The toolbooth keeps track of the number of cars that have gone by, and of the
total amount of money collected. Model this toll booth with a class called
tollbooth. 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 of these to 0. A member
function called payingCar() increments the car total and adds 50 rupees
to the cash total. Another function, called nopayCar() increments the car total but
adds nothing to the cash total. Finally, a member function called diplay() displays
the two totals.
Make appropriate member functions const.

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 esc
key should cause the program to print out total cars and total cash and then exit.

2) Create a class called time that has separate int member data for hours, minutes,
and seconds. One constructor should initialize this data to 0 nad another should
initialize it to fixed values.
Another member function should display it in 11:59:59 format. The final member
function should add two objects of type time passed as arguments.
A main() program should create two initailized time objects and one that isn't
initialized. Then it should add the initialized values together, leaving the result
in the third time variable.
Finally it should display the value of this third variable. Make appropriate member
functions const.

You might also like