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