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 Schoolboy
- {
- string name, surname, Сlass;
- string phone;
- int grades[4];
- };
- Schoolboy x[100];
- int countRow = 0;
- void outputScreen()
- {
- cout << " Structure Schoolboy" << endl;
- cout << " __________________________________________________________________________" << endl;
- cout << " |№ | Name | Surname | Сlass | Phone | M | P | R | L | " << 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].Сlass << "|" << setw(13) << x[i].phone
- << "|" << setw(3) << x[i].grades[0] << "|" << setw(3) << x[i].grades[1] << "|"
- << setw(3) << x[i].grades[2] << "|" << setw(3) << x[i].grades[3] << "|" << 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].Сlass >> x[countRow].phone >> x[countRow].grades[0]
- >> x[countRow].grades[1] >> x[countRow].grades[2] >> x[countRow].grades[3];
- 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].Сlass << " " << setw(11) << x[i].phone << " " << setw(11) << x[i].grades;
- if (i != countRow - 1)
- output << endl;
- if (output.fail())
- break;
- }
- output.close();
- cout << "File created" << endl;
- }
- void addSchoolboy()
- {
- int countAddRow;
- cout << "How many lines to add: ";
- cin >> countAddRow;
- for (int j = 0; j<countAddRow; j++)
- {
- cout << "-Enter Schoolboy Data-" << endl;
- cout << "Surname: ";
- cin >> x[countRow].surname;
- cout << "Name: ";
- cin >> x[countRow].name;
- cout << "Сlass: ";
- cin >> x[countRow].Сlass;
- cout << "Phone: ";
- cin >> x[countRow].phone;
- cout << "Mathematics: ";
- cin >> x[countRow].grades[0];
- cout << "Physics: ";
- cin >> x[countRow].grades[1];
- cout << "Russian language: ";
- cin >> x[countRow].grades[2];
- cout << "Literature: ";
- cin >> x[countRow].grades[3];
- countRow++;
- }
- outputScreen();
- }
- void deleteSchoolboy()
- {
- int ptr = 0;
- for (int i = 0; i < countRow; i++)
- {
- for (int j = 0; j < 4; j++)
- {
- if (x[i].grades[j] == 2)
- {
- for (int ii = i; ii <= countRow; ii++)
- x[ii] = x[ii + 1];
- i--;
- countRow--;
- }
- }
- }
- outputScreen();
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- setlocale(LC_ALL, 0);
- int option;
- cout << "Structure Schoolboy" << 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-Add K elements to the end of the file" << endl;
- cout << "5-Delete all items that have 2 at least one school subject" << 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: addSchoolboy(); break;
- case 5: deleteSchoolboy(); break;
- case 6: exit(0);
- default: cout << "Invalid value entered" << endl;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment