Please teach me how to do this class question and show the f



Please teach me how to do this class question and show the full code C++.


Create a class called Student The data members are; name(char), location(char), ic(char) and age(int). All data members must be dedared as private. The member functions are ; void set_data () and void print (). All member functions must be declared as public. In member function get set_data(), get input from the user and set the values to the data members. In member function print(), display all the information on screen. In function main(), create an object of class Student called S1. From main(), call both member functions set_data() and print(). Save and compile your codes, correct any errors encountered. Execute your program.

Solution


#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();

}


Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site