-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathas1.cpp
More file actions
73 lines (56 loc) · 1.2 KB
/
as1.cpp
File metadata and controls
73 lines (56 loc) · 1.2 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
#include <iostream>
#include <string>
using namespace std;
class weight {
public :
int kg;
int gram;
weight();
void set_weight(int n1, int n2);
int get_weight();
};
weight::weight()
{
kg = 0;
gram = 0;
}
void weight::set_weight(int n1, int n2)
{
kg = n1;
gram = n2;
}
int weight::get_weight()
{
return (kg * 1000) + gram ;
}
weight add_weight(weight n1, weight n2)
{
weight t;
t.kg = n1.kg + n2.kg;
t.gram = n1.gram + n2.gram;
return t;
}
int less_than(weight n1, weight n2)
{
if(n1.kg < n2.kg)
return 1;
else if(n1.kg == n2.kg)
{
if(n1.gram < n2.gram)
return 1;
return 0;
}
return 0;
}
int main( )
{
weight w1, w2, w3 ; // weight라는 class object 3개 생성
w1.set_weight(3, 400); // w1을 3kg 400 g으로
w2.set_weight(2, 700); // w2을 2kg 700 g으로
w3 = add_weight(w1, w2); // w1과 w2을 더하여 w3에 à w3는 6kg 100g
cout << w3.get_weight( ) << "grams\n"; // w3의 값 ‘6100 grams’ 출력
if ( less_than(w1, w2) ) // w1이 w2보다 작은 값인가 판단
cout << "yes.\n";
else
cout << "no. \n"; // 작지 않으므로 ‘no’ 출력
}