Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. //Austin Chen
  2. //January 15 2019
  3. //Program A P 9.1
  4. //This program implements a class that models a tally counter, a device that is
  5. //used to count people.
  6. #include <iostream>
  7. using namespace std;
  8. class Tally
  9. {
  10.  
  11. public:
  12.  
  13. void count(int current_number)//member function to find number of people incrementing by 1 each time.
  14. {
  15. current_people = current_number;
  16. int x = 1;
  17. while(x == 1)
  18. {
  19. cout << "Press 1 to add to tally count or press any other key when done counting: ";
  20. cin >> x;//if the user inputs something other than one, it exits.
  21. if(x == 1)
  22. {
  23. current_people++;//increases by one
  24. }
  25. }
  26.  
  27. }
  28. int get_value()
  29. {
  30. return current_people;//returns final count of people
  31. }
  32.  
  33. private:
  34. int current_people;
  35.  
  36. };
  37.  
  38. int main()
  39. {
  40. Tally counter;
  41. int current_number = 15;//Initial number is 15.
  42.  
  43. counter.count(current_number);//Calls function
  44. cout << "Current number of people is: " <<counter.get_value()<<endl;
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement