Answer to Question #306421 in C++ for Ahmad

Question #306421

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)

1
Expert's answer
2022-03-05T06:47:51-0500


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog