Answer to Question #318847 in C++ for Simon

Question #318847

Write a C++ program to display your name and matriculation number.


Note: Your full name and matriculation number must be on separate line.

1
Expert's answer
2022-03-27T07:57:40-0400
#include <iostream>
#include <string>


using namespace std;


class Matriculation_number
{
	string fullName;
	int number;
public:
	Matriculation_number(){}
	friend istream& operator>> (istream&, Matriculation_number&);
	friend ostream& operator<< (ostream& , Matriculation_number&);
};


istream& operator >> (istream& is, Matriculation_number &m)
{
	cout << "\nFullname: ";
	getline(is, m.fullName, '\n');
	cout << "Number: ";
	is >> m.number;
	return is;
}
ostream& operator<< (ostream& os, Matriculation_number &m)
{
	return os << "\nFullname: " << m.fullName<<endl<< "\Number: " <<m.number;
}


int main()
{
	Matriculation_number x;
	cout << "Please, enter the fullname and matriculation number: ";
	cin >> x;
	cout << "\nThe fullname and matriculation number 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