Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <string>
- #include <windows.h>
- #include <conio.h>
- using namespace std;
- struct CIVILIAN {
- char surname[13];
- char district[15];
- char social[15];
- double value;
- };
- short menu();
- void input(CIVILIAN* x, int &pc, int &max);
- void inputInFile(CIVILIAN* x, int &pc, int &max);
- void list();
- void list2(int &pc, int &max);
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- setlocale(LC_ALL, "Rus");
- int max = 0, pc = 0;
- short choice;
- CIVILIAN *group = new CIVILIAN;
- do {
- choice = menu();
- switch (choice) {
- case 1:
- system("cls");
- inputInFile(group, pc, max);
- _getch();
- system("cls");
- break;
- case 2:
- system("cls");
- list();
- _getch();
- system("cls");
- break;
- case 3:
- system("cls");
- list2(pc, max);
- _getch();
- system("cls");
- break;
- case 0:
- cout << "Goodbye!" << endl;
- system("pause");
- break;
- default:
- cout << "Error!" << endl;
- cout << "\n\nPress Enter..." << endl;
- _getch();
- system("cls");
- break;
- }
- } while (choice);
- delete group;
- system("pause");
- return 0;
- }
- short menu() {
- short m;
- cout << " МЕНЮ \n";
- cout << " Введите [1] чтобы добавить вкладчика \n";
- cout << " Введите [2] для просмотра введенных данных о вкладчиках \n";
- cout << " Введите [3] для просмотра введенных данных о служащих вкладчиках \n";
- cout << " Введите [0] для выхода \n";
- cout << " Пункт: ";
- cin >> m;
- return m;
- }
- void inputInFile(CIVILIAN* x, int &pc, int &max) {
- input(x, pc, max);
- FILE* pFile;
- fopen_s(&pFile, "datebase.dat", "a+");
- system("pause");
- cout << "\n\nФамилия вкладчика: " << x->surname << endl;
- cout << "Район: " << x->district << endl;
- cout << "Социальное положение: " << x->social << endl;
- cout << "Величина вклада: " << x->value << endl;
- fwrite(x, sizeof(CIVILIAN), 1, pFile);
- cout << "Ваши данные теперь находятся в файле.";
- fclose(pFile);
- }
- void input(CIVILIAN* x, int &pc, int &max) {
- cin.ignore();
- cout << "Фамилия вкладчика: ";
- cin.getline(x->surname, 13);
- cout << "Район: ";
- cin.getline(x->district, 15);
- cout << "Социальное положение: ";
- cin.getline(x->social, 15);
- cout << "Величина вклада: ";
- cin >> x->value;
- if (strcmp(x->social, "Служащий") == 0) {
- pc++;
- max += x->value;
- }
- }
- void list() {
- CIVILIAN* group = new CIVILIAN;
- FILE* pFile;
- int i = 1;
- fopen_s(&pFile, "datebase.dat", "r+");
- cout << "ТАБЛИЦА О ВКЛАДЧИКАХ:\n";
- while (!feof(pFile)) {
- fread(group, sizeof(CIVILIAN), 1, pFile);
- if (!feof(pFile)) {
- cout << i++ << ": " << endl;
- cout << "\tФамилия: " << group->surname << endl;
- cout << "\tРайон: " << group->district << endl;
- cout << "\tСоц.положение: " << group->social << endl;
- cout << "\tВеличина вклада: " << group->value << endl;
- }
- }
- system("pause");
- delete group;
- fclose(pFile);
- }
- void list2(int &pc, int &max) {
- CIVILIAN* group = new CIVILIAN;
- FILE* pFile;
- int i = 1;
- fopen_s(&pFile, "datebase.dat", "r+");
- cout << "ТАБЛИЦА О CЛУЖАЩИХ ВКЛАДЧИКАХ:\n";
- while (fread(group, sizeof(CIVILIAN), 1, pFile) == 1) {
- if (strcmp(group->social, "Служащий") == 0) {
- cout << i++ << ": " << endl;
- cout << "\tФамилия: " << group->surname << endl;
- cout << "\tРайон: " << group->district << endl;
- cout << "\tСоц.положение: " << group->social << endl;
- cout << "\tВеличина вклада: " << group->value << endl;
- }
- }
- cout << "Количество служащих: " << pc << endl;
- cout << "Суммарный вклад служащих: " << max << endl;
- delete group;
- fclose(pFile);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement