Quote:
<< setw(10) << left << student1.displayGPA;
As pointed out above, you can't chain the call to displayGPA into the output stream like that. This poses a problem: you obviously want a specific format, but even if you call displayGPA() correctly, the format specification is done outside the student class, and will be forgotten within the display function!
You stated that your instructions require that displayGPA() returns void. Given that, if you want that formatting. you need to find another way:
1. pass the format specification (alignment, spacing) as additional parameters to your displayGPA() function and apply the formatting within the function
2. add another function to specify the formatting for any display function and store the formatting specifiers within your student class (not a great solution imho. The student class shouldn't have to concern itself with display format info)
3. Add another function to get the GPA value directly rather than having it printed (the only reasonable solution imho)
Quote:
while(students[x].getStudentName() == "-")
Here are some big issues:
1. you are specifically checking for a default value defined within the student class. How is the program using a class supposed to know of that value in general, assuming that the function implementation is in a different source file, or may even only be vailable in binary format as a lib or dll?
1.a) you are also equating that default with an invalid input, which is plain wrong: your loop will accept any input that isn't "-", even an empty string, a string containg numbers or other non-alphabetic characters, all of which are clearly invalid!
2. the way you ask for input and check it's validity are things that only the student class should need to know about, not your main program! This is clearly code that belongs into the student class
3. You (try to) directly stream input from cin into a variable. Apart from the fact that the code is incorrect, you should normally never directly stream input into the final destination variable. How do you know the input is a valid string? How do you know it doesn't somehow cause an issue? Are you willing to overwrite an existing valid value with one that is complete gibberish without checking? A better way is to read the input into a temporary variable, check the validity of that variable, and only then copy it to the true destination. Again, only the student class should need to know how to best handle that, and provide functions for reading these values from an input stream.
Quote:
while(students[x].getStudentNumber() < 1)
Same problem: you are using internal knowledge of the student class, i. e. that a value < 1 is invalid. Leave that code to the student class! Provide a function for reading the student number and checking it properly. Besides, classes are all about reusability. A well implemented class may be used in dozens or hundreds of places within a program. If some time in the future the student format changes to allow for alphanumeric IDs in place of simple numbers, would you rather change your code in hundreds of places - or just within the student class? ;)
Quote:
while(students[x].displayGPA == 0)
Do I need to mention this is the same problem as above? What's more, the restrictionsin your instructions on the function displayGPA() make it impossible to actually check a valid input! Again, put that code inside a function in the student class, and you're fine.
Summary:
1. Add a GetGPA() function to your student class
2. Write member functions for your student class to read their own member variables from cin and do all the querying and validation within those functions
3. Always use temporary variables to hold input from cin. Check before copying them over to the actual destination.
(and you might also want to insert a few more <<endl ;) )