Write an executable C++ program to display name of your department using the input and output operation.
#include <iostream>
#include <string>
using namespace std;
class Department
{
string depName;
public:
Department(){}
friend istream& operator>> (istream& , Department&);
friend ostream& operator<< (ostream& , Department&);
};
istream& operator>> (istream& is, Department &d)
{
getline(is, d.depName, '\n');
return is;
}
ostream& operator<< (ostream& os, Department &d)
{
return os << d.depName;
}
int main()
{
Department x;
cout << "Please, enter the name of department: ";
cin >> x;
cout << "\nThe name of enterd department is "<<x;
}
Comments
Leave a comment