Answer to Question #260831 in C++ for AB Agha

Question #260831

Create a class named 'Student' with a string variable 'name' and an integer variable



'roll_no'. Set the values of roll_no and name by the help of a ‘set’ function. After that also



display the values.

1
Expert's answer
2021-11-03T17:30:28-0400


#include <iostream>
#include <string>
using namespace std; 


class Student{
private:
	string name;
	int roll_no;
public:


	void setName(string name){
		this->name=name;
	}


	void setRollNo(int roll_no){
		this->roll_no=roll_no;
	}


	void display(){
		cout<<"Name: "<<name<<"\n";
		cout<<"Roll no: "<<roll_no<<"\n";
	}
	
};






int main(){ 


	Student student;
	student.setName("Peter Smith");
	student.setRollNo(855501);
	student.display();


	int k;
	cin>>k;
	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
APPROVED BY CLIENTS