#include
#include
#include
#include
using namespace std;
struct Subject {
string title;
unsigned short mark;
Subject() : mark(0) {}
friend istream& operator>>(istream& inp, Subject& s) {
cout << "Назавние предмета: ";
getline(inp, s.title);
cout << "Оценка за предмет: ";
inp >> s.mark;
inp.ignore(inp.rdbuf()->in_avail());
return inp;
}
};
struct Schoolkid {
string name;
string group;
string phone;
vector box;
void input() {
Subject sub;
cin >> sub;
box.push_back(sub);
}
double average()const {
if (box.empty()) return 0;
auto sum = 0.;
for (const auto& x : box) sum += x.mark;
return sum / box.size();
}
void results()const {
cout << fixed << setprecision(2);
cout << name << " " << group << " " << average() << '\n';
}
};
Schoolkid input(size_t m) {
Schoolkid sk;
cout << "Ф. И. О.: ";
getline(cin, sk.name);
cout << "Класс: ";
getline(cin, sk.group);
cout << "Телефон: ";
getline(cin, sk.phone);
for (auto i = 0U; i < m; ++i) {
Subject sub;
cin >> sub;
sk.box.push_back(sub);
}
return sk;
};
unsigned integer(const char* msg) {
cout << msg;
unsigned value;
cin >> value;
cin.ignore(cin.rdbuf()->in_avail());
return value;
}
int main() {
system("chcp 1251 > nul");
auto n = integer("Количество школьников: ");
vector box(n);
auto m = integer("Количество предметов: ");
for (auto& x : box) x = input(m);
puts("");
for (auto& x : box) x.results();
system("pause > nul");
}
