College Residency

I am trying to write a portion of my program that will ask a student to input whether they are a Resident or Non-Resident. In the class definition, I have char residency; listed, but have no idea where or how to make the statement that only 'N' for Non-Resident or 'R' for Resident will be accepted. Will this go in the Void Print function, or do I need to place it in the MAIN Function of the program? Lastly, what would the code even look like? Thank you.
If the residency can only accept N or R, that should be in the constructor of the class (and in the methods that modifies residency)
1
2
3
4
5
6
7
8
9
class studend{
private: 
   char residency;
public: 
   student(char r){
      if(r!='N' && r!='R')
          throw some_error;
   }
}

This way the object will not be constructed with a wrong state
Last edited on
Topic archived. No new replies allowed.