DUE 15mins: Quick Tally Program Question

Apr 22, 2011 at 12:31am
I have most of the program written, but I just can't seem to remember or know how to make the function add 1 each time for the tally counter. Help will be much appreciated. Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
using namespace std;

class TallyCounter
{
        private:
        int counter;
        public:
        void set_value (int a);
        int get_value ();

};

void TallyCounter::set_value (int a)
{

        counter = a;
        counter++;
}

int TallyCounter::get_value()
{
        return counter;
}

int main()
{
        TallyCounter count;
        count.set_value (1);
        cout << "Tally is: " << count.get_value();

return 0;
}
Last edited on Apr 23, 2011 at 5:34am
Apr 22, 2011 at 12:34am
Make what function increment the tally counter?
Apr 22, 2011 at 12:52am
@BurgerTown: First, what do you think the second part of your "set_vaue" function is doing =)

Second: I do believe that an int will accomplish the purpose of your tallycounter. You can simply ++ to increment it, and you can directly use the << operator to output it to the console =D
Apr 22, 2011 at 9:01am
Well to answer the first question, nothing lol.

And sorry for not understanding it completely, but what exactly do you mean by your second statement? Because I need to have a get_value function. The class also should have a default construct and a constructor to initialize the count and a set_value() function that sets the value to the integer passed to it.

And thanks for the help, its really appreciated and I do want to learn how to do this.
Apr 22, 2011 at 9:11am
Did you realise that SetCounter(a) sets the counter to a + 1?

You set it to a and then increment it...

I'm still not really sure what you're trying to so, is this it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
using namespace std;

class TallyCounter
{
        private:
        int counter;
        public:
        void set_value (int a);
        void increment ();
        int get_value ();

};

void TallyCounter::set_value (int a)
{
        counter = a;
}

void TallyCounter::increment ()
{
        ++counter;
}

int TallyCounter::get_value()
{
        return counter;
}

int main()
{
        TallyCounter count;
        count.set_value (1);
        cout << "Tally is: " << count.get_value() << endl;
        count.increment ();
        cout << "Tally is: " << count.get_value() << endl;
        return 0;
}
Last edited on Apr 22, 2011 at 9:12am
Apr 22, 2011 at 6:33pm
Im trying to create a class that models a tally counter. Like the thing they use a concerts and such that track how many people go through the gates. It needs to display the current value by the class get_value() member function.
The class should have a default construct and a constructor to initialize the count. It should also have a set_value() function that sets the value to the integer passed to it. Thanks for the help tho.

Anyone else want to take a shot at this.
Apr 22, 2011 at 11:32pm
anyone want to take a crack at helping me fix my program so that it is like what I described in my post above because I am completely lost.

Thanks
Apr 23, 2011 at 4:40am
This program is due soon, anyone there?
Apr 23, 2011 at 4:58am
closed account (D80DSL3A)
I'm here but I don't understand what your program is supposed to do. Is it supposed to make counter increase by 1 each time the increment() function is called? It looks like your code would do that.
I would expect your programs output to be:

Tally is: 1
Tally is: 2

Is this not what you are getting?
Last edited on Apr 23, 2011 at 5:00am
Apr 23, 2011 at 5:07am
I know it doesn't make much sense, but I think it is suppose to be like one of those things at a concert or stadium that tallies how many people go through the gates. But im not sure how to set it up. Make anymore sense?
Apr 23, 2011 at 5:34am
anyone?
Topic archived. No new replies allowed.