Class Definitions

I am in the middle of debugging my project and I can't figure out for the life of he how to correct some of the errors

Our assignment is as follows

We are to make a program that implements class files so that we have the output

Havingone experienced runner, and one light weight runner as two separate methods


Sonia O’Sullivan walked 0 miles, ran 500 miles and jogged 0 miles

Sonia O’Sullivan walked 0 miles, ran 1000 miles and jogged 0 miles

Sonia O’Sullivan walked 0 miles, ran 500 miles and jogged 0 miles

You walked 10 miles, ran 0 miles and jogged 10 miles




So far my Jogger.h file is as follows

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
#ifndef JOGGER_H
#define JOGGER_H
#include <string>
using namespace std;


class Jogger {
public:
	Jogger();
	Jogger(string name);

	void walk(int amount);
	void run(int amount);
	void jog(int amount);

	void displayStats();
	void clearStats();

private:
	string name;
	int walkedSoFar;
	int ranSoFar;
	int joggedSoFar;
};

#endif 



And my .cpp file is as follows

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
39
40
#include <iostream>
#include <cstdlib>
#include <string>

#include "Jogger.h"

using namespace std;

Jogger::Jogger() {
	name = "?name?";
	walkedSoFar  = 0;
	ranSoFar = 0;
	joggedSoFar = 0;
}

Jogger::Jogger (string name)
{
	name = marathoner;
	name = liteWeight;
}

void Jogger::walk(int amount) {
	walkedSoFar = amount;
}

void Jogger::run(int amount) {
	ranSoFar = amount;
}

void Jogger::jog(int amount) {
	joggedSoFar = amount;
}

void Jogger::displayStats(int amount) {
}

void Jogger::clearStats(int amount) {
}





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <cstdlib>
#include <string>

#include "Jogger.h"

using namespace std;

int main( )
{
Jogger marathoner( "Sonia O’Sullivan" );
marathoner.run( 500 );
marathoner.displayStats( );
marathoner.run( 500 );
marathoner.displayStats( );
marathoner.clearStats( );
marathoner.run( 500 );
marathoner.displayStats( );

Jogger liteWeight( "You" );
liteWeight.walk( 10 );
liteWeight.jog( 10 );
liteWeight.displayStats( );
}


The errors I am getting is
------ Build started: Project: Jog, Configuration: Debug Win32 ------
Build started 7/15/2013 1:09:16 AM.
InitializeBuildStatus:
  Touching "Debug\Jog.unsuccessfulbuild".
ClCompile:
  Jogger.cpp
c:\documents and settings\administrator\my documents\visual studio 2010\projects\jog\jog\jogger.h(17): error C2144: syntax error : 'void' should be preceded by ';'
c:\documents and settings\administrator\my documents\visual studio 2010\projects\jog\jog\jogger.cpp(9): error C2511: 'Jogger::Jogger(void)' : overloaded member function not found in 'Jogger'
          c:\documents and settings\administrator\my documents\visual studio 2010\projects\jog\jog\jogger.h(8) : see declaration of 'Jogger'
c:\documents and settings\administrator\my documents\visual studio 2010\projects\jog\jog\jogger.cpp(18): error C2065: 'marathoner' : undeclared identifier
c:\documents and settings\administrator\my documents\visual studio 2010\projects\jog\jog\jogger.cpp(19): error C2065: 'liteWeight' : undeclared identifier
c:\documents and settings\administrator\my documents\visual studio 2010\projects\jog\jog\jogger.cpp(34): error C2511: 'void Jogger::displayStats(int)' : overloaded member function not found in 'Jogger'
          c:\documents and settings\administrator\my documents\visual studio 2010\projects\jog\jog\jogger.h(8) : see declaration of 'Jogger'
c:\documents and settings\administrator\my documents\visual studio 2010\projects\jog\jog\jogger.cpp(37): error C2511: 'void Jogger::clearStats(int)' : overloaded member function not found in 'Jogger'
          c:\documents and settings\administrator\my documents\visual studio 2010\projects\jog\jog\jogger.h(8) : see declaration of 'Jogger'
  Jog.cpp
c:\documents and settings\administrator\my documents\visual studio 2010\projects\jog\jog\jogger.h(17): error C2144: syntax error : 'void' should be preceded by ';'
  Generating Code...

Build FAILED.

Time Elapsed 00:00:01.67
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



I can't figure out how to correct some of these, especially the "jogger.h(8) : see declaration of 'Jogger'
Jog.cpp"
Last edited on
1
2
3
4
5
Jogger::Jogger (string name)
{
	name = marathoner;
	name = liteWeight;
}

marathoner and liteWeight variables are not defined in class and the code would wrong even if those variables were defined. I think that what you want to do is
1
2
3
4
Jogger::Jogger (string name)
{
	this->name = name; // assign constructor parameter 'name' to 'Jogger::name'
}


Also, change

1
2
3
4
5
void Jogger::displayStats(int amount) {
}

void Jogger::clearStats(int amount) {
}

to
1
2
3
4
5
6
void Jogger::displayStats() {

}

void Jogger::clearStats() {
}
Last edited on
this->
IS AMAZING

Thank you

I was able to figure it out except for calling the string name,
which is RADICALLY difficult to find an example just as this anywhere else on the internet...
THANK U!

Was able to complete the program.
Topic archived. No new replies allowed.