Advertisement
noler89

Untitled

May 19th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.59 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include<fstream>
  4. #include<ostream>
  5. #include <list>
  6. using namespace std;
  7.  
  8. class Station{
  9. public:
  10. char name[30];
  11. double time;
  12. double distanceToTheNextStation;
  13. double speed;
  14. char Station::nam() const{ for(int i=0;i<30;i++) return name[i];}
  15. double Station::tim() const{return time;}
  16. double Station::dis() const{return distanceToTheNextStation;}
  17. double Station::spe() const{return speed;}
  18. Station(){
  19. name[30]=' ';
  20. time=0;
  21. speed=0;
  22. distanceToTheNextStation=0;
  23. }
  24. Station(char name0[30],double time0,double distanceToTheNextStation0,double speed0){
  25. for (int i=0;i<30;i++)
  26. name[i]=name0[i];
  27. time=time0;
  28. speed=speed0;
  29. distanceToTheNextStation=distanceToTheNextStation0;
  30. }
  31. void Get(){
  32. cout << "Имя: ";
  33. cin >> name;
  34. cout << "Время в пути до сдедующей станции : ";
  35. cin >> time;
  36. cout << "Расстояние до следующей станции: ";
  37. cin >> distanceToTheNextStation;
  38. cout << "Скорость движения на участке до следующей станции: ";
  39. cin >> speed;
  40. cout << endl;
  41. }
  42. void print (int i) {
  43. cout << i + 1 << " " << name << '\t';
  44. cout << time <<'\t';
  45. cout << distanceToTheNextStation << '\t';
  46. cout << speed << endl;
  47. }
  48. friend ostream & operator << (ostream & out, Station T){
  49. out << " " << T.nam() << '\t';
  50. out << T.tim() <<'\t';
  51. out << T.dis() << '\t';
  52. out << T.spe() << endl;
  53. return out;
  54. }
  55. };
  56. class Route{
  57. public:
  58. list<Station> listStation;
  59. Route(){}
  60. // Вывод содержимого списка
  61. void Gets(){
  62. list<Station>::iterator it;
  63. for (it=listStation.begin();it!=listStation.end();it++)
  64. cout << (*it);
  65. }
  66. void GetStation(Station s){
  67.  
  68. listStation.push_back(s);
  69. }
  70. void ShowMarshryt(Station* Obj, int n, char p3[30], char p4[30]){
  71. cout << "№ " << "Имя\t" << "Время в пути\t" << "Расстояние\t" << "Скорость\t" << endl;
  72. cout << "========================================" << endl;
  73. int p1 = 0, p2 = 0;
  74. for (int i = 0; i < n; i++){
  75. if (strstr(Obj[i].name, p3))
  76. p1 = i;
  77. if (strstr(Obj[i].name, p4))
  78. p2 = i;
  79. }
  80. for (int i = p1; i < p2+1; i++)
  81. Obj[i].print (i);
  82. }
  83. void VremyaRoute(Station* Obj, int n){
  84. double min = 0;
  85. double metr=0;
  86. for(int i=0;i<n;i++)
  87. min += Obj[i].time;
  88. cout << "\n"<<"Общее время в пути(от начальной станции до конечной): " << min;
  89. for(int i=0;i<n;i++)
  90. metr+=Obj[i].distanceToTheNextStation;
  91. cout <<"\n"<< "Длина всего маршрута(от начальной станции до конечной): " << metr;
  92. }
  93. void GetVremyaRoute(Station* Obj, int n, char p3[30], char p4[30]){//время в пути
  94. double min = 0;
  95. double metr=0;
  96. int p1 = 0, p2 = 0;
  97. for (int i = 0; i < n; i++){
  98. if (strstr(Obj[i].name, p3))
  99. p1 = i;
  100. if (strstr(Obj[i].name, p4))
  101. p2 = i;
  102. }
  103. for (int i = p1; i < p2; i++)
  104. min += Obj[i].time;
  105. cout << "\n"<<"Время в пути: " << min;
  106. for (int i = p1; i < p2; i++)
  107. metr+=Obj[i].distanceToTheNextStation;
  108. cout << "\n"<<"Длина пути: " << metr;
  109. }
  110. void Replacement(Station* Obj, int n, char nam[30], double sp){//замена средней скорости
  111. int p=0;
  112. for (int i = 0; i < n; i++){
  113. if (strstr(Obj[i].name, nam))
  114. p = i;
  115. }
  116. Obj[p].speed=sp;
  117. Obj[p].print(p);
  118. cout<<endl;
  119. }
  120. };
  121.  
  122. template <class T>
  123. struct element {
  124. T data;
  125. element *prev, *next;
  126. element(T item): data(item), prev(NULL), next(NULL) {};
  127. };
  128.  
  129.  
  130. int main() {
  131. setlocale(LC_ALL, "rus");
  132. int n;
  133. cout<<"Введите количество станций: ";
  134. cin>>n;
  135. Station* Obj=new Station [n];
  136. Route R;
  137. for (int i=0;i<n;i++){
  138. Station S;
  139. S.Get();
  140. R.GetStation(S);
  141. }
  142. R.Gets();
  143. /*char p3[30];
  144. cout << "Ведите пункт отправления: ";
  145. cin >> p3;
  146. char p4[30];
  147. cout << "Ведите пункт назначения: ";
  148. cin>> p4;
  149. R.ShowMarshryt(Obj,n,p3,p4);
  150. R.VremyaRoute(Obj,n);
  151. R.GetVremyaRoute(Obj,n,p3,p4);
  152. char nam[30];
  153. double sp;
  154. cout<<"\n"<<"Введите название станции, в которой меняется скорость: ";
  155. cin>>nam;
  156. cout<<"Введите скорость: ";
  157. cin>>sp;
  158. R.Replacement(Obj,n,nam,sp);
  159. */
  160. list<Station> listStation1;
  161. for (int i = 1; i < n; i++)
  162. listStation1.push_back(Obj[i]);
  163. //// Вывод содержимого списка
  164. //list<Station>::iterator it;
  165. //for (it=listStation.begin();it!=listStation.end();it++)
  166. // cout << (*it);
  167. /* Station Obj1("p",16,18,10);
  168. listStation.push_back(Obj1);
  169. cout << endl;
  170. list<Station>::iterator it1;
  171. for (it1=listStation.begin();it1!=listStation.end();it1++)
  172. cout << (*it1);
  173. cout << endl;
  174. listStation.pop_front();
  175. for (it1=listStation.begin();it1!=listStation.end();it1++)
  176. cout << (*it1);
  177. cout << endl;
  178. list<Station>::iterator it2=listStation.begin();
  179. listStation.insert(it2,Obj1);
  180. for (it1=listStation.begin();it1!=listStation.end();it1++)
  181. cout << (*it1);
  182. cout << endl;
  183. */
  184.  
  185. delete []Obj;
  186.  
  187. system("pause");
  188. return 0;
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement