Advertisement
kokokozhina

struct_1

Dec 11th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #include <iostream> //exercise 1
  2. #include <string> //create structure STUDENT, which includes full name, birth's year, marks for session
  3. #include <vector> //output - names of students, which average mark is higher than predetermined number
  4. #include <fstream> //example of input-file(for this example k = 5): Kozhina Olga Olegovna 1234 5 4 3 2 1
  5.  
  6. using namespace std;
  7.  
  8. int k; //amount of marks; for comfortable counting of average mark
  9.  
  10. struct Student
  11. {
  12.         Student(){};
  13.         string surname, name, patrinymic_name;
  14.         int birth_year;
  15.         int* marks;
  16.         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) {};
  17.  
  18.         double averageMark()
  19.         {
  20.             double sum = 0;
  21.             for(int i = 0; i < k; i++)
  22.                 sum += *(marks + i);
  23.             return sum / k;
  24.         }
  25. };
  26.  
  27.  
  28. int main()
  29. {
  30.     ifstream in("input.txt");
  31.     ofstream out("output.txt");
  32.    
  33.     double n;
  34.     cout << "Enter the border: ";
  35.     cin >> n;
  36.  
  37.     vector<Student> student;
  38.    
  39.     cout << "How many exams do students have to pass? ";
  40.     cin >> k;
  41.    
  42.     while(in.peek() != EOF)
  43.     {
  44.        
  45.         string surname, name, patrinymic_name;
  46.         int birth_year;
  47.         int *marks = new int[k];
  48.  
  49.         in >> surname;
  50.         in >> name;
  51.         in >> patrinymic_name;
  52.         in >> birth_year;
  53.  
  54.         for(int i = 0; i < k; i++)
  55.             in >> *(marks + i);
  56.         student.push_back(Student(surname, name, patrinymic_name, birth_year, marks));
  57.     }
  58.  
  59.     for(unsigned int i = 0; i < student.size(); i++)
  60.     {
  61.         if (student[i].averageMark() > n)
  62.             out << student[i].surname << " "  << student[i].name << " " << student[i].patrinymic_name << endl;
  63.     }
  64.  
  65.     in.close();
  66.     out.close();
  67.     system("pause");
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement