I have a class student and constructor for name and age but latter on student must be able to edit that info. I tried following but edit info dont work:
class Student{
public:
string name;
int age;
int grades[3];
int assignments[4];
Student(string name, int age){
this->name = name;
this->age = age;
}
void edit_info(){
string newName;
int newAge;
cout<<"Set new name:";
cin>>newName;
cout<<"Set new age:";
cin>>newAge;
this->name=newName;
this->age=newAge;
}
void show_info(){
cout<<name<<"\n";
cout<<age<<"\n";
}
Code when I chose which student to "play":
if(input == "studentOne"){
cout<<"You are now student 1\n";
cout<<"What is your name:";
cin >> s1_name;
cout<<"How old are you:";
cin >> s1_age;
Student student1(s1_name, s1_age);
while(true){
CMD(student1);
}
and CMD function:
void CMD(Student student){
string command;
cout<<"Type your command(edit_info, submit_assignments, sitFortest, show_info):";
cin>>command;
if(command=="edit_info"){
student.edit_info();
}
else if(command=="show_info"){
student.show_info();
}
}