Create a Student class, where attributes associated with each student are name, registration
number, father name, degree and department. All attributes should not be accessed directly.
One can view the details of all students. Note student attributes cannot be changed by any
means after initialization. (Hint use constant objects)
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
string name;
string registrationNumber;
string fatherName;
string degree;
string department;
public:
Student(){
}
void input(){
cout<<"Enter Student name: ";
getline(cin,name);
cout<<"Enter Student registration number: ";
getline(cin,registrationNumber);
cout<<"Enter Student father name: ";
getline(cin,fatherName);
cout<<"Enter Student degree: ";
getline(cin,degree);
cout<<"Enter Student department: ";
getline(cin,department);
}
void displayDetails(){
cout<<"The Student name is: "<<this->name<<"\n";
cout<<"The Student registration number is: "<<this->registrationNumber<<"\n";
cout<<"The Student father name is: "<<this->fatherName<<"\n";
cout<<"The Student degree is: "<<this->degree<<"\n";
cout<<"The Student department is: "<<this->department<<"\n";
}
~Student(){
}
};
int main(){
Student s;
s.input();
s.displayDetails();
system("pause");
return 0;
}
Comments
Leave a comment