A ticket selling booth in a cricket stadium, people has to buy the ticket from this booth to enter into the stadium. Price of the each ticket is Rs. 500. The booth keeps track of the number of people visited the stadium. Model this ticketing booth with a class called Counter A including following members Data members (i) Number of people visited (ii) Total amount money collected Member functions (i) To assign initial value (ii) To increment people total as well as amount total if a ticket is sold out. (iii) To display two totals Write a program to test this class.
#include <iostream>
using namespace std;
class CounterA{
private:
//members Data members
//(i) Number of people visited
int numberPeopleVisited;
//(ii) Total amount money collected
float totalAmountMoneyCollected;
public:
//Member functions
//(i) To assign initial value
void assignValues(){
this->numberPeopleVisited=0;
this->totalAmountMoneyCollected=0;
}
//(ii) To increment people total as well as amount total if a ticket is sold out.
void sellTicket(){
this->numberPeopleVisited++;
// Price of the each ticket is Rs. 500.
this->totalAmountMoneyCollected+=500.0;
}
//(iii) To display two totals
void display(){
cout<<"\nNumber of people visited: "<<this->numberPeopleVisited<<"\n";
cout<<"Total amount money collected: "<<this->totalAmountMoneyCollected<<"\n";
}
};
int main() {
//Write a program to test this class.
CounterA counterA;
counterA.assignValues();
int numberPeopleVisited;
cout<<"Enter the number of people visited the stadium: ";
cin>>numberPeopleVisited;
for(int i=0;i<numberPeopleVisited;i++){
counterA.sellTicket();
}
counterA.display();
cout<<"\n\n";
system("pause");
return 0;
}
Comments
Leave a comment