Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ЗАДАНИЕ 7.10 (1)
- // Создать массив, элементами которого являются структуры:
- // список стран (название, площадь, столица, население).
- // Вывести информацию по странам с населением,
- // меньшим введенного пользователем значения
- #include <iostream> // Для ВВОДА и ВЫВОДА
- #include <string> // Для string
- using namespace std; // ПРОСТРАНСТВО ИМЁН
- int const size = 5; // Кол-во стран
- // Структура Страна
- struct country {
- string name; // Название страны
- string area; // Площадь страны
- string capital; // Название столицы
- // Численость населения
- unsigned long int population;
- };
- int main() {
- // Создание массива структур Учеников
- country countrys[size];
- // Цикл ввода данных
- for (int i = 0; size > i; i++) {
- string str;
- cout << "Enter name " << i + 1 << " country: ";
- getline(cin, str);
- countrys[i].name = str;
- cout << "Enter area " << i + 1 << " country: ";
- getline(cin, str);
- countrys[i].area = str;
- cout << "Enter name capital " << i + 1 << " country: ";
- getline(cin, str);
- countrys[i].capital = str;
- cout << endl;
- }
- // Цикл ввода Числености населения стран
- for (int i = 0; size > i; i++) {
- cout << "Enter population " << countrys[i].name << ": ";
- cin >> countrys[i].population;
- }
- cout << endl;
- // Ввод искомой Числености населения
- cout << "Enter search population: ";
- int population;
- cin >> population;
- cout << "====================" << endl;
- // Перебор всех стран
- for (int i = 0; size > i; i++) {
- // Если у страны население меньше искомой
- if (countrys[i].population < population) {
- // Выводится ее информация
- cout << "Country: " << countrys[i].name << endl;
- cout << "Area: " << countrys[i].area << endl;
- cout << "Capital: " << countrys[i].capital << endl;
- cout << "Population: " << countrys[i].population << endl;
- cout << "====================" << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement