Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <math.h>
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- ///////////////////////////////////////////////////////
- class student
- {
- public:
- string fio;
- int id;
- string group;
- void getData()
- {
- cout << "Enter fio: "; cin >> fio;
- cout << "Enter id: "; cin >> id;
- cout << "Enter group: "; cin >> group;
- }
- void showData()
- {
- cout << "Fio: " << fio;
- cout << "Id: " << id;
- cout << "Group: " << group;
- }
- };
- int main()
- {
- student person;
- fstream file;
- int operation;
- do
- {
- cout << "Select one of the following operation:\n";
- cout << "1 = Add student\n";
- cout << "2 = Change student\n";
- cout << "3 = Delete student\n";
- cout << "4 = Search student\n";
- cout << "0 = Exit\n";
- cin >> operation;
- if (operation == 1)
- {
- file.open("lab_1.txt", ios_base::out | ios_base::app | ios_base::binary);
- cout << "Enter data:\n";
- person.getData();
- file.write(reinterpret_cast<char*>(&person), sizeof(person));
- file << "\r\n";
- file.close();
- }
- else if (operation == 2)
- {
- int search;
- cout << "Enter id of the student for search and change: "; cin >> search;
- file.open("lab_1.txt", ios_base::out | ios_base::in | ios_base::binary);
- file.seekg(0);
- while (!file.eof())
- {
- file.read(reinterpret_cast(&person), sizeof(person));
- cout « "FOUND" « person.id;
- /* file.read(reinterpret_cast<char*>(&person), sizeof(person));
- if (search == person.id)
- {
- cout << "Enter new data:\n";
- person.getData();
- file.write(reinterpret_cast<char*>(&person), sizeof(person));
- }
- */
- }
- file.close();
- }
- /*
- else if (operation == 3)
- {
- int search;
- cout << "Enter id of the student for search and delete: "; cin >> search;
- file.open("lab_1.txt", ios_base::in | ios_base::binary);
- file.seekg(0);
- while (!file.eof())
- {
- cout << file.tellg() << " | ";
- file.read(reinterpret_cast<char*>(&person), sizeof(person));
- if (search == person.id)
- {
- }
- cout << file.tellg() << " | ";
- file.close();
- }
- }
- else if (operation == 4)
- {
- int id_student;
- cout << "Введите номер зачетки студента, по которому будет осуществляться поиск и вывод информации: "; cin >> id_student;
- file.open("1.txt", ios_base::out | ios_base::binary);
- file.seekg(0);
- file.read(reinterpret_cast<char*>(&pers), sizeof(pers));
- while (!file.eof())
- {
- if (id_student == pers.id_zachet)
- {
- }
- file.read(reinterpret_cast<char*>(&pers), sizeof(pers));
- }
- file.close();
- }
- */
- } while (operation != 0);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment