-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraining3.cpp
More file actions
79 lines (70 loc) · 1.4 KB
/
training3.cpp
File metadata and controls
79 lines (70 loc) · 1.4 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
/*
new와 delete
heap 동적 메모리 할당.
new - 메모리 할당
delete - 메모리 해제 new로 할당한 공간만 해제가능
*/
// #include <iostream>
// int main(){
// int arr_size=10;
// int *list = new int[arr_size]; //배열도 할당가능
// for (int i = 0; i < arr_size; i++)
// {
// std::cin >> list[i];
// }
// delete[] list;
// std::cout << "해제" <<std::endl;
// return 0;
// }
#include<iostream>
typedef struct Animal{
int name;
int age;
int health;
int food;
int clean;
} Animal;
void newAnimal(Animal* p,int num){
p = new Animal;
p->name = num;
p->age = 1;
p->health=10;
}
void play(Animal& a){
a.age++;
a.health--;
}
void show_stat(Animal& a){
std::cout
<< a.name<<" "
<< a.age <<" "
<< a.health <<std::endl;
}
int main(){
Animal* list[30];
int input;
int num=0;
while(1){
std::cout <<"입력:"<<std::endl;
std::cin>>input;
if(input == 0){
newAnimal(list[num],num);
num++;
}
else if(input == 1){
for (int i = 0; i < num; i++)
{
play(*list[num]);
}
}
else if(input == 2){
for (int i = 0; i < num; i++)
{
show_stat(*list[i]);
}
}
else{
break;
}
}
}