Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Lab_10_var8
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include <windows.h>
- #include <fstream>
- #include <string>
- using namespace std;
- struct Buyer
- {
- string name, surname, address;
- string phone, card;
- };
- Buyer x[100];
- int countRow = 0;
- void outputScreen()
- {
- cout << " Structure Buyer" << endl;
- cout << " __________________________________________________________________________" << endl;
- cout << " |№ | Name | Surname | Address | Phone | Card | " << endl;
- cout << " |--|------------|------------|------------|-------------|----------------|" << endl;
- for (int i = 0; i < countRow; i++)
- {
- cout << left << " |" << setw(2) << i + 1 << "|" << setw(12) << x[i].name << "|" << setw(12)
- << x[i].surname << "|" << setw(12) << x[i].address << "|" << setw(13) << x[i].phone
- << "|" << setw(16) << x[i].card << "|" << 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 >> x[countRow].name >> x[countRow].surname >> x[countRow].address >> x[countRow].phone >> x[countRow].card;
- 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) << x[i].surname << " " << setw(10) << x[i].name << " " << setw(10) << x[i].address << " " << setw(11) << x[i].phone << " " << setw(11) << x[i].card;
- if (i != countRow - 1)
- output << endl;
- if (output.fail())
- break;
- }
- output.close();
- cout << "File created" << endl;
- }
- void addBuyer()
- {
- int countAddRow;
- string tmpNumber;
- cout << "How many lines to add: ";
- cin >> countAddRow;
- cout << "Enter card number: ";
- cin >> tmpNumber;
- for (int j = 0; j<countAddRow; j++)
- {
- cout << "-Enter Vehicle Owner Data-" << endl;
- cout << "Surname: ";
- cin >> x[countRow].surname;
- cout << "Name: ";
- cin >> x[countRow].name;
- cout << "Address: ";
- cin >> x[countRow].address;
- cout << "Phone: ";
- cin >> x[countRow].phone;
- x[countRow].card = tmpNumber;
- countRow++;
- }
- cout << countAddRow << " Byer with number " << tmpNumber << " added" << endl;
- outputScreen();
- }
- void deleteBuyer()
- {
- int colvo;
- cout << "Enter the number of items to remove from the beginning of the list: ";
- cin >> colvo;
- int ptr = 0;
- for (int i = colvo; i < countRow; i++)
- {
- x[ptr] = x[i];
- ptr++;
- }
- countRow -= colvo;
- cout << colvo << " items deleted" << endl;
- outputScreen();
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- setlocale(LC_ALL, 0);
- int option;
- cout << "Structure Buyer" << endl;
- while (1)
- {
- cout << "1-Input from a text file" << endl;
- cout << "2-View data" << endl;
- cout << "3-Saving to text file" << endl;
- cout << "4-Adding N elements with the number K" << endl;
- cout << "5-Deleting an item with a specified 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: addBuyer(); break;
- case 5: deleteBuyer(); break;
- case 6: exit(0);
- default: cout << "Invalid value entered" << endl;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement