Confused on Class definitions

From this point on in our course over the next several weeks we are going to be concentrating on classes--
I am finding it INCREDIBLY difficult to make sense of it :(

Our first 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
#ifndef JOGGER_H
#define JOGGER_H
#include <iostream>
#include <cstdlib>

using namespace std;

class Jogger {
public:
	Jogger(string name);

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

	void   displayStats()
	void   clearStats();

	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
#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( );
}



I was able to get the SKELETON put together but now I've come to a sudden brick wall and am starting to pull out my hair trying to wrap my head around it.
I haven't been able to find a decent example to help me guide my way into understanding it

I am having a terrible time trying to wrap my head around defining any of the classes.

So far 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
#include <iostream>
#include <cstdlib>
#include <string>

#include "Jogger.h"

using namespace std;


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

void Jogger::walk(int amount) {
}

void Jogger::run(int amount) {
}

void Jogger::jog(int amount) {
}

void Jogger::displayStats(int amount) {
}

void Jogger::clearStats(int amount) {
}

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


But I can not direct my logic to make the proper definitions-- and specifically am having trouble figuring out how to implement the DisplayStats() and how to direct the names of the joggers

Any help with this would be a huge relief.
Last edited on
I've since updated this as such

I am still not quite sure how to implement displayStatus()

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

#include "Jogger.h"

using namespace std;


Jogger::Jogger() {
	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) {
}
Last edited on
Topic archived. No new replies allowed.