Q 2
tollbooth1.cpp
#include<iostream>
#include "tollbooth1.h"
using namespace std;
tollbooth1::tollbooth1()
{
noc = 0;
t_m = 0;
}
void tollbooth1::payingcar()
{
noc++;
t_m = t_m + 50;
}
void tollbooth1::nopaycar()
{
noc++;
}
void tollbooth1::display()
{
cout << "TOTAL CARS PASSED" << noc << endl;
cout << "TOTAL CASH" << t_m << endl;
}
tollbooth1.h
#pragma once
class tollbooth1
{
private:
int rs;
int noc;
int t_m;
public:
tollbooth1();
void payingcar();
void nopaycar();
void display();
};
main.cpp
#include<iostream>
#include "tollbooth1.h"
using namespace std;
char key;
void main()
{
tollbooth1 car;
do{
cout << "PRESS P FOR PAYING CAR\n";
cout << "PRESS N FOR NONPAYING CAR\n";
cout << "PRESS E TO DISPLAY THE TOTALS\n";
cin >> key;
if (key == 'P' || key == 'p')
car.payingcar();
else if (key == 'N' || key == 'n')
car.nopaycar();
else if (key == 'E' || key == 'e')
car.display();
} while (key != 'e');
system("pause");
}
0 comments: