-
Notifications
You must be signed in to change notification settings - Fork 0
/
learn.cpp
133 lines (106 loc) · 2.53 KB
/
learn.cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "learn.h"
int Learn::addition(int a,int b){
return (a+b);
}
int Learn::subtraction(int a,int b){
return (a-b);
}
void CRectangle::set_values (int a, int b) {
width = a;
height = b;
}
void Learn::test(){
CRectangle a, *b, *c;
CRectangle * d = new CRectangle[2];
b= new CRectangle;
c= &a;
a.set_values (1,2);
b->set_values (3,4);
d->set_values (5,6);
d[1].set_values (7,8);
cout << "a area: " << a.area() << endl;
cout << "*b area: " << b->area() << endl;
cout << "*c area: " << c->area() << endl;
cout << "d[0] area: " << d[0].area() << endl;
cout << "d[1] area: " << d[1].area() << endl;
}
CVector::CVector (int a, int b) {
x = a;
y = b;
}
CVector CVector::operator+ (CVector param) {
CVector temp;
temp.x = x + param.x;
temp.y = y + param.y;
return (temp);
}
// double Learn::betsy(int lns) {
// return 0.05 * lns;
// }
// double Learn::pam(int lns) {
// return 0.03 * lns * 0.004 *lns *lns;
// }
// void Learn::estimate(int lines, double (*pf)(int)) {
// cout << lines << "lines will take";
// cout << (*pf)(lines) << "hour(s)\n";
// }
void Learn::swapr(int& a,int& b) {
int temp;
temp = a;
a = b;
b = temp;
}
void Learn::swapp(int* p,int* q) {
int temp;
temp = *p;
*p = *q;
*q = temp;
}
void Learn::swapv(int a,int b) {
int temp;
temp = a;
a = b;
b = temp;
}
void Learn::test1(){
CVector a (3,1);
CVector b (1,2);
CVector c;
c = a + b;
cout << c.x << "," << c.y<<endl;
}
void Learn::test2(){
int i=5, j=6, k;
long l=10, m=5, n;
k=GetMax(i,j);
n=GetMax(l,m);
cout << k << endl;
cout << n << endl;
//注意传入类型要写
pairs<int> myobject(100, 75);
cout<< myobject.getmax()<<endl;
}
// void Learn::test3() {
// int code;
// cout << "How mang lines of code do you need?";
// cin >> code;
// cout << "Here`s Betsy`s estimate:";
// estimate(code,betsy);
// cout << "Here`s Pam`s estimate:";
// estimate(code,pam);
// }
void Learn::test4() {
int wallet1 = 300;
int wallet2 = 350;
cout << "wallet1 = $" << wallet1<<endl;
cout << "wallet2 = $" << wallet2<<endl;
swapr(wallet1,wallet2);
cout << "wallet1 = $" << wallet1<<endl;
cout << "wallet2 = $" << wallet2<<endl;
swapp(&wallet1, &wallet2);
cout << "wallet1 = $" << wallet1<<endl;
cout << "wallet2 = $" << wallet2<<endl;
swapv(wallet1,wallet2);
cout << "wallet1 = $" << wallet1<<endl;
cout << "wallet2 = $" << wallet2<<endl;
}