Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //В массиве хранится информация о количестве жильцов
- //каждой квартиры пятиэтажного дома(4 подъезда, на
- //каждом этаже по 2 квартиры).
- //а) по выбранному номеру квартиры определить количество жильцов, а также их соседей проживающих
- //на одном этаже;
- //б) определить суммарное количество жильцов для
- //каждого подъезда;
- //в) определить номера квартир, где живут многодетные
- //семьи.Условно будем считать таковыми, у которых
- //количество членов семьи превышает пять человек.
- #include "pch.h"
- #include <iostream>
- #include <time.h>
- using namespace std;
- int main()
- {
- //початкові параметри
- //srand(time(0)); // настройка рандомізатора
- const int flats = 40; // кількість квартир = кількість елементів масива
- int people[flats] = { 0 }; //масив
- int currFlat = 0;
- int one = 0, two = 0, three = 0, four = 0;
- int multiKid[flats] = {0};
- //заповнити масив
- for (int i = 0; i < flats; i++) {
- people[i] = rand() % 7;
- }
- //варіант а
- cout << "Enter flat number" << endl;
- cin >> currFlat;
- cout << "Flat " << currFlat << " : " << people[currFlat-1] << " peoples" << endl;
- (currFlat-1) % 2 == 0 ?
- (cout << "Neighbors: Flat " << currFlat+1 << " : " << people[currFlat] << " peoples" << endl) :
- (cout << "Neighbors: Flat " << currFlat-1 << " : " << people[currFlat] << " peoples" << endl);
- cout << endl;
- //варіант б
- for (int i = 0; i < flats; i++) {
- if (i >= 0 and i <= 9) {
- one += people[i];
- }
- else if (i >= 10 and i <= 19) {
- two += people[i];
- }
- else if (i >= 20 and i <= 29) {
- three += people[i];
- }
- else if (i >= 30 and i <= 39) {
- four += people[i];
- }
- }
- cout << "Podyezd 1: " << one << "\nPodyezd 2: " << two << "\nPodyezd 3: " << three << "\nPodyezd 4: " << four << endl;
- cout << endl;
- //варiант в
- for (int i = 0, j=0; i < flats; i++) {
- if (people[i] > 5) {
- multiKid[j] = i+1;
- j++;
- }
- }
- cout << "Families with multiple kids flats:";
- for (int i = 0; i < flats; i++) {
- if (multiKid[i] > 0)
- {
- cout << " " << multiKid[i] << " ";
- }
- }
- cout << endl;
- }
Add Comment
Please, Sign In to add comment