Answer to Question #218627 in C++ for Tibin

Question #218627
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-20T02:32:26-0400
#include <iostream>

class Counter {
private:
  int number_of_visited;
  float total_amount;
public:
  void init() {
    this->number_of_visited = 0;
    this->total_amount = 0;
  }
  void sold() {
    this->number_of_visited++;
    this->total_amount += 500; // Rs.500 
  }
  void show() {
    std::cout << "number of visited people:" << this->number_of_visited << std::endl;
    std::cout << "total amount:" << this->total_amount << std::endl;
  }
};

int main() 
{
  Counter c;

  c.init();

  c.sold();

  c.show();

  c.sold();
  c.sold();
  c.sold();

  s.show();

  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