Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include<fstream>
- #include<ostream>
- #include <list>
- using namespace std;
- class Station{
- public:
- char name[30];
- double time;
- double distanceToTheNextStation;
- double speed;
- char Station::nam() const{ for(int i=0;i<30;i++) return name[i];}
- double Station::tim() const{return time;}
- double Station::dis() const{return distanceToTheNextStation;}
- double Station::spe() const{return speed;}
- Station(){
- name[30]=' ';
- time=0;
- speed=0;
- distanceToTheNextStation=0;
- }
- Station(char name0[30],double time0,double distanceToTheNextStation0,double speed0){
- for (int i=0;i<30;i++)
- name[i]=name0[i];
- time=time0;
- speed=speed0;
- distanceToTheNextStation=distanceToTheNextStation0;
- }
- void Get(){
- cout << "Имя: ";
- cin >> name;
- cout << "Время в пути до сдедующей станции : ";
- cin >> time;
- cout << "Расстояние до следующей станции: ";
- cin >> distanceToTheNextStation;
- cout << "Скорость движения на участке до следующей станции: ";
- cin >> speed;
- cout << endl;
- }
- void print (int i) {
- cout << i + 1 << " " << name << '\t';
- cout << time <<'\t';
- cout << distanceToTheNextStation << '\t';
- cout << speed << endl;
- }
- friend ostream & operator << (ostream & out, Station T){
- out << " " << T.nam() << '\t';
- out << T.tim() <<'\t';
- out << T.dis() << '\t';
- out << T.spe() << endl;
- return out;
- }
- };
- class Route{
- public:
- list<Station> listStation;
- Route(){}
- // Вывод содержимого списка
- void Gets(){
- list<Station>::iterator it;
- for (it=listStation.begin();it!=listStation.end();it++)
- cout << (*it);
- }
- void GetStation(Station s){
- listStation.push_back(s);
- }
- void ShowMarshryt(Station* Obj, int n, char p3[30], char p4[30]){
- cout << "№ " << "Имя\t" << "Время в пути\t" << "Расстояние\t" << "Скорость\t" << endl;
- cout << "========================================" << endl;
- int p1 = 0, p2 = 0;
- for (int i = 0; i < n; i++){
- if (strstr(Obj[i].name, p3))
- p1 = i;
- if (strstr(Obj[i].name, p4))
- p2 = i;
- }
- for (int i = p1; i < p2+1; i++)
- Obj[i].print (i);
- }
- void VremyaRoute(Station* Obj, int n){
- double min = 0;
- double metr=0;
- for(int i=0;i<n;i++)
- min += Obj[i].time;
- cout << "\n"<<"Общее время в пути(от начальной станции до конечной): " << min;
- for(int i=0;i<n;i++)
- metr+=Obj[i].distanceToTheNextStation;
- cout <<"\n"<< "Длина всего маршрута(от начальной станции до конечной): " << metr;
- }
- void GetVremyaRoute(Station* Obj, int n, char p3[30], char p4[30]){//время в пути
- double min = 0;
- double metr=0;
- int p1 = 0, p2 = 0;
- for (int i = 0; i < n; i++){
- if (strstr(Obj[i].name, p3))
- p1 = i;
- if (strstr(Obj[i].name, p4))
- p2 = i;
- }
- for (int i = p1; i < p2; i++)
- min += Obj[i].time;
- cout << "\n"<<"Время в пути: " << min;
- for (int i = p1; i < p2; i++)
- metr+=Obj[i].distanceToTheNextStation;
- cout << "\n"<<"Длина пути: " << metr;
- }
- void Replacement(Station* Obj, int n, char nam[30], double sp){//замена средней скорости
- int p=0;
- for (int i = 0; i < n; i++){
- if (strstr(Obj[i].name, nam))
- p = i;
- }
- Obj[p].speed=sp;
- Obj[p].print(p);
- cout<<endl;
- }
- };
- template <class T>
- struct element {
- T data;
- element *prev, *next;
- element(T item): data(item), prev(NULL), next(NULL) {};
- };
- int main() {
- setlocale(LC_ALL, "rus");
- int n;
- cout<<"Введите количество станций: ";
- cin>>n;
- Station* Obj=new Station [n];
- Route R;
- for (int i=0;i<n;i++){
- Station S;
- S.Get();
- R.GetStation(S);
- }
- R.Gets();
- /*char p3[30];
- cout << "Ведите пункт отправления: ";
- cin >> p3;
- char p4[30];
- cout << "Ведите пункт назначения: ";
- cin>> p4;
- R.ShowMarshryt(Obj,n,p3,p4);
- R.VremyaRoute(Obj,n);
- R.GetVremyaRoute(Obj,n,p3,p4);
- char nam[30];
- double sp;
- cout<<"\n"<<"Введите название станции, в которой меняется скорость: ";
- cin>>nam;
- cout<<"Введите скорость: ";
- cin>>sp;
- R.Replacement(Obj,n,nam,sp);
- */
- list<Station> listStation1;
- for (int i = 1; i < n; i++)
- listStation1.push_back(Obj[i]);
- //// Вывод содержимого списка
- //list<Station>::iterator it;
- //for (it=listStation.begin();it!=listStation.end();it++)
- // cout << (*it);
- /* Station Obj1("p",16,18,10);
- listStation.push_back(Obj1);
- cout << endl;
- list<Station>::iterator it1;
- for (it1=listStation.begin();it1!=listStation.end();it1++)
- cout << (*it1);
- cout << endl;
- listStation.pop_front();
- for (it1=listStation.begin();it1!=listStation.end();it1++)
- cout << (*it1);
- cout << endl;
- list<Station>::iterator it2=listStation.begin();
- listStation.insert(it2,Obj1);
- for (it1=listStation.begin();it1!=listStation.end();it1++)
- cout << (*it1);
- cout << endl;
- */
- delete []Obj;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement