Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Lab_10.cpp
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include <windows.h>
- #include <fstream>
- #include <string>
- using namespace std;
- struct ownerСar
- {
- string name, surname, carNumber;
- string phone, technicalNumber;
- };
- ownerСar x[100];
- int countRow = 0;
- void outputScreen()
- {
- cout << " Structure Car owner" << endl;
- cout << " __________________________________________________________________________" << endl;
- cout << " |№ | Name | Surname | Сar number | Phone |Technical number| " << 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].carNumber << "|" << setw(13) << x[i].phone
- << "|" << setw(16) << x[i].technicalNumber << "|" << 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].carNumber >> x[countRow].phone >> x[countRow].technicalNumber;
- 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].carNumber << " " << setw(11) << x[i].phone << " " << setw(11) << x[i].technicalNumber;
- if (i != countRow - 1)
- output << endl;
- if (output.fail())
- break;
- }
- output.close();
- cout << "File created" << endl;
- }
- void addOwner()
- {
- int countAddRow;
- string tmpNumber;
- cout << "How many lines to add: ";
- cin >> countAddRow;
- cout << "Enter vehicle 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;
- x[countRow].carNumber = tmpNumber;
- cout << "Phone: ";
- cin >> x[countRow].phone;
- cout << "Technical document number: ";
- cin >> x[countRow].technicalNumber;
- countRow++;
- }
- cout << countAddRow << " owners with number " << tmpNumber << " added" << endl;
- outputScreen();
- }
- void deleteOwner()
- {
- string tmpNumber;
- ownerСar tempStruct;
- cout << "Enter the number of the car: ";
- cin >> tmpNumber;
- for (int i = 0; i < countRow; i++)
- {
- if (tmpNumber == x[i].carNumber)
- {
- cout << tmpNumber << "==" << x[i].carNumber << endl;
- for (int j = i; j < countRow - 1; j++)
- {
- x[i] = x[i + 1];
- }
- countRow--;
- cout << "Owner deleted" << endl;
- }
- else if (i == countRow - 1)
- cout << "There is no such number" << endl;
- }
- outputScreen();
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- int option;
- cout << "Structure Car owner" << 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: addOwner(); break;
- case 5: deleteOwner(); break;
- case 6: exit(0);
- default: cout << "Invalid value entered" << endl;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement