回答編集履歴
2
微修正
test
CHANGED
@@ -65,7 +65,7 @@
|
|
65
65
|
// Output the weekly temperature data for each city
|
66
66
|
for (int i = 0; i < temperatures.size(); ++i) {
|
67
67
|
std::cout << "Weekly temperature data for " << cities[i] << std::endl;
|
68
|
-
for ( double
|
68
|
+
for ( double temp : temperatures[i] ) {
|
69
69
|
std::cout << std::fixed << std::setprecision(2) << temp << ' ';
|
70
70
|
}
|
71
71
|
std::cout << std::endl;
|
1
追記
test
CHANGED
@@ -36,4 +36,44 @@
|
|
36
36
|
Assignment1();
|
37
37
|
}
|
38
38
|
```
|
39
|
+
[追記] C++ に寄せたやつ。
|
40
|
+
```C++
|
41
|
+
#include <iostream>
|
42
|
+
#include <iomanip>
|
43
|
+
#include <array>
|
44
|
+
#include <string>
|
39
45
|
|
46
|
+
void Assignment1() {
|
47
|
+
|
48
|
+
// Define a two-dimensional array to hold the weekly temperature data for all cities
|
49
|
+
const int num_cities = 3;
|
50
|
+
const int num_weeks = 5;
|
51
|
+
std::array<std::array<double,num_weeks>,num_cities> temperatures;
|
52
|
+
|
53
|
+
// Define an array of city names
|
54
|
+
const std::string cities[num_cities] = { "New York", "Los Angeles", "Chicago" };
|
55
|
+
|
56
|
+
// Input the weekly temperature data for each city
|
57
|
+
|
58
|
+
for (int i = 0; i < temperatures.size(); ++i ) {
|
59
|
+
std::cout << "Enter the weekly temperature data for " << cities[i] << std::endl;
|
60
|
+
for ( double& temp : temperatures[i] ) {
|
61
|
+
std::cin >> temp;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
// Output the weekly temperature data for each city
|
66
|
+
for (int i = 0; i < temperatures.size(); ++i) {
|
67
|
+
std::cout << "Weekly temperature data for " << cities[i] << std::endl;
|
68
|
+
for ( double& temp : temperatures[i] ) {
|
69
|
+
std::cout << std::fixed << std::setprecision(2) << temp << ' ';
|
70
|
+
}
|
71
|
+
std::cout << std::endl;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
int main() {
|
76
|
+
Assignment1();
|
77
|
+
}
|
78
|
+
```
|
79
|
+
|