Answer to Question #218756 in Programming & Computer Science for Ravi Parmar

Question #218756

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.



1
Expert's answer
2021-07-19T10:14:53-0400
#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;
}





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
APPROVED BY CLIENTS