-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.cpp
More file actions
executable file
·63 lines (59 loc) · 1.15 KB
/
template.cpp
File metadata and controls
executable file
·63 lines (59 loc) · 1.15 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
#include <iostream>
using namespace std;
template <class Any>
void Swap(Any &a,Any &b);
struct job {
char name[200];
double salary;
int floor;
};
template <>
void Swap<job>(job &,job & );
int main(void)
{
int i=10,j=99;
double e=23.7,f=168.8;
job a = {"Mike",2000.0,3};
job b = {"John",3000.0,4};
cout<<"i="<<i<<endl;
cout<<"j="<<j<<endl;
cout<<"e="<<e<<endl;
cout<<"f="<<f<<endl;
cout<<a.name<<endl;
cout<<"Salary:"<<a.salary<<endl;
cout<<"Floor:"<<a.floor<<endl;
cout<<b.name<<endl;
cout<<"Salary:"<<b.salary<<endl;
cout<<"Floor:"<<b.floor<<endl;
Swap(i,j);
Swap(e,f);
Swap(a,b);
cout<<"i="<<i<<endl;
cout<<"j="<<j<<endl;
cout<<"e="<<e<<endl;
cout<<"f="<<f<<endl;
cout<<a.name<<endl;
cout<<"Salary:"<<a.salary<<endl;
cout<<"Floor:"<<a.floor<<endl;
cout<<b.name<<endl;
cout<<"Salary:"<<b.salary<<endl;
cout<<"Floor:"<<b.floor<<endl;
return 0;
}
template <class Any>
void Swap(Any &a,Any &b)
{
Any temp;
temp=a;
a=b;
b=temp;
}
template <>
void Swap<job>(job &a,job &b)
{
job temp=a;
a.salary=b.salary;
a.floor=b.floor;
b.salary=temp.salary;
b.floor=temp.floor;
}