hi friends, I am new to c++, just learning.
i want the program to access the private member of the class, and have used set and get, and validate when user input. but the program below is not working.
i cant compile it.
can anyone help me, thanks friends.
Code:
#include<iostream>
#include<string>
using namespace std;
class students
{
private :
string name;
string ID;
int age;
public :
string setName(string temp)
{
name = temp;
}
string getName()
{
return name;
}
void setID(int temp)
{
if(temp < 1)
{
cout << " You have enter an invalid ID number ";
exit(1);
}
else
ID = temp;
}
string getID()
{
return ID;
}
void setAge(int temp)
{
if (temp < 1)
{
cout<< " invalid age type"<<"program terminatingt";
exit(1);
}
else if (temp > 150)
{
cout <<" you are not human"<< "program terminating";
exit(1);
}
else
age = temp;
}
int getAge()
{
return age;
}
};
int main()
{
students st;
cout <<" Enter your name : ";
cin >>st.setName();
cout<< "Enter your ID :";
cin >>st.setID();
cout<< " Enter your age :";
cin >>st.setAge();
}