Write a C++ program to display your name and matriculation number.
Note: Your full name and matriculation number must be on separate line.
#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;
}
Comments
Leave a comment