Advertisement
Proff_Ust

students

Oct 5th, 2019
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. #include <fstream>
  4. #define nmarks 5
  5. #define nsessions 2
  6.  
  7. using namespace std;
  8. struct Tstudent
  9. {
  10.     string name, lastname, surname, exam_name;
  11.     unsigned int nkurs, ngroup, exam_mark;
  12.     int marks[nsessions][nmarks];
  13.     bool study_form;
  14. };
  15.  
  16. Tstudent* Read_from_file(ifstream &f)
  17. {
  18.     Tstudent* temp = new Tstudent;
  19.     string s;
  20.     getline(f,temp->lastname);
  21.     if(f.eof())
  22.     {
  23.         delete temp;
  24.         return NULL;
  25.     }
  26.     getline(f,temp->name);
  27.     getline(f,temp->surname);
  28.     f >> temp->nkurs;
  29.     f >> temp->ngroup;
  30.     for ( int i=0; i<nsessions;i++)
  31.         for(int j=0; j<nmarks; j++)
  32.             f >> temp->marks[i][j];
  33.     f >> temp->study_form;
  34.     getline(f, s);
  35.     getline(f,temp->exam_name);
  36.     f >> temp->exam_mark;
  37.     getline(f, s);
  38.     return temp;
  39. }
  40.  
  41. Tstudent* Move_to_next_kurs(Tstudent * st)
  42. {
  43.     if(st!=NULL)
  44.     {
  45.         if(st->nkurs==4)
  46.             return NULL;
  47.         else
  48.         {
  49.             st->nkurs++;
  50.             return st;
  51.         }
  52.     }
  53.     return NULL;
  54. }
  55.  
  56. int Write_to_file(Tstudent* st, ofstream &f)
  57. {
  58.     if(st!=NULL)
  59.     {
  60.         f << st->lastname << endl;
  61.         f << st->name << endl;
  62.         f << st->surname << endl;
  63.         f << st->nkurs << endl;
  64.         f << st->ngroup << endl;
  65.         for ( int i=0; i<nsessions;i++)
  66.             for(int j=0; j<nmarks; j++)
  67.                 f << st->marks[i][j] << " ";
  68.         f << endl;
  69.         f << st->study_form << endl;
  70.         f << st->exam_name << endl;
  71.         f << st->exam_mark << endl;
  72.         return 0;
  73.     }
  74.     else
  75.         return 1;
  76. }
  77.  
  78. int main()
  79. {
  80.     setlocale(0,"Russian");
  81.     ifstream input_file("student.dat.txt");
  82.     ofstream output_file("student_output.dat.txt");
  83.     while(!input_file.eof())
  84.         Write_to_file(Move_to_next_kurs(Read_from_file(input_file)),output_file);
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement