I just want to look at your code really quick, just to give suggestions. (As a student who's been through this before)
1 2 3 4 5 6 7 8 9
|
int Video::get_rating()
{
int i;
for( i = 0; i <5; i++)
{
cout << "*" << endl;
}
}
| |
Usually a get-function (also called a getter) has only one job, return the value of a private member. Is there a rating member in your video class? In that case,
int get_rating()
should simply
return rating;
, I'm not saying that rating might not also have to be modified in some way if it requires it, but usually that is done by modifier functions before the getter is used. In main that returned value should be caught by a variable that is waiting for an assignment...
1 2
|
Video bobFallsDown("videoFile", other variables as needed including rating);
int vidRating = bobFallsDown.get_rating();
| |
That's the common practice for getters, setters being just as simple but in the opposite direction (hope that made sense).
If you want to output something to the console, I prefer to call it something like print_rating() or otherwise something clear that it is a console-output function for a specific member, and it should also only do a simple task like your for loop to print the appropriate number of stars. I wouldn't even use endl since I don't know if I want those stars to be part of a larger paragraph (leave that to more complex print functions or for main to deal with). Usually a print function is going to be a void function since it doesn't need to return anything and even better you can type const after its declaration to tell the compiler that the function itself will not change any of the object members.
Also try to keep in mind something called function decomposition. Basically if you have a complex function then try to break it down into littler functions. Like a large print function for the whole object could now be written;
1 2 3 4 5 6 7
|
void Video::print()
{
print_title();
print_address();
print_comment();
print_rating();
}
| |
I know I'm getting a bit dense in "common practice", if your instructor says anything that doesn't fit with what I've said then listen to the teacher, right?