Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Austin Chen
- //January 15 2019
- //Program A P 9.1
- //This program implements a class that models a tally counter, a device that is
- //used to count people.
- #include <iostream>
- using namespace std;
- class Tally
- {
- public:
- void count(int current_number)//member function to find number of people incrementing by 1 each time.
- {
- current_people = current_number;
- int x = 1;
- while(x == 1)
- {
- cout << "Press 1 to add to tally count or press any other key when done counting: ";
- cin >> x;//if the user inputs something other than one, it exits.
- if(x == 1)
- {
- current_people++;//increases by one
- }
- }
- }
- int get_value()
- {
- return current_people;//returns final count of people
- }
- private:
- int current_people;
- };
- int main()
- {
- Tally counter;
- int current_number = 15;//Initial number is 15.
- counter.count(current_number);//Calls function
- cout << "Current number of people is: " <<counter.get_value()<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement