alpha
Login
or
Join now
shuuji3.xyz
/
yasashii-cpp
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
[READ-ONLY] Mirror of https://github.com/shuuji3/yasashii-cpp. Codes for "やさしいC++ 5th edition"
books.google.co.jp/books?id=JHe2tAEACAAJ
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
Solve problem 11 with my arrangement
author
TAKAHASHI Shuuji
date
7 years ago
(Aug 26, 2019, 11:18 AM +0900)
commit
94ad7c4f
94ad7c4f343627d2667edda1defb705632141346
parent
a26b95ff
a26b95ffeaf0b83ee98913c0fb31b296ccdc3ca3
+46
2 changed files
Expand all
Collapse all
Unified
Split
CMakeLists.txt
src
lesson-11
main.cpp
+1
CMakeLists.txt
View file
Reviewed
···
4
4
set(CMAKE_CXX_STANDARD 14)
5
5
6
6
add_executable(lesson7 src/lesson-7/main.cpp)
7
7
+
add_executable(lesson11 src/lesson-11/main.cpp)
+45
src/lesson-11/main.cpp
View file
Reviewed
···
1
1
+
#include <iostream>
2
2
+
3
3
+
struct Person {
4
4
+
int age;
5
5
+
double height;
6
6
+
};
7
7
+
8
8
+
void aging(Person &p);
9
9
+
void showPerson(const Person &p);
10
10
+
11
11
+
int main() {
12
12
+
const int num = 2;
13
13
+
auto persons = new Person[num];
14
14
+
15
15
+
for (int i = 0; i < num; i++) {
16
16
+
std::cout << i + 1 << "人目の年齢を入力してください: " << std::endl;
17
17
+
std::cin >> persons[i].age;
18
18
+
std::cout << i + 1 << "人目身長を入力してください: " << std::endl;
19
19
+
std::cin >> persons[i].height;
20
20
+
}
21
21
+
22
22
+
for (int i = 0; i < num; i++) {
23
23
+
std::cout << i + 1 << "人目: ";
24
24
+
showPerson(persons[i]);
25
25
+
}
26
26
+
27
27
+
aging(persons[0]);
28
28
+
aging(persons[1]);
29
29
+
std::cout << "歳を取りました" << std::endl;
30
30
+
31
31
+
for (int i = 0; i < num; i++) {
32
32
+
std::cout << i + 1 << "人目: ";
33
33
+
showPerson(persons[i]);
34
34
+
}
35
35
+
36
36
+
delete[] persons;
37
37
+
}
38
38
+
39
39
+
void showPerson(const Person &p) {
40
40
+
std::cout << "年齢 = " << p.age << ", 身長 = " << p.height << std::endl;
41
41
+
}
42
42
+
43
43
+
void aging(Person &p) {
44
44
+
p.age++;
45
45
+
}