Answer to Question #293577 in C++ for Ianidy

Question #293577

A proposed system intends to store the student data (Student Number, Student Name and Phone Number) and also allow for the access of the same data. The data should be hidden and not prone to direct manipulation. The data is read and written using methods.



Required:



(i) Create a class called Student for the above scenario in C++ (6 marks)



(ii) Write a main function in the same C++ program to instantiate an object from the class Student, and allow for student data to be inputted though the keyboard and then display that student data.




1
Expert's answer
2022-02-03T08:38:29-0500
#include <iostream>
#include <string>


using namespace std;


class Student{
private:
	string number;
	string name;
	string phoneNumber;
public:
	Student(){}


	void setNumber(string number){
		this->number=number;
	}
	void setName(string name){
		this->name=name;
	}
	void setPhoneNumber(string phoneNumber){
		this->phoneNumber=phoneNumber;
	}




	string getNumber(){
		return number;
	}
	string getName(){
		return name;
	}
	string getPhoneNumber(){
		return phoneNumber;
	}


};






int main(){
	string number;
	string name;
	string phoneNumber;
	
	cout<<"Enter Student Number: ";
	getline(cin,number);
	cout<<"Enter Student Name: ";
	getline(cin,name);
	cout<<"Enter Student Phone Number: ";
	getline(cin,phoneNumber);
	


	Student student;
	student.setNumber(number);
	student.setName(name);
	student.setPhoneNumber(phoneNumber);




	cout<<"Student Number: "<<student.getNumber()<<"\n";
	cout<<"Student Name: "<<student.getName()<<"\n";
	cout<<"Student Phone Number: "<<student.getPhoneNumber()<<"\n";




	getline(cin,number);
	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