I need HELP!! ASAP

I started writing a c++ program but am at a loss! Any Help would be highly appreciated! My program asks for this:
implement a class that models a tally counter, a mechanical device that is used to count people. whenever the operator pushes a button, the counter value advances by one. Model this operation with a count member function. a physical counter has a display to show the current value. in your class, use a get_value member function instead.

Im so confused! Please help!!
Seems pretty straight forward.

1) Start by making a class
2) Write a member function 'count' that increments a counter
3) Write a member function 'get_value' that returns the counter

What is confusing you?

You're looking for something basic like this I take 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
#include "stdafx.h"
#include<iostream>

using namespace std;

class TallyCounter
{

   int counter;

   public:

   void count(int a)
   {
      counter = a;
	  counter++;
   }

   int get_value()
   {
      return counter;
   }

};


int _tmain(int argc, _TCHAR* argv[])
{
	TallyCounter Kount;
	Kount.count(1);
	cout << Kount.get_value() <<endl;

	system("pause");
	return 0;
}
I dont need to have (int a, a++) for adding one to the value every time? Im confused with the use a get_value member function instead. Also 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. How do I put this in my program?
Have you read the tutorial about classes[1] (I think part 1 is enough for)? @MidnightRyder RL did most of the work for you. Just take the class he wrote and make the minor changes needed.

[1] http://www.cplusplus.com/doc/tutorial/classes/
@ Midnight Ryder:

Please don't give out full solutions. Doing his homework for him doesn't help anyone.

Although at least your solution has a major error in it so he can't use it as-is.
My Program looks like this but I dont understand why it isnt compiling and what the errors are.
#include<iostream>
#include<cmath>

using namespace std;

class TallyCounter
{
private:
int a;

public:
void count_up(){
a++;
}

int get_value()
{
return a;
}
void set_value(int x)
{
a = x;
}
TallyCounter();

TallyCounter(int c);
};

TallyCounter::TallyCounter(){
a = 0;
}
TallyCounter::TallyCounter(){
a = c;
}

int main(){
int class TallyCounter()

cout<<"sum"<<sum<<endl;

return 0;

//my errors are as follows:
prog7.cpp:37: error: redefinition of ‘TallyCounter::TallyCounter()’
prog7.cpp:34: error: ‘TallyCounter::TallyCounter()’ previously defined here
prog7.cpp: In function ‘int main()’:
prog7.cpp:42: error: expected primary-expression before ‘int’
prog7.cpp:42: error: expected ‘;’ before ‘int’



how can i fix it???
if you took 3 seconds to look at your code youd see that you define tallycounter twice. just remove one of the
1
2
3
TallyCounter::TallyCounter(){
a = c;
}

also please use code tags now
Last edited on
I fixed the problem but now I can only get it to put out Tally_Count(). How do I get it to count and give me a number?
#include<iostream>
#include<cmath>

using namespace std;

class Tally_Counter
{
private:
int a;

public:
void count_up(){
a++;
}

int get_value()
{
return a;
}
void set_value(int x)
{
a = x;
}
Tally_Counter();
Tally_Counter(int c);
};
Tally_Counter::Tally_Counter(){
a=0;
}

int main(){

cout<<"Tally_Counter()"<<endl;

return 0;
}

you havent made any instances of the class yet, you really need to go through the tutorial
Topic archived. No new replies allowed.