Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <string>
- #include <iostream>
- #include <locale>
- using namespace std;
- //6. Классы маршрут и остановка.
- //Класс обработчик реализует сравнение маршрутов на идентичность,
- //расчет времени прохождения всего маршрута.
- //Класс-остановка
- class TStation
- {
- private:
- string Name;
- int Time;
- public:
- TStation();
- int getTime()
- {
- return Time;
- }
- string getName()
- {
- return Name;
- }
- void setTime(int time)
- {
- Time = time;
- }
- void setName(string name)
- {
- Name = name;
- }
- ~TStation();
- };
- TStation::TStation()
- {
- cout << "Constructor class TStation" << endl;
- }
- TStation::~TStation()
- {
- cout << "Destructor class TStation" << endl;
- }
- //Класс-маршрут
- class TRoute
- {
- public:
- TRoute();
- int Max;
- int CurrentPos = 0;
- TStation *Spointer;
- void setMaxAndPointer(TStation *S, int max)
- {
- Max = max;
- Spointer = S;
- }
- int getMax()
- {
- return Max;
- }
- void addStation();
- void print();
- ~TRoute();
- };
- TRoute::TRoute()
- {
- cout << "Constructor class TRoute" << endl;
- }
- TRoute::~TRoute()
- {
- cout << "Destructor class TRoute" << endl;
- }
- void TRoute::addStation()
- {
- string name;
- int time;
- cout << "Enter name: ";
- cin >> name;
- Spointer[CurrentPos].setName(name);
- cout << "Enter time: ";
- cin >> time;
- Spointer[CurrentPos].setTime(time);
- CurrentPos++;
- }
- void TRoute::print()
- {
- cout << "Name\t" << "Time\t" << endl;
- for (int i = 0; i < CurrentPos; i++)
- {
- cout << Spointer[i].getName() << "\t" << Spointer[i].getTime() << endl;
- }
- }
- //Класс-обработчик
- class TProcessor
- {
- public:
- TProcessor();
- TProcessor(TRoute *R);
- TRoute *Rpointer;
- int CalculateTime(int routeNumber);
- void IdentityCheck(int routeNumber1, int routeNumber2);
- ~TProcessor();
- };
- int TProcessor::CalculateTime(int routeNumber)
- {
- int summ = 0;
- cout << "Travel time for route " << routeNumber << ": ";
- routeNumber -= 1;
- for (int i = 0; i < Rpointer[routeNumber].getMax(); i++)
- {
- summ += Rpointer[routeNumber].Spointer[i].getTime();
- if(i<Rpointer[routeNumber].getMax()-1)
- cout << Rpointer[routeNumber].Spointer[i].getTime() << " + ";
- else
- cout << Rpointer[routeNumber].Spointer[i].getTime() << " = ";
- }
- cout << summ << endl;
- return summ;
- }
- void TProcessor::IdentityCheck(int routeNumber1, int routeNumber2)
- {
- int one = CalculateTime(routeNumber1);
- int two = CalculateTime(routeNumber2);
- cout << "Time for the first route: " << one << endl;
- cout << "Time for the second route: " << two << endl;
- if (one == two)
- {
- cout << "Time for the first and second routes are the same: " << one << " min" << endl;
- }
- else if (one > two)
- {
- cout << "The time for the second route is less for: " << one-two << " min" << endl;
- }
- else if (one < two)
- {
- cout << "The time for the first route is less for: " << two - one << " min" << endl;
- }
- }
- TProcessor::TProcessor()
- {
- cout << "Constructor class TProcessor" << endl;
- };
- TProcessor::TProcessor(TRoute *R)
- {
- Rpointer = R;
- }
- TProcessor::~TProcessor()
- {
- cout << "Destructor class TProcessor" << endl;
- };
- int main()
- {
- int countRoute = 0, countStation = 0, sortRow = 0;
- string name = "";
- int year = 0;
- cout << "Enter the number of route: ";
- cin >> countRoute;
- TRoute *route = new TRoute[countRoute];
- //TRoute route(station, countStation);
- for (int i = 0; i < countRoute; i++)
- {
- cout << "Enter the number of station: ";
- cin >> countStation;
- TStation *station = new TStation[countStation];
- route[i].setMaxAndPointer(station, countStation);
- for (int j = 0; j < countStation; j++)
- {
- route[i].addStation();
- }
- route[i].print();
- }
- TProcessor processor(route);
- while (1)
- {
- int option;
- cout << "1.Calculation of transit time" << endl;
- cout << "2.Comparison of identity" << endl;
- cout << "3.Exit" << endl;
- cin >> option;
- switch (option)
- {
- case 1:
- {
- int routeNumber;
- cout << "For which route is the time calculated: (1-" << countRoute << ")" << endl;
- cin >> routeNumber;
- processor.CalculateTime(routeNumber);
- break;
- }
- case 2:
- {
- int routeNumber1, routeNumber2;
- cout << "Which routes to compare: (1-" << countRoute << ")" << endl;
- cout << "Enter the first route to compare: ";
- cin >> routeNumber1;
- cout << "Enter the second route to compare: ";
- cin >> routeNumber2;
- processor.IdentityCheck(routeNumber1, routeNumber2);
- break;
- }
- case 3:
- {
- exit(0);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement