/
Pereroncino
/
Proga
Обзор
Документация
Войти
/
Pereroncino
/
Proga
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
lab8(2).cpp
76 строк
2 KB
Pereroncino
create: lab8(2).cpp
11 май 2026, 14:01
Верифицирован
11 май 2026, 14:01
238e550
Код
Авторство
О чём код?
#include <stdio.h> #include <iostream> #include <string.h> using namespace std; #define N 6 #define K 3 char facNames[K][30] = {"Информатика", "Экономика", "Юриспруденция"}; struct Room { int number; float area; int facIdx; int residents; }; int main() { struct Room dormitory[N]; int i, j; printf("--- Ввод данных о комнатах (%d записей) ---\n", N); printf("Справка по факультетам: 0 - %s, 1 - %s, 2 - %s\n", facNames[0], facNames[1], facNames[2]); for (i = 0; i < N; i++) { printf("\nЗапись №%d\n", i + 1); printf("Номер комнаты: "); scanf("%d", &dormitory[i].number); printf("Площадь комнаты: "); scanf("%f", &dormitory[i].area); printf("ID факультета (0-%d): ", K - 1); scanf("%d", &dormitory[i].facIdx); printf("Кол-во студентов: "); scanf("%d", &dormitory[i].residents); } printf("\n--- Полный список комнат ---\n"); printf("Комната | Площадь | Факультет | Студентов\n"); printf("------------------------------------------------\n"); for (i = 0; i < N; i++) { printf("%-7d | %-7.2f | %-16s | %d\n", dormitory[i].number, dormitory[i].area, facNames[dormitory[i].facIdx], dormitory[i].residents); } printf("\n--- Статистика по факультетам ---\n"); printf("Факультет | Комнат | Студентов | Ср. площадь на чел.\n"); printf("----------------------------------------------------------\n"); for (i = 0; i < K; i++) { int totalRooms = 0; int totalStudents = 0; float totalArea = 0; for (j = 0; j < N; j++) { if (dormitory[j].facIdx == i) { totalRooms++; totalStudents += dormitory[j].residents; totalArea += dormitory[j].area; } } float avgArea = 0; if (totalStudents > 0) { avgArea = totalArea / totalStudents; } printf("%-16s | %-6d | %-9d | %-5.2f\n", facNames[i], totalRooms, totalStudents, avgArea); } return 0; }