Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include <windows.h>
- #include <fstream>
- #include <string>
- using namespace std;
- struct Patient
- {
- string name, surname, middlename;
- string address;
- int medicalCard, insurancePolicy;
- };
- Patient patient[100];
- int countRow = 0;
- void outputScreen()
- {
- cout << " Structure Patient" << endl;
- cout << " ___________________________________________________________________________________________" << endl;
- cout << " |№ | Name | Surname | Middle | Address | Medical Card |Insurance Policy| " << endl;
- cout << " |--|------------|------------|------------|-------------|----------------|----------------|" << endl;
- for (int i = 0; i < countRow; i++)
- cout << left << " |" << setw(2) << i + 1 << "|" << setw(12) << patient[i].name << "|" << setw(12)
- << patient[i].surname << "|" << setw(12) << patient[i].middlename << "|" << setw(13) << patient[i].address
- << "|" << setw(16) << to_string(patient[i].medicalCard) << "|" << to_string(patient[i].insurancePolicy) << "|" << endl;
- cout << " ___________________________________________________________________________________________" << endl;
- }
- void inputFile()
- {
- ifstream input;
- input.open("Input.txt", ios::in);
- if (input.fail()) {
- cout << "Could not open file" << endl;
- system("pause");
- }
- do
- {
- input >> patient[countRow].name >> patient[countRow].surname >> patient[countRow].middlename >> patient[countRow].address >> patient[countRow].medicalCard >> patient[countRow].insurancePolicy;
- countRow++;
- } while (!input.eof());
- input.close();
- cout << "\nFile read out. Number of items = " << countRow << endl;
- outputScreen();
- }
- void outputFile()
- {
- ofstream output;
- output.open("Output.txt", ios::out);
- if (output.fail())
- {
- cout << "Could not create file" << endl;
- system("pause");
- }
- for (int i = 0; i<countRow; i++)
- {
- output << setw(10) << patient[i].surname << " " << setw(10) << patient[i].name << " " << setw(10) << patient[i].middlename << " " << setw(11) << patient[i].address << " " << setw(11) << patient[i].medicalCard;
- if (i != countRow - 1)
- output << endl;
- if (output.fail())
- break;
- }
- output.close();
- cout << "File created" << endl;
- }
- void addPatient()
- {
- int countAddRow;
- cout << "How many lines to add: ";
- cin >> countAddRow;
- for (int i = countRow + countAddRow; i <= countAddRow - 1; i--)
- patient[i + 1] = patient[i];
- Patient tmp[100];
- for (int i = 0; i < countRow; i++)
- {
- tmp[i+countAddRow] = patient[i];
- }
- for (int i = 0; i<countAddRow; i++)
- {
- cout << "-Enter Patient Data [" << i+1 << "]-" << endl;
- cout << "Name: ";
- cin >> tmp[i].name;
- cout << "Surname: ";
- cin >> tmp[i].surname;
- cout << "Middle Name: ";
- cin >> tmp[i].middlename;
- cout << "Address: ";
- getline(cin, tmp[i].address);
- cout << "Medical Card: ";
- cin >> tmp[i].medicalCard;
- cout << "Insurance Policy: ";
- cin >> tmp[i].insurancePolicy;
- countRow++;
- }
- for (int i = 0; i < countRow; i++)
- {
- cout << "Save" << tmp[i].name << endl;
- patient[i] = tmp[i];
- }
- outputScreen();
- cout << countAddRow << " items added to the beginning of the file" << endl;
- cout << "Changes are written to the Output.txt file" << endl;
- outputFile();
- }
- void deletePatient()
- {
- int value;
- cout << "Enter the medical card number: ";
- cin >> value;
- for (int i = 0; i < countRow; i++)
- {
- if (value == patient[i].medicalCard)
- {
- for (int j = i; j <= countRow; j++)
- patient[j] = patient[j+1];
- cout << "Patient deleted" << endl;
- countRow--;
- }
- else if (i == countRow - 1)
- cout << "There is no such medical card number" << endl;
- }
- outputScreen();
- cout << "Changes are written to the Output.txt file" << endl;
- outputFile();
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- int option;
- cout << "Structure Patient" << endl;
- while (1)
- {
- cout << "1-Input from a txt file (Input.txt)" << endl;
- cout << "2-View data" << endl;
- cout << "3-Saving to txt file (Output.txt)" << endl;
- cout << "4-Add K elements to the beginning of the file" << endl;
- cout << "5-Delete an item with the specified medical card number." << endl;
- cout << "6-Exit" << endl;
- cout << "Your choice (1-6): ";
- cin >> option;
- switch (option)
- {
- case 1: inputFile(); break;
- case 2: outputScreen(); break;
- case 3: outputFile(); break;
- case 4: addPatient(); break;
- case 5: deletePatient(); break;
- case 6: exit(0);
- default: cout << "Invalid value entered" << endl;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment