Answer to Question #318848 in C++ for Simon

Question #318848

Write an executable C++ program to display name of your department using the input and output operation.

1
Expert's answer
2022-03-27T07:57:46-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog