Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> //exercise 1
- #include <string> //create structure STUDENT, which includes full name, birth's year, marks for session
- #include <vector> //output - names of students, which average mark is higher than predetermined number
- #include <fstream> //example of input-file(for this example k = 5): Kozhina Olga Olegovna 1234 5 4 3 2 1
- using namespace std;
- int k; //amount of marks; for comfortable counting of average mark
- struct Student
- {
- Student(){};
- string surname, name, patrinymic_name;
- int birth_year;
- int* marks;
- Student(string surname, string name, string patrinymic_name, int birth_year, int* marks) : surname(surname), name(name), patrinymic_name(patrinymic_name), birth_year(birth_year), marks(marks) {};
- double averageMark()
- {
- double sum = 0;
- for(int i = 0; i < k; i++)
- sum += *(marks + i);
- return sum / k;
- }
- };
- int main()
- {
- ifstream in("input.txt");
- ofstream out("output.txt");
- double n;
- cout << "Enter the border: ";
- cin >> n;
- vector<Student> student;
- cout << "How many exams do students have to pass? ";
- cin >> k;
- while(in.peek() != EOF)
- {
- string surname, name, patrinymic_name;
- int birth_year;
- int *marks = new int[k];
- in >> surname;
- in >> name;
- in >> patrinymic_name;
- in >> birth_year;
- for(int i = 0; i < k; i++)
- in >> *(marks + i);
- student.push_back(Student(surname, name, patrinymic_name, birth_year, marks));
- }
- for(unsigned int i = 0; i < student.size(); i++)
- {
- if (student[i].averageMark() > n)
- out << student[i].surname << " " << student[i].name << " " << student[i].patrinymic_name << endl;
- }
- in.close();
- out.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement