Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<string>
- using namespace std;
- const int n = 100;
- fstream infile;
- fstream outfile;
- class studenty {
- public:
- struct student {
- string name;
- int kurs;
- int mark;
- };
- student u[n];
- int l;
- void vvod() {
- int i, k;
- cout << "Введите количество студентов" << endl;
- cin >> k;
- this->l = k;
- for (i = 0; i < k; i++) {
- cout << "Student №" << i + 1 << endl;
- cout << "Имя" << endl;
- cin >> u[i].name;
- cout << "Курс" << endl;
- cin >> u[i].kurs;
- cout << "Оценка" << endl;
- cin >> u[i].mark;
- }
- }
- void update() {
- int i = 0;
- infile.open("file1.bin");
- while (!infile.eof()) {
- infile >> u[i].name;
- infile >> u[i].kurs;
- infile >> u[i].mark;
- i++;
- }
- this->l = i;
- infile.close();
- }
- void sohr() {
- int i;
- outfile.open("file2.bin", ios::binary | ios::out);
- for (i = 0; i < 6; i++) {
- outfile << u[i].name;
- outfile << u[i].kurs;
- outfile << u[i].mark;
- outfile.write(reinterpret_cast <char*> (&u), sizeof(&u));
- }
- //outfile.write(reinterpret_cast <char*> (&u), sizeof(int));
- outfile.close();
- }
- void vyvod() {
- int i;
- for (i = 0; i < 6; i++) {
- cout << "Student №" << i + 1 << endl;
- cout << "Имя" << endl;
- cout << u[i].name << endl;
- cout << "Курс" << endl;
- cout << u[i].kurs << endl;
- cout << "Оценка" << endl;
- cout << u[i].mark << endl;
- }
- }
- };
- int main()
- {
- setlocale(LC_ALL, "rus");
- int i, k, num = 0;
- studenty b;
- b.vvod();
- b.sohr();
- cout << "Enter kurs" << endl;
- cin >> k;
- b.update();
- b.sohr();
- for (i = 0; i < b.l; i++) {
- if (b.u[i].kurs == k && b.u[i].mark < 4) num++;
- }
- cout << endl << "Количество неуспевающих студентов на k курсе:" << num+4 << endl;
- b.vyvod();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement