Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Lab_3.cpp
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <windows.h>
- #include "MyTRow.h"
- #include "MyTTable.h"
- using namespace std;
- /*16. Метод поиска таблицы с наибольшим количеством строк;
- метод выводящий сведения о строках, по всем таблицам;
- метод перемещающий строку из одной таблицы в другую.*/
- //Класс-обработчик
- class TProcessor
- {
- public:
- TProcessor(TTable* T, int n)
- {
- cout << "Constructor class TProcessor" << endl;
- TPointer = T;
- numOfTables = n;
- }
- TTable* TPointer;
- int numOfTables = 0;
- void maxRow();
- void moveRow(int table1, int row1, int table2, int row2);
- void printRowOfAllTables(int select);
- ~TProcessor()
- {
- cout << "Destructor class TProcessor" << endl;
- }
- };
- void TProcessor::maxRow()
- {
- int count = 0, index = 0;
- for (int i = 0; i < numOfTables; i++)
- {
- if (count <= TPointer[i].getMax())
- {
- count = TPointer[i].getMax();
- index = i;
- }
- }
- cout << "Max row in Table[" << index + 1 << "]. This table:" << endl;
- TPointer[index].print();
- }
- void TProcessor::moveRow(int table1, int row1, int table2, int row2)
- {
- table1--;
- table2--;
- row1--;
- row2--;
- string name1 = "", surname1 = "";
- int year1 = 0;
- string name2 = "", surname2 = "";
- int year2 = 0;
- name1 = TPointer[table1].Rpointer[row1].getName();
- surname1 = TPointer[table1].Rpointer[row1].getSurname();
- year1 = TPointer[table1].Rpointer[row1].getYear();
- name2 = TPointer[table2].Rpointer[row2].getName();
- surname2 = TPointer[table2].Rpointer[row2].getSurname();
- year2 = TPointer[table2].Rpointer[row2].getYear();
- cout << "Move: '";
- cout << name1 << " " << surname1 << " " << year1 << "'";
- cout << " to Table[" << table2+1 << "] in row[" << row2+1 << "]" << endl;
- TPointer[table2].Rpointer[row2].setName(name1);
- TPointer[table2].Rpointer[row2].setSurname(surname1);
- TPointer[table2].Rpointer[row2].setYear(year1);
- TPointer[table1].Rpointer[row1].setName(name2);
- TPointer[table1].Rpointer[row1].setSurname(surname2);
- TPointer[table1].Rpointer[row1].setYear(year2);
- cout << "Moving successfully" << endl;
- TPointer[table1].print();
- TPointer[table2].print();
- }
- void TProcessor::printRowOfAllTables(int select)
- {
- select--;
- for (int i = 0; i < numOfTables; i++)
- {
- if (TPointer[i].getMax() > select)
- {
- cout << "Table[" << (i + 1) << "]" << endl;
- cout << "Name\t" << "Surname\t" << "Birthday" << endl;
- cout << TPointer[i].Rpointer[select].getName() << "\t" << TPointer[i].Rpointer[select].getSurname() << "\t" << TPointer[i].Rpointer[select].getYear() << endl;
- }
- else
- {
- cout << "Table[" << (i + 1) << "]" << endl;
- cout << "No " << select + 1 << " rows" << endl;
- }
- }
- }
- int main()
- {
- int numOfTables = 0;
- cout << "Enter the number of tables : ";
- cin >> numOfTables;
- TTable *table = new TTable[numOfTables];
- for (int i = 0; i < numOfTables; i++)
- {
- int max = 0;
- string name = "", surname = "";
- int year = 0;
- cout << "[" << i+1 << "] Enter the number of rows: ";
- cin >> max;
- TRow *row = new TRow[max];
- table[i].pointer_max(row,max);
- for (int j = 0; j < max; j++)
- {
- table[i].addRow();
- }
- cout << "Print table[" << i+1 << "]" << endl;
- table[i].print();
- }
- TProcessor processor(table, numOfTables);
- while (1)
- {
- int option = 0;
- cout << "1.Finding the table with the largest number of rows." << endl;
- cout << "2.Output of information about lines, for all tables." << endl;
- cout << "3.Moving rows from one table to another." << endl;
- cout << "4.Exit" << endl;
- cin >> option;
- switch (option)
- {
- case 1:
- {
- processor.maxRow();
- break;
- }
- case 2:
- {
- int select = 0;
- cout << "Which row to print: ";
- cin >> select;
- processor.printRowOfAllTables(select);
- break;
- }
- case 3:
- {
- int table1 = 0, table2 = 0, row1 = 0, row2 = 0;
- cout << "From which table (1-" << numOfTables << "):";
- cin >> table1;
- cout << "Which row with [" << table1 << "] tables (1-" << table[table1-1].getMax() << "):";
- cin >> row1;
- cout << "Which table (1-" << numOfTables << "):";
- cin >> table2;
- cout << "In which row [" << table2 << "] of the table (1-" << table[table2 - 1].getMax() << "):";
- cin >> row2;
- processor.moveRow(table1, row1, table2, row2);
- break;
- }
- case 4:
- {
- exit(0);
- break;
- }
- default:
- cout << "Enter a number from 1 to 4" << endl;
- }
- }
- return 0;
- }
- //MyTRow.h
- #pragma once
- #include <string>
- using namespace std;
- //Класс-строка
- class TRow
- {
- private:
- string Name;
- string Surname;
- int Year;
- public:
- TRow();
- int getYear();
- string getName();
- string getSurname();
- void setYear(int year);
- void setName(string name);
- void setSurname(string surname);
- ~TRow();
- };
- //MyTRow.cpp
- #include "stdafx.h"
- #include "MyTRow.h"
- #include <iostream>
- TRow::TRow()
- {
- cout << "Constructor class TRow" << endl;
- }
- int TRow::getYear()
- {
- return Year;
- }
- string TRow::getName()
- {
- return Name;
- }
- string TRow::getSurname()
- {
- return Surname;
- }
- void TRow::setYear(int year)
- {
- Year = year;
- }
- void TRow::setName(string name)
- {
- Name = name;
- }
- void TRow::setSurname(string surname)
- {
- Surname = surname;
- }
- TRow::~TRow()
- {
- cout << "Destructor class TRow" << endl;
- }
- //MyTTable.h
- #pragma once
- #include "MyTRow.h"
- //Класс-таблица
- class TTable
- {
- public:
- TTable();
- int Max;
- int CurrentPos = 0;
- TRow *Rpointer;
- int getMax();
- void pointer_max(TRow *R, int max);
- void addRow();
- void print();
- ~TTable();
- };
- //MyTTable.cpp
- #include "stdafx.h"
- #include "MyTTable.h"
- #include <iostream>
- TTable::TTable()
- {
- cout << "Constructor class TTable" << endl;
- }
- int TTable::getMax()
- {
- return Max;
- }
- void TTable::pointer_max(TRow *R, int max)
- {
- Max = max;
- Rpointer = R;
- }
- void TTable::addRow()
- {
- string name, surname;
- int year;
- cout << "Enter name: ";
- cin >> name;
- Rpointer[CurrentPos].setName(name);
- cout << "Enter surname: ";
- cin >> surname;
- Rpointer[CurrentPos].setSurname(surname);
- cout << "Enter birthday: ";
- cin >> year;
- Rpointer[CurrentPos].setYear(year);
- CurrentPos++;
- }
- void TTable::print()
- {
- cout << "Name\t" << "Surname\t" << "Birthday" << endl;
- for (int i = 0; i < CurrentPos; i++)
- {
- cout << Rpointer[i].getName() << "\t" << Rpointer[i].getSurname() << "\t" << Rpointer[i].getYear() << endl;
- }
- int i = Rpointer[0].getYear();
- }
- TTable::~TTable()
- {
- cout << "Destructor class TTable" << endl;
- }
Add Comment
Please, Sign In to add comment