Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Lab_9_Task2
- #include "stdafx.h"
- #include <string>
- #include <iostream>
- #include <locale>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- //3. Классы табель выходов и сотрудник.
- //Класс обработчик реализует заполнение табеля выходов и расчет заработной платы сотрудник на основании информации о отработанном времени.
- //Класс-сотрудник
- class TSotrudnik
- {
- private:
- string Name;
- string Surname;
- int Id;
- int Time;
- public:
- TSotrudnik();
- int getId()
- {
- return Id;
- }
- string getName()
- {
- return Name;
- }
- string getSurname()
- {
- return Surname;
- }
- int getTime()
- {
- return Time;
- }
- void setId(int id)
- {
- Id = id;
- }
- void setName(string name)
- {
- Name = name;
- }
- void setSurname(string surname)
- {
- Surname = surname;
- }
- void setTime(int time)
- {
- Time = time;
- }
- ~TSotrudnik();
- };
- TSotrudnik::TSotrudnik()
- {
- cout << "Constructor class TSotrudnik" << endl;
- }
- TSotrudnik::~TSotrudnik()
- {
- cout << "Destructor class TSotrudnik" << endl;
- }
- //Класс-табель
- class TTabel
- {
- public:
- TTabel();
- TTabel(TSotrudnik*, int);
- int Max;
- int CurrentPos = 0;
- TSotrudnik *SotrudnikPointer;
- void setMax(int newMax)
- {
- Max = newMax;
- }
- int getMax()
- {
- return Max;
- }
- void addSotrudnik();
- ~TTabel();
- };
- TTabel::TTabel()
- {
- cout << "Constructor class TTabel" << endl;
- }
- TTabel::TTabel(TSotrudnik *S, int max)
- {
- setMax(max);
- SotrudnikPointer = S;
- }
- TTabel::~TTabel()
- {
- cout << "Destructor class TTabel" << endl;
- }
- void TTabel::addSotrudnik()
- {
- string name, surname;
- int id, time;
- cout << "Enter ID: ";
- cin >> id;
- SotrudnikPointer[CurrentPos].setId(id);
- cout << "Enter name: ";
- cin >> name;
- SotrudnikPointer[CurrentPos].setName(name);
- cout << "Enter surname: ";
- cin >> surname;
- SotrudnikPointer[CurrentPos].setSurname(surname);
- cout << "Enter time work: ";
- cin >> time;
- SotrudnikPointer[CurrentPos].setTime(time);
- CurrentPos++;
- }
- class TableOutput
- {//табличный вывод информации в файл и на экран
- public:
- virtual void Print(TTabel *T) = 0;
- };
- class StringOutput
- {//вывод информации в ленточной форме в файл и на экран
- public:
- virtual void Print(TTabel *T) = 0;
- };
- class TableOutput_helper : public TableOutput {
- public:
- virtual void TableOutput_Print(TTabel *T) = 0;
- void Print(TTabel *T)
- {
- TableOutput_Print(T);
- }
- };
- class StringOutput_helper : public StringOutput {
- public:
- virtual void StringOutput_Print(TTabel *T) = 0;
- void Print(TTabel *T)
- {
- StringOutput_Print(T);
- }
- };
- class TProcessor : public TableOutput_helper, public StringOutput_helper
- {
- public:
- TProcessor();
- TProcessor(TTabel *T);
- TTabel *Tpointer;
- void calculateEarnings(int rate);
- void TableOutput_Print(TTabel *T)
- {
- string out = "";
- cout << "Table Output" << endl;
- out += "Table Output\n";
- cout << "ID\t" << "Name\t" << "Surname\t" << "\tTime" << endl;
- out += "ID\tName\tSurname\t\tTime\n";
- for (int i = 0; i < T[0].CurrentPos; i++)
- {
- out += to_string(T[0].SotrudnikPointer[i].getId()) + "\t" + T[0].SotrudnikPointer[i].getName() + "\t";
- out += T[0].SotrudnikPointer[i].getSurname() + "\t" + to_string(T[0].SotrudnikPointer[i].getTime()) + "\n";
- cout << T[0].SotrudnikPointer[i].getId() << "\t" << T[0].SotrudnikPointer[i].getName() << "\t" << T[0].SotrudnikPointer[i].getSurname() << "\t" << T[0].SotrudnikPointer[i].getTime() << endl;
- }
- ofstream fout;
- fout.open("Table.txt");
- fout << out;
- fout.close();
- }
- void StringOutput_Print(TTabel *T)
- {
- string out = "";
- out += "String Output\n";
- cout << "String Output" << endl;
- cout << "ID: ";
- out += "ID: ";
- for (int i = 0; i < T[0].CurrentPos; i++)
- {
- out += to_string(T[0].SotrudnikPointer[i].getId()) + "; ";
- cout << T[0].SotrudnikPointer[i].getId() << "; ";
- }
- cout << endl;
- cout << "Name: ";
- out += "\nName: ";
- for (int i = 0; i < T[0].CurrentPos; i++)
- {
- out += T[0].SotrudnikPointer[i].getName() + "; ";
- cout << T[0].SotrudnikPointer[i].getName() << "; ";
- }
- cout << endl;
- cout << "Surname: ";
- out += "\nSurname: ";
- for (int i = 0; i < T[0].CurrentPos; i++)
- {
- out += T[0].SotrudnikPointer[i].getSurname() + "; ";
- cout << T[0].SotrudnikPointer[i].getSurname() << "; ";
- }
- cout << endl;
- cout << "Time: ";
- out += "\nTime: ";
- for (int i = 0; i < T[0].CurrentPos; i++)
- {
- out += to_string(T[0].SotrudnikPointer[i].getTime()) + "; ";
- cout << T[0].SotrudnikPointer[i].getTime() << "; ";
- }
- cout << endl;
- out += "\n";
- ofstream fout;
- fout.open("String.txt");
- fout << out;
- fout.close();
- }
- ~TProcessor();
- };
- void TProcessor::calculateEarnings(int rate)
- {
- cout << " __________________________________________________________________" << endl;
- cout << " | ID | Name | Surname | Time | Earnings | " << endl;
- cout << " |------------|------------|------------|------------|------------|" << endl;
- for (int i = 0; i < Tpointer[0].getMax(); i++)
- cout << left << " |" << setw(12) << Tpointer[0].SotrudnikPointer[i].getId() << "|" << setw(12) << Tpointer[0].SotrudnikPointer[i].getName() << "|" << setw(12)
- << Tpointer[0].SotrudnikPointer[i].getSurname() << "|" << setw(12) << Tpointer[0].SotrudnikPointer[i].getTime() << "|" << setw(12) << Tpointer[0].SotrudnikPointer[i].getTime()*rate << "|" << endl;
- cout << " __________________________________________________________________" << endl;
- }
- TProcessor::TProcessor()
- {
- cout << "Constructor class TProcessor" << endl;
- };
- TProcessor::TProcessor(TTabel *T)
- {
- Tpointer = T;
- }
- TProcessor::~TProcessor()
- {
- cout << "Destructor class TProcessor" << endl;
- };
- int main()
- {
- int max = 0, rate = 5;
- string name = "", surname = "";
- int Id = 0;
- cout << "Enter the number of employees: ";
- cin >> max;
- TSotrudnik *employees;
- employees = new TSotrudnik[max];
- TTabel table(employees, max);
- for (int i = 0; i < max; i++)
- {
- table.addSotrudnik();
- }
- TProcessor processor(&table);
- StringOutput* SO = &processor;
- TableOutput* TO = &processor;
- SO->Print(&table);
- TO->Print(&table);
- processor.calculateEarnings(rate);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment