В хорошем виде -
www.cpp.sh/7zzc4
или по мейловски:
#include < iostream >
#include < vector >
#include < string >
using namespace std;
class Student {
private:
string _name;
double _mark;
public:
Student(string name, double mark) {
this->_name = name;
this->_mark = mark;
}
string getStudentName(){
return _name;
}
double getStudentMark(){
return _mark;
}
};
class Lecture{
private:
string _lectureName;
vector< Student > _vecStudent;
public:
Lecture(string lectureName) {
this->_lectureName = lectureName;
}
void addStudent(Student st) {
_vecStudent.push_back(st);
}
void getStudentMarks() {
for (Student st : _vecStudent){
cout << "Lecture " << _lectureName << "/ mark " << st.getStudentMark() << "/ name " << st.getStudentName() << endl;
}
}
void getAverageMark() {
double averageMark = 0;
for (Student st : _vecStudent){
averageMark += st.getStudentMark();
}
averageMark /= _vecStudent.size();
cout << "srednaya ocenka za predmet " << _lectureName << " = " << averageMark << endl;
}
string getLectureName(){
return _lectureName;
}
};
vector< Lecture > exam;
void getStudentMark(string lectureName) {
for (Lecture l : exam) {
if (l.getLectureName() == lectureName)
l.getStudentMarks();
}
}
void getLectureAverageMark(string lectureName) {
for (Lecture l : exam) {
if (l.getLectureName() == lectureName)
l.getAverageMark();
}
}
int main() {
Lecture math("Math");
math.addStudent(Student("vasya", 2));
math.addStudent(Student("petya", 3));
math.addStudent(Student("gena", 4));
Lecture programming("Programming");
programming.addStudent(Student("vasya", 3));
programming.addStudent(Student("petya", 4));
programming.addStudent(Student("gena", 5));
exam.push_back(math);
exam.push_back(programming);
bool x = true;
string lectureName = "";
int menu;
while (x){
cout << "1: vivesti ocenku studentov " << endl;
cout << "2: vivesti vredniy bal predmeta " << endl;
cout << "ina4e = exit" << endl;
cin >> menu;
switch (menu) {
case 1:
cout << "vvedite nazvanie predmeta" << endl;
cin >> lectureName;
getStudentMark(lectureName);
break;
case 2:
cout << "vvedite nazvanie predmeta " << endl;
cin >> lectureName;
getLectureAverageMark(lectureName);
break;
}
}
system("pause");
return 0;
}