You are on page 1of 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