C/C++

Visual Studio. Решение задач

Жители Норвегии, Швеции и Финляндии спорили, где зима холоднее, называя среднюю температуру января в своих столицах. Определите, в каких странах эта температура оказалась ниже средней температуры января в Челябинске (t = — 13°С).
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Terrain {
string name;
double average_temperature;
Terrain(const string& terrain)
: name(terrain), average_temperature(0) {}
Terrain(string&& terrain)
: name(terrain), average_temperature(0) {}
friend bool operator<(const Terrain& a, const Terrain& b) {
return a.average_temperature < b.average_temperature;
}
friend istream& operator>>(istream& inp, Terrain tr) {
return inp >> tr.average_temperature;
}
friend ostream& operator<<(ostream& out, const Terrain& tr) {
return out << tr.name << " " << tr.average_temperature;
}
};
class Climatic {
public:
void add(const Terrain& tr) {
box.push_back(tr);
}
Terrain min()const {
return *min_element(box.begin(), box.end());
}
private:
vector<Terrain> box;
friend ostream& operator<<(ostream& out, const Climatic& c) {
for (const auto& item : c.box) out << item << '\n';
return out;
}
};
Terrain create(const string& name) {
cout << '\t' << name << '\n';
Terrain terrain(name);
cout << "Введите среднюю температуру января: ";
cin >> terrain.average_temperature;
return terrain;
}
int main() {
system("chcp 1251 > nul");
Climatic box;
string country[] = {
"Норвегия",
"Швеция",
"Финляндия"
};
Terrain сhelyabinsk("Челябинск");
сhelyabinsk.average_temperature = -13;
box.add(сhelyabinsk);
for (const auto& name : country) {
auto terrain = create(name);
box.add(terrain);
}
system("cls");
cout << box << '\n';
auto min = box.min();
cout << "Минимум: " << min << '\n';
system("pause > nul");
}
ЧЭ
Чеслав Эд
62 171
Лучший ответ