Answer to Question #315926 in C++ for khan

Question #315926

Consider a toll plaza on a bridge. Cars passing through the toll plaza must pay a toll of Rs.30/-. Most of the time, they do, but every now and then, a car drives by without paying. The toll plaza records the number of cars that have passed through as well as the total amount of money collected. Model this toll-plaza with the help of the toll-plaza class. The classs two data items are to hold the total number of cars and to hold the total amount of money collected. For the c++ class, implement:

 A constructor that initializes both data items to 0.

 A member function called payingCar() increments the car total and adds 30 to the cash total.

 Another function, called nopayCar() that increments the car total but adds nothing to the

cash total.

 Finally, a member function called display() should display the total cars and the total cash collected.


1
Expert's answer
2022-03-25T15:11:22-0400
#include <iostream>
using namespace std;


class TollPlaza {
    int cars;
    int money;
public:
    TollPlaza() : cars(0), money(0) {}
    void payingCar() {
        cars++;
        money += 30;
    }
    void nonpayCar() {
        cars++;
    }
    void display() {
        cout << "Total cars: " << cars << endl;
        cout << "Cash: Rs." << money << "/-" << endl;
    }
};


int main() {
    TollPlaza plaza;


    plaza.payingCar();
    plaza.payingCar();
    plaza.nonpayCar();
    plaza.payingCar();


    plaza.display();


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog