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
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
Any push in the right direction would be a TREMENDOUS relief
If this is your first time using classes, your work doesn't seem all that bad. I'm not sure exactly what kind of trouble you're having so I'll just give a bit of generic advice about classes.
Use them to represent "things" you want to work with; in this case, a "jogger" is one of those things, so you created a class to represent it. The members (variables inside the class) represent information or otherwise internal data about the class. In this case, the amount of miles ran/walked/c. were that kind of information. Methods (functions in the class) should be things you'll want to ask the class to do for you with its data, such as printing it.
It seems like you have the idea right, so what exactly aren't you sure about?
Well, My main problem that I am having trouble with is the other .cpp file that goes with a class file that sort of "directs" the classes in the right way,
I am looking at other examples of this and can't quite seem to figure out how to even get started
For Example, How do I tell the program to recognize a jogger as "marathoner" and then print the walkedSoFar, or ranSoFar, or joggedSoFar as values.
That second .cpp file is what is really stumping me. For some reason, it just makes no sense.
Again,
I was able to put together what I have already by sort of 'cherry picking' similar examples from similar programs-- which is how I learn C++ best-- through example..
Our instructor likes a more independent study approach and on this particular topic, there isn't any example I can find that makes completing this program any easier...
Basically the .cpp file for the class is just a definition of what the methods of the class do. I assume you already know how to define functions, so it's really just a similar process to that.
I think the thing that is stalling me a little bit that I keep looking at are specifically how to implement "displayStats()" and how to assign the string name as marathoner or liteWeight
This is what I came up with for the definition .cpp