Advertisement
daniil_mironoff

Ex. 7.10 (1)

May 23rd, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.69 KB | None | 0 0
  1. // ЗАДАНИЕ 7.10 (1)
  2. // Создать массив, элементами которого являются структуры:
  3. // список стран (название, площадь, столица, население).
  4. // Вывести информацию по странам с населением,
  5. // меньшим введенного пользователем значения
  6.  
  7. #include <iostream>         // Для ВВОДА и ВЫВОДА
  8. #include <string>           // Для string
  9.  
  10. using namespace std;        // ПРОСТРАНСТВО ИМЁН
  11.  
  12. int const size = 5;         // Кол-во стран
  13.  
  14. // Структура Страна
  15. struct country {
  16.     string name;            // Название страны
  17.     string area;            // Площадь  страны
  18.     string capital;         // Название столицы
  19.    
  20.     // Численость населения
  21.     unsigned long int population;
  22. };
  23.  
  24. int main() {
  25.     // Создание массива структур Учеников
  26.     country countrys[size];
  27.    
  28.     // Цикл ввода данных
  29.     for (int i = 0; size > i; i++) {
  30.         string str;
  31.        
  32.         cout << "Enter name " << i + 1 << " country: ";
  33.         getline(cin, str);
  34.         countrys[i].name = str;
  35.        
  36.         cout << "Enter area " << i + 1 << " country: ";
  37.         getline(cin, str);
  38.         countrys[i].area = str;
  39.        
  40.         cout << "Enter name capital " << i + 1 << " country: ";
  41.         getline(cin, str);
  42.         countrys[i].capital = str;
  43.        
  44.         cout << endl;
  45.     }
  46.    
  47.     // Цикл ввода Числености населения стран
  48.     for (int i = 0; size > i; i++) {
  49.         cout << "Enter population " << countrys[i].name << ": ";
  50.         cin >> countrys[i].population;
  51.     }
  52.    
  53.     cout << endl;
  54.    
  55.     // Ввод искомой Числености населения
  56.     cout << "Enter search population: ";
  57.     int population;
  58.     cin >> population;
  59.    
  60.     cout << "====================" << endl;
  61.    
  62.     // Перебор всех стран
  63.     for (int i = 0; size > i; i++) {
  64.         // Если у страны население меньше искомой
  65.         if (countrys[i].population < population) {
  66.             // Выводится ее информация
  67.             cout << "Country: " << countrys[i].name << endl;
  68.             cout << "Area: " << countrys[i].area << endl;
  69.             cout << "Capital: " << countrys[i].capital << endl;
  70.             cout << "Population: " << countrys[i].population << endl;
  71.             cout << "====================" << endl;
  72.         }
  73.     }
  74.    
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement