-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtemp_operator.cpp
More file actions
81 lines (69 loc) · 1.49 KB
/
temp_operator.cpp
File metadata and controls
81 lines (69 loc) · 1.49 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <string>
#include <vector>
using namespace std;
template <typename object>
class MemoryCell
{
public:
explicit MemoryCell(const object& initvalue = object())
:storedvalue(initvalue) {}
const object& read() const
{return storedvalue;}
void write(const object& x)
{storedvalue = x;}
private:
object storedvalue;
};
template <typename comparable>
const comparable& findMax( const vector<comparable>& a)
{
int Maxindex = 0;
for (int i = 0; i < a.size(); i++)
{
if(a[Maxindex] < a[i])
{
Maxindex = i;
}
}
return a[Maxindex];
}
class employee
{
public:
void setValue(const string& n, int s){
name = n;
salary = s;
}
const string getName() const{
return name;
}
void print(ostream & out) const{
out << name << "(" << salary << ")";
}
bool operator< (const employee& rhs) const{
return salary < rhs.salary;
}
private:
string name;
int salary;
};
ostream & operator<< (ostream& out, const employee& rhs){
rhs.print(out);
return out;
}
int main()
{
/*MemoryCell<int> m1;
m1.write(32);
MemoryCell<string> m2("hello");
m2.write(m2.read() + " world");
cout << m1.read() << endl;
cout << m2.read() << endl;*/
vector<employee> v(3);
v[0].setValue("a", 100);
v[1].setValue("b", 200);
v[2].setValue("c", 300);
cout << findMax(v) << endl;
return 0;
}