Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <iomanip>
- #include <cstring>
- #include "stdlib.h"
- using namespace std;
- struct STUDENT
- {
- string FIO;
- int age;
- char gender;
- int kurs;
- double average;
- };
- void create_file()
- {
- int numberofenter;
- ifstream fin("base.txt");
- ofstream fout("base.txt");
- string tmp;
- cout << "Введите число записей, которое вы хотите сделать: "; cin >> numberofenter;
- for (int i = 0; i < numberofenter; i++)
- {
- cout << "-------------------------------------------------------------------------------" << endl;
- cout << "Введите ФИО студента: ";
- getline(cin, tmp);
- fout << tmp << " ";
- cout << tmp << endl;
- cout << "Введите возраст студента: "; cin >> tmp; fout << tmp << " ";
- cout << "Введите пол (м / ж): "; cin >> tmp; fout << tmp << " ";
- cout << "Введите курс: "; cin >> tmp; fout << tmp << " ";
- cout << "Введите средний бал: "; cin >> tmp; fout << tmp << endl;
- getline(fin, tmp);
- cout << tmp << endl;
- }
- cout << "-------------------------------------------------------------------------------" << endl;
- }
- void output_file()
- {
- string tmp;
- STUDENT student;
- ifstream fin("base.txt");
- int tmpnum = 0;
- while (fin.good())
- {
- getline(fin, tmp);
- int i = 0;
- while (tmp[i] < 48 && tmp[i] > 57)
- {
- student.FIO[i] = tmp[i];
- i++;
- }
- while (tmp[i] != ' ')
- {
- tmpnum = tmpnum * 10 + (tmp[i] - 48);
- i++;
- }
- student.age = tmpnum;
- tmpnum = 0;
- i++;
- student.gender = tmp[i];
- i++;
- student.kurs = tmp[i];
- while (i < tmp.length())
- {
- if (tmp[i] != '.')
- {
- tmpnum = tmpnum * 10 + (tmp[i] - 48);
- i++;
- }
- else
- {
- tmpnum = tmpnum + ((tmp[i] - 48)*0.1);
- i++;
- }
- }
- cout << "| " << setw(38) << left << student.FIO << "| " << setw(2) << left << student.age << " | " << setw(1) << left << student.age << "| " << setw(1) << left << student.kurs << " | " << setw(4) << left << student.average << " |" << endl;
- }
- }
- void menu_output()
- {
- cout << "-------------------------------------------------------------------------------" << endl;
- cout << "Введите 1 для создания файла" << endl;
- cout << "Введите 2 для просмотра содержимого файла в виде таблицы" << endl;
- cout << "Введите 3 для добавления записи в файл" << endl;
- cout << "Введите 4 для удаления записи из файла" << endl;
- cout << "Введите 5 для изменения записи в файле" << endl;
- cout << "Введите 6 для определения студентов с фамилией на заданую букву" << endl;
- cout << "Введите 9 для вывода этого меню" << endl;
- cout << "Введите 0 для выхода из программы" << endl;
- cout << "-------------------------------------------------------------------------------" << endl;
- }
- void main()
- {
- setlocale(LC_ALL, "Russian");
- int c;
- menu_output();
- do
- {
- cout << "Введите команду: "; cin >> c;
- cout << "-------------------------------------------------------------------------------" << endl;
- switch (c)
- {
- case 1:
- {
- create_file();
- } break;
- case 2:
- {
- cout << "-------------------------------------------------------------------------------" << endl;
- cout << "| ФИО | возраст | пол | курс | успеваемость |" << endl;
- output_file();
- cout << "-------------------------------------------------------------------------------" << endl;
- } break;
- case 9:
- {
- menu_output();
- } break;
- }
- } while (c != 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement