Please teach me how to do this class question and show the full code C++. Create
ID: 3538273 • Letter: P
Question
Please teach me how to do this class question and show the full code C++.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
class student
{
int rollno;
char name[10];
float per;
public:
void getdata()
{
char ch; //to clear buffer
cout<<" Enter Roll No. : ";
cin>>rollno;
cout<<"Enter Name No. : ";
cin.get(ch);
cin.getline(name,10);
cout<<"Enter % : ";
cin>>per;
}
void putdata()
{
cout<<"Roll No. : "<<rollno;
cout<<" Name No. : "<<name;
cout<<" % "<<per;
}
int getrollno()
{
return (rollno);
}
};
void main()
{
student s[5];
int rno;
for(int x=0;x<5;x++)
{
cout<<" Enter Details for student "<<x+1;
s[x].getdata();
}
cout<<" Niw enter rollno of student to be displayed : ";
cin>>rno;
for(x=0;x<5;x++)
{
if(s[x].getrollno()==rno)
{
s[x].putdata();
break;
}
}
if(x==5)
cout<<" Your RollNo does not exists: ";
getch();
}