In this, we are going to see how to display user input in class in C++ Programming Language.
The Code given below can be used in TURBO C++ Compilers: -
//Member functions used to read and display data
#include<iostream.h>
#include<conio.h>
class emp
{
private:
char name[20];
int ph, sal;
public:
void getdata(void);
void display(void);
};
void emp::getdata(void)
{
cout<<"\n Enter employee name-";
cin>>name;
cout<<"\n Enter employee salary";
cin>>sal;
cout<<"\n Enter phone number-";
cin>>ph;
}
void emp::display(void)
{
cout<<"\n Name:"<<name;
cout<<"\n Salary:"<<sal;
cout<<"\n Phone number"<<ph;
}
void main()
{
emp e;
e.getdata();
e.display();
getch();
}
//.........Coded by ARADHANA MISHRA
The Code given below can be used in gcc/g++ Compilers: -
//Member functions used to read and display data
#include<iostream>
using namespace std;
class emp
{
private:
char name[20];
int ph, sal;
public:
void getdata(void);
void display(void);
};
void emp::getdata(void)
{
cout<<"\n Enter employee name-";
cin>>name;
cout<<"\n Enter employee salary";
cin>>sal;
cout<<"\n Enter phone number-";
cin>>ph;
}
void emp::display(void)
{
cout<<"\n Name:"<<name;
cout<<"\n Salary:"<<sal;
cout<<"\n Phone number"<<ph;
}
int main()
{
emp e;
e.getdata();
e.display();
return 0;
}
//.........Coded by ARADHANA MISHRA
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP