Create a class named 'Student' with a string variable 'name' and an integer variable
'roll_no'. Assign the value of roll_no as '2' and that of name as "John" by creating an
object of the class Student.
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
std::string _name;
int _roll_no;
public:
Student(const std::string& name, int roll_no) {
_name = name;
_roll_no = roll_no;
}
};
int main()
{
Student s("Dan", 10);
return 0;
}
Comments
Leave a comment