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

Practise Problems..

The document defines a Tollboth class to track vehicles and cash at a toll booth. The Tollboth class has data members for the number of cars and cash amount. Member functions are defined to increment cars and cash for paying cars, increment cars only for non-paying cars, and display the totals. The main function creates a Tollboth object and uses getch to get keyboard input representing pay, non-pay, or display choices to simulate cars passing and increment the Tollboth data accordingly before displaying the results.

Uploaded by

Shayan Khan
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Practise Problems..

The document defines a Tollboth class to track vehicles and cash at a toll booth. The Tollboth class has data members for the number of cars and cash amount. Member functions are defined to increment cars and cash for paying cars, increment cars only for non-paying cars, and display the totals. The main function creates a Tollboth object and uses getch to get keyboard input representing pay, non-pay, or display choices to simulate cars passing and increment the Tollboth data accordingly before displaying the results.

Uploaded by

Shayan Khan
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include<iostream>

#include<conio.h>

using namespace std;

class Tollboth {

int cars;

double cash;

public:

Tollboth()

cars = 0;

cash = 0;

void paycar()

cars++;

cash += 0.50;

void nopaycar()

cars++;

void display()

cout << "The total cars which have passed through the tollboth are: " << cars << endl;

cout << "The total amount is: " << cash;

};

int main()

{
Tollboth T1;

int i = 0;

cout << "Press enter for a pay_car: " << endl;

cout << "Press n for a non pay_car: " << endl;

cout << "Press escape to show all the results and exit: " << endl;

while (true)

int choice;

choice = _getch();

if (choice == 13)

T1.paycar();

i++;

cout <<"cars= "<< i << endl;

else if (choice == 110)

T1.nopaycar();

i++;

cout << "cars= " << i << endl;

else if (choice == 27)

system("cls");

T1.display();

}
return 0;

2)

#include<iostream>

using namespace std;

class Time

int hours, minutes, seconds;

public:

Time()

hours = 0;

minutes = 0;

seconds = 0;

Time(int h,int m, int s)

hours = h, minutes = m, seconds = s;

void display(Time x, Time y)

int h, m, s;

h = x.hours + y.hours;

m = x.minutes + y.minutes;

s = x.seconds + y.seconds;

while (true)
{

if (m > 59 || s > 59)

if (m > 59)

h += 1;

m -= 60;

if (s > 59)

m += 1;

s -= 60;

continue;

else

break;

cout << h << ":" << m << ":" << s;

};

int main()

Time const t1(10, 90, 90), t2(30, 90, 90);

Time t3;
t3.display(t1,t2);

return 0;

You might also like