C++ program to show insertion and extraction of user defined objects

#include<iostream>
class emp
{
int eno;
char ename[10];
float sal;
public:
emp(){}
friend ostream & operator << (ostream &, emp &);
friend istream & operator >> (istream &, emp &);
}
ostream & operator << (stream &S, emp&e) // overloading the extraction operator (<<)
{
S << endl << "Eno:" << e.eno;
S << endl << "Ename:" << e.name;
S << endl << "Salary:" << e.sal;
return S;
}
istream & operator >> (istream &S, emp&e) // overloading insertion operator (>>)
{
cout << "Enter eno:";
S >> e.eno;
cout << "Enter name:";
S >> e.name;
cout << "Enter sal:";
S >> e.sal;
return S; // Returning reference
}
void main()
{
emp el;
cin >> el;
cout << el;
}

It's very calm over here, why not leave a comment?

Leave a Reply

You must be logged in to post a comment.