set validation
i have written a class and some code. my next thing to do is put in validation. here is what i have to do:
Modify your StudentGrade class such that the "set" methods perform data validation. A student ID should be in the range of 10000-50000, and a grade should be in the range 0 - 100. Use a single "if" statement (using the && operator) in each "set" method.
Here is my code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
using std::getline;
class StudentGrade
{
public:
//function that sets the student ID
void setStudentID( string number )
{
studentID = number; //store the course name in the object
}
//function that gets the student ID
string getStudentID()
{
return studentID; //returns the objects Student ID
}
void setTestScore( string score )
{
testScore = score;
}
string getTestScore()
{
return testScore;
}
void displayMessage()
{
cout << "Student " << getStudentID() << " has a score of " << getTestScore() << endl;
}
private:
string studentID;
string testScore;
};
int main()
{
string studentIDnumber;
string studentTestscore;
StudentGrade myStudentID;
cout << "Student ID is: " <<myStudentID.getStudentID() << endl;
cout << "\nPlease enter the Student ID number:" << endl;
getline( cin, studentIDnumber );
myStudentID.setStudentID( studentIDnumber );
cout << endl;
cout << "Student test score is: " <<myStudentID.getTestScore() << endl;
cout << "\nPlease enter the Student Test Score:" << endl;
getline( cin, studentTestscore );
myStudentID.setTestScore( studentTestscore );
cout << endl;
myStudentID.displayMessage();
return 0;
}
every time i try and put in the data validation and the if statement it crashes the program. what am i doing wrong? how do i put in the data validation?
|