Que- make a program by using class?
#include<iostream>
using namespace std;
class krishna
{
private:
int roll, classroom,age;
string name;
public:
void getdata ()
{
cout<<"enter your name : ";
cin>>name;
cout<<"enter your age : ";
cin>>age;
cout<<"enter your class room no. : ";
cin>>classroom;
cout<<"enter your roll no. : ";
cin>>roll;
}
void display ()
{
cout<<"your name : "<<name<<endl;
cout<<"your roll no. : "<<roll<<endl;
cout<<"your class room no. : "<<classroom<<endl;
cout<<"your age :"<<age;
}
};
int main()
{
krishna ob ;
ob.getdata();
ob.display();
return 0;
}
Result:-
Tags
Class example