Answer to Question #296586 in C++ for Maryam

Question #296586

Create a class named 'Student' with a string variable 'name' and an integer variable 'roll_no'. Assign the value of roll_no as '20021' and that of name as "Sidra" by creating an object of the class Student.

1
Expert's answer
2022-02-11T10:19:50-0500
#include<iostream>
#include<string>

using namespace std;

class Student
{
	string name;
	int roll_no;
public:
	Student(){}
	Student(string _name, int _roll_no)
	:name(_name),roll_no(_roll_no){}
	void Assign()
	{
		cout << "Please, enter a name: ";
		cin >> name;
		cout << "Please, enter a roll no: ";
		cin >> roll_no;
	}
	void Display()
	{
		cout << "\nInfo about student: "
			<< "\nName is " << name
			<< "\nRoll no is " << roll_no<<endl;
	}
};

int main()
{
	Student a("Sidra", 20021);
	a.Display();
	Student b;
	b.Assign();
	b.Display();
}	

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