In this program we will create class of student and enter his record using setter and getter function with one extra function of display.
The code is given below.
//Code starts
#include<iostream>
#include<conio.h>
using namespace std;
class stu
{
private:
char
nam[30],id[30];
float
cgpa;
public:
char
setname();
char
setid();
float
setcgpa();
char*
getname();
char*
getid();
float
getcgpa();
void
display();
};
char stu::setname()
{
cout<<"Enter
Student's name: ";
cin>>nam;
}
char stu::setid()
{
cout<<"Enter
Student's ID: ";
cin>>id;
}
float stu::setcgpa()
{
cout<<"Enter
CGPA of Student: ";
cin>>cgpa;
}
char* stu::getname()
{
return nam;
}
char* stu::getid()
{
return id;
}
float stu::getcgpa()
{
return cgpa;
}
void stu::display()
{
stu s; //creating object of class
s.setname();
s.setid();
s.setcgpa();
}
int main()
{
stu s1; //creating
object of class
s1.display();
getch();
}
//code ends
0 comments:
Post a Comment