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.
#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();
}
Comments
Leave a comment