Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <fstream>
- using namespace std;
- struct birthday
- {
- int day;
- int month;
- int year;
- };
- struct STUDENTS
- {
- char surname[20];
- char name[20];
- char familiya[20];
- birthday born;
- int mark;
- int num;
- };
- void sort(STUDENTS* student, int fcount)
- {
- for (int i = 0; i < fcount - 1; i++)
- for (int j = i + 1; j < fcount; j++)
- if (strcmp(student[i].surname, student[j].surname) > 0)
- {
- STUDENTS t = student[i];
- student[i] = student[j];
- student[j] = t;
- }
- }
- int main()
- {
- FILE* fstud;
- fstud = fopen("D://students.bin", "ab");
- fclose(fstud);
- int N;
- int count = 0;
- cout << "How many students in the group?\n";
- cin >> N;
- STUDENTS* student = new STUDENTS[N];
- STUDENTS* fmass = new STUDENTS[N];
- int fcount = 0;
- int q;
- int low_count = 0;
- int mid_count = 0;
- int high_count = 0;
- question:
- cout << "\nВыберите пункт меню: "<< endl;
- cout << "1.Добавить студента. " << endl;
- cout << "2.Показать всех студентов. " << endl;
- cout << "3.Поиск студента по: " << endl;
- cout << "4.Удалить студента по номеру " << endl;
- cout << "5.По оценкам " << endl;
- cin >> q;
- switch (q)
- {
- case 1:
- if (count == N)
- N++;
- cout << "Enter name: ";
- cin >> student[count].name;
- cout << "Enter surname: ";
- cin >> student[count].surname;
- cout << "Enter patronymic: ";
- cin >> student[count].familiya;
- cout << "Enter date of birth(day/space/month/space/year): ";
- cin >> student[count].born.day;
- cin >> student[count].born.month;
- cin >> student[count].born.year;
- cout << "Enter avarage mark from 0 to 100: ";
- cin >> student[count].mark;
- student[count].num = count + 1;
- fopen("students.bin", "ab");
- fwrite(&student[count], sizeof(STUDENTS), 1, fstud);
- fclose(fstud);
- count++;
- goto question;
- case 2:
- fopen("students.bin", "rb");
- for (int i = 0; i < count; i++)
- fread(&fmass[i], sizeof(STUDENTS), 1, fstud);
- sort(fmass, count);
- for (int i = 0; i < count; i++)
- {
- student[i].num = i + 1;
- fmass[i].num = i + 1;
- cout << fmass[i].num << " " << fmass[i].surname << " " << fmass[i].name << " " << fmass[i].familiya << " " << fmass[i].born.day << "." << fmass[i].born.month << "." << fmass[i].born.year << " " << fmass[i].mark;
- cout << "\n";
- }
- fclose(fstud);
- goto question;
- case 3:
- sort(fmass, count);
- fopen("students.bin", "rb");
- cout << "1.By surname\n";
- cout << "2.By marks\n";
- cout << "3.By date of birth\n";
- cin >> q;
- switch (q)
- {
- case 1:
- cout << "Enter surname: ";
- char sur[20];
- cin >> sur;
- for (int i = 0; i < count; i++)
- {
- fread(&fmass[i], sizeof(STUDENTS), 1, fstud);
- if (!strcmp(sur, fmass[i].surname))
- {
- cout << fmass[i].num << " " << fmass[i].surname << " " << fmass[i].name << " " << fmass[i].familiya << " " << fmass[i].born.day << "." << fmass[i].born.month << "." << fmass[i].born.year << " " << fmass[i].mark;
- cout << "\n";
- }
- }
- fclose(fstud);
- goto question;
- case 2:
- cout << "From mark: ";
- int fmark;
- cin >> fmark;
- cout << "To mark: ";
- int tmark;
- cin >> tmark;
- for (int i = 0; i < N; i++)
- {
- if (fmass[i].mark >= fmark && fmass[i].mark <= tmark)
- {
- cout << fmass[i].num << " " << fmass[i].surname << " " << fmass[i].name << " " << fmass[i].familiya << " " << fmass[i].born.day << "." << fmass[i].born.month << "." << fmass[i].born.year << " " << fmass[i].mark;
- cout << "\n";
- }
- }
- fclose(fstud);
- goto question;
- case 3:
- cout << "Enter date of birth(day/space/month)";
- int day1;
- int month1;
- cin >> day1;
- cin >> month1;
- for (int i = 0; i < count; i++)
- {
- fread(&fmass[i], sizeof(STUDENTS), 1, fstud);
- if (fmass[i].born.day == day1 && fmass[i].born.month == month1)
- {
- cout << fmass[i].num << " " << fmass[i].surname << " " << fmass[i].name << " " << fmass[i].familiya << " " << fmass[i].born.day << "." << fmass[i].born.month << "." << fmass[i].born.year << " " << fmass[i].mark;
- cout << "\n";
- }
- }
- fclose(fstud);
- goto question;
- }
- case 4:
- cout << "Enter student's number:";
- int num1;
- cin >> num1;
- fopen("students.bin", "wb");
- for (int i = num1 - 1; i < count - 1; i++)
- {
- strcpy(student[i].name, student[i + 1].name);
- strcpy(student[i].surname, student[i + 1].surname);
- strcpy(student[i].familiya, student[i + 1].familiya);
- student[i].born.day = student[i + 1].born.day;
- student[i].born.month = student[i + 1].born.month;
- student[i].born.year = student[i + 1].born.year;
- student[i].mark = student[i + 1].mark;
- student[i].num = student[i + 1].num;
- }
- for (int i = 0; i < count - 1; i++)
- fwrite(&student[i], sizeof(STUDENTS), 1, fstud);
- fclose(fstud);
- count--;
- goto question;
- case 5:
- low_count = 0;
- mid_count = 0;
- high_count = 0;
- fopen("low_mark.bin", "wb");
- fclose(fstud);
- fopen("mid_mark.bin", "wb");
- fclose(fstud);
- fopen("high_mark.bin", "wb");
- fclose(fstud);
- sort(student, count);
- for (int i = fcount; i < count; i++)
- {
- if (student[i].mark < 50)
- {
- low_count++;
- fopen("low_mark.bin", "ab");
- fwrite(&student[i], sizeof(STUDENTS), 1, fstud);
- fclose(fstud);
- }
- else
- if (student[i].mark < 70)
- {
- mid_count++;
- fopen("mid_mark.bin", "ab");
- fwrite(&student[i], sizeof(STUDENTS), 1, fstud);
- fclose(fstud);
- }
- else
- if (student[i].mark < 101)
- {
- high_count++;
- fopen("high_mark.bin", "ab");
- fwrite(&student[i], sizeof(STUDENTS), 1, fstud);
- fclose(fstud);
- }
- }
- STUDENTS low[5];
- STUDENTS mid[5];
- STUDENTS high[5];
- cout << "1.High mark students \n";
- cout << "2.Middle mark students\n";
- cout << "3.Low mark students\n";
- cin >> q;
- switch (q)
- {
- case 1:
- fopen("high_mark.bin", "rb");
- for (int i = 0; i < high_count; i++)
- fread(&high[i], sizeof(STUDENTS), 1, fstud);
- for (int i = 0; i < high_count; i++)
- {
- cout << high[i].num << " " << high[i].surname << " " << high[i].name << " " << high[i].familiya << " " << high[i].born.day << "." << high[i].born.month << "." << high[i].born.year << " " << high[i].mark;
- cout << "\n";
- }
- fclose(fstud);
- goto question;
- case 2:
- fopen("mid_mark.bin", "rb");
- for (int i = 0; i < mid_count; i++)
- fread(&mid[i], sizeof(STUDENTS), 1, fstud);
- for (int i = 0; i < mid_count; i++)
- {
- cout << mid[i].num << " " << mid[i].surname << " " << mid[i].name << " " << mid[i].familiya << " " << mid[i].born.day << "." << mid[i].born.month << "." << mid[i].born.year << " " << mid[i].mark;
- cout << "\n";
- }
- fclose(fstud);
- goto question;
- case 3:
- fopen("low_mark.bin", "rb");
- for (int i = 0; i < low_count; i++)
- fread(&low[i], sizeof(STUDENTS), 1, fstud);
- for (int i = 0; i < low_count; i++)
- {
- cout << low[i].num << " " << low[i].surname << " " << low[i].name << " " << low[i].familiya << " " << low[i].born.day << "." << low[i].born.month << "." << low[i].born.year << " " << low[i].mark;
- cout << "\n";
- }
- fclose(fstud);
- goto question;
- }
- goto question;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement