Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #define nmarks 2
- #define nsessions 2
- #define nstudent 3
- using namespace std;
- struct Tstudent
- {
- char FIO[40], exam_name[10];
- unsigned int nkurs, ngroup, exam_mark;
- int marks[nsessions][nmarks];
- bool study_form;
- };
- Tstudent* Read_from_file(ifstream &f)
- {
- Tstudent* temp = new Tstudent;
- f.read((char*)temp,sizeof(Tstudent));
- return temp;
- }
- unsigned int check(int m[nsessions][nmarks])
- {
- bool otl = 1;
- for(int i=0;i<nsessions;i++)
- {
- for(int j=0; j<nmarks; j++)
- if(m[i][j]!=5)
- {
- otl=0;
- break;
- }
- if(!otl)
- break;
- }
- return otl;
- }
- int Task(ifstream &f)
- {
- unsigned int countOtl=0, count_max=0, nk=0, ng=0, ng_max=0;
- unsigned int kurs_not_changed = 1;
- unsigned int group_not_changed = 1;
- Tstudent* temp = new Tstudent;
- cout<<"_____"<<endl;
- while(!f.eof())
- {
- f.read((char*)temp,sizeof(Tstudent));
- if(ng!= temp->ngroup)
- {
- if(count_max<countOtl)
- {
- ng_max=ng;
- count_max = countOtl;
- }
- if(ng!=0)
- group_not_changed = 0;
- ng=temp->ngroup;
- countOtl = 0;
- }
- if (nk==0)
- nk = temp->nkurs;
- if (nk!=temp->nkurs)
- {
- cout<<"|"<<nk<<"|"<<ng_max<<"|"<<endl;
- nk=temp->nkurs;
- countOtl = 0;
- count_max = 0;
- kurs_not_changed = 0;
- }
- countOtl = countOtl + check(temp->marks);
- }
- if(group_not_changed)
- ng_max = ng;
- if(count_max<countOtl)
- {
- ng_max = ng;
- cout<<"|"<<nk<<"|"<<ng_max<<"|"<<endl;
- }
- if(kurs_not_changed)
- cout<<"|"<<nk<<"|"<<ng_max<<"|"<<endl;
- cout<<"_____"<<endl;
- return 0;
- }
- int Write_to_file(Tstudent* st, ofstream &f)
- {
- if(st!=NULL)
- {
- f.write((char*)st,sizeof(Tstudent));
- return 0;
- }
- else
- return 1;
- }
- Tstudent* Read_from_keyboard()
- {
- Tstudent* temp = new Tstudent;
- cout << "Введите ФИО студента ";
- cin >> temp->FIO;
- cout << "Введите номер курса ";
- cin >> temp->nkurs;
- cout << "Введите номер группы ";
- cin >> temp->ngroup;
- cout << "Введите оценки ";
- for(int i=0;i<nsessions;i++)
- for(int j=0;j<nmarks;j++)
- cin >> temp->marks[i][j];
- cout << "Введите форму обучение(1 - очная, 0 - заочная) ";
- cin >> temp->study_form;
- cout << "Введите название экзамена ";
- cin >> temp->exam_name;
- cout << "Введите оценку за экзамен ";
- cin >> temp->exam_mark;
- return temp;
- }
- int main()
- {
- setlocale(0,"");
- char answer;
- cout<<"Create new file?(y/n)";
- cin>>answer;
- if(answer=='y')
- {
- ofstream output_file("student.dat",ios::binary|ios::out);
- for(int i=0;i<nstudent;i++)
- Write_to_file(Read_from_keyboard(),output_file);
- output_file.close();
- ifstream input_file("student.dat",ios::binary|ios::in);
- Task(input_file);
- input_file.close();
- return 0;
- }
- else
- {
- ifstream input_file("student.dat",ios::binary|ios::in);
- Task(input_file);
- input_file.close();
- return 0;
- }
- //return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement