-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwork31.cpp
More file actions
52 lines (51 loc) · 1.16 KB
/
Copy pathwork31.cpp
File metadata and controls
52 lines (51 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <string>
using namespace std;
class Singer
{
private:
string name;
char sex;
int age;
double num;
public:
string getName()
{
return name;
}
friend bool operator==(Singer s1,Singer s2)
{
return s1.num == s2.num;
}
friend bool operator>(Singer s1, Singer s2)
{
return s1.num > s2.num;
}
friend bool operator<(Singer s1, Singer s2)
{
return s1.num < s2.num;
}
friend ostream &operator<<(ostream& os,Singer& s)
{
os << s.name << " " << s.sex << " " << s.age << " " << s.num;
return os;
}
friend istream &operator>>(istream &is,Singer& s)
{
is >> s.name >> s.sex >> s.age >> s.num;
return is;
}
};
int main()
{
Singer s1, s2;
cin >> s1 >> s2;
cout << s1 << "\n"<< s2 << endl;
if (s1 > s2)
cout << s1.getName() << "'s score is higher than " << s2.getName() << "'s.\n";
else if (s1 == s2)
cout << s1.getName() << "'s score is equal to " << s2.getName() << "'s.\n";
else
cout << s1.getName() << "'s score is lower than " << s2.getName() << "'s.\n";
return 0;
}