Advertisement
Guest User

Untitled

a guest
May 26th, 2014
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.21 KB | None | 0 0
  1. class pojazd{
  2. int liczba_kol;
  3. protected:
  4. string rejestracja;
  5. public:
  6. pojazd() {};
  7. ~pojazd() {};
  8. pojazd *poprz;
  9. pojazd *nast;
  10. char nazwa[20];
  11. pojazd(int l_kol, string rejestr) : liczba_kol(l_kol), rejestracja(rejestr) {}
  12. void wyswietl()
  13. {
  14. cout<<"Liczba kol: "<<liczba_kol<<endl;
  15. cout<<"Rejestracja: "<<rejestracja<<endl;
  16. }
  17. void Modyfikuj_pojazd()
  18. {
  19. cout<<"Podaj nazwe obiektu:"<<endl;
  20. cin>>nazwa;
  21. cout<<"Jaka liczbe kol ma posiadac pojazd?"<<endl;
  22. cin>>liczba_kol;
  23. cout<<"Jaka rejestracje ma posiadac pojazd"<<endl;
  24. cin>>rejestracja;
  25. }
  26. void zapis_pojazd(FILE *pFile)
  27. {
  28. fprintf(pFile,"\n%s\n%d\n%s", nazwa, liczba_kol, rejestracja.c_str());
  29. }
  30. void czytaj_pojazd(FILE *pFile)
  31. {
  32. fscanf(pFile,"\n%s\n%d\n%s", nazwa, liczba_kol, rejestracja.c_str());
  33. }
  34.  
  35. };
  36.  
  37.  
  38. //B - na grafie projektu
  39. class jednoslady : public pojazd{
  40. int liczba_swiatel;
  41. protected:
  42. string kolor;
  43. public:
  44. jednoslady() {};
  45. ~jednoslady() {};
  46. jednoslady(int l_kol1, string rejestr1, int l_swiatel, string kol) : pojazd(l_kol1, rejestr1), liczba_swiatel(l_swiatel), kolor(kol) {}
  47.  
  48. void wyswietl1()
  49. {
  50. wyswietl();
  51. cout<<"Liczba swiatel: "<<liczba_swiatel<<endl;
  52. cout<<"Kolor: "<<kolor<<endl;
  53. }
  54. void Modyfikuj_jednoslady()
  55. {
  56. Modyfikuj_pojazd();
  57. cout<<"Jaka liczbe swiatel ma miec pojazd"<<endl;
  58. cin>>liczba_swiatel;
  59. cout<<"Jaki kolor ma miec pojazd"<<endl;
  60. cin>>kolor;
  61. }
  62.  
  63. void zapis_jednoslady(FILE *pFile)
  64. {
  65. zapis_pojazd(pFile);
  66. fprintf(pFile,"\n%d\n%s", liczba_swiatel, kolor.c_str());
  67. }
  68. void czytaj_jednoslad(FILE *pFile)
  69. {
  70. czytaj_pojazd(pFile);
  71. fscanf(pFile,"\n%d\n%s", liczba_swiatel, kolor.c_str());
  72. }
  73.  
  74. };
  75.  
  76. template <class pnt>
  77. pnt* Zapisz_plik(pnt *tmp)
  78. {
  79. char naswa[20];
  80. cout<<"Podaj nazwe pliku (z dopiskiem .txt)"<<endl;
  81. cin>>naswa;
  82. FILE *pFile;
  83. pFile=fopen(naswa, "w+");
  84. if(current==D_first)
  85. {
  86. if(D_first->nast!=NULL)
  87. {
  88. D_first=(rowery*)D_first->nast;
  89. while(D_first)
  90. {
  91. // fprintf(pFile, "Rowery");
  92. D_first->zapis_rowery(pFile);
  93. D_first=(rowery*)D_first->nast;
  94. }
  95. }
  96. D_first=(rowery*)tmp;}
  97. else if(current==E_first)
  98. {
  99. tmp=(motory*)E_first;
  100. E_first->zapis_motory(pFile);
  101. if(E_first->nast!=NULL)
  102. {
  103. E_first=(motory*)E_first->nast;
  104. while(E_first)
  105. {
  106. // fprintf(pFile, "Motory");
  107. E_first->zapis_motory(pFile);
  108. E_first=(motory*)E_first->nast;
  109. }
  110. }
  111. E_first=(motory*)tmp;}
  112. else if(current==K_first)
  113. {
  114. tmp=(lotniskowce*)K_first;
  115. K_first->zapis_lotniskowce(pFile);
  116. if(K_first->nast!=NULL)
  117. {
  118. K_first=(lotniskowce*)K_first->nast;
  119. while(K_first)
  120. {
  121. // fprintf(pFile, "Lotniskowce");
  122. K_first->zapis_lotniskowce(pFile);
  123. K_first=(lotniskowce*)K_first->nast;
  124. }
  125. }
  126. K_first=(lotniskowce*)tmp;}
  127. else if(current==J_first)
  128. {
  129. tmp=(kajaki*)J_first;
  130. J_first->zapis_kajaki(pFile);
  131. if(J_first->nast!=NULL)
  132. {
  133. J_first=(kajaki*)J_first->nast;
  134. while(J_first)
  135. {
  136. // fprintf(pFile, "Kajaki");
  137. J_first->zapis_kajaki(pFile);
  138. J_first=(kajaki*)J_first->nast;
  139. }
  140. }
  141. J_first=(kajaki*)tmp;}
  142. else if(current==L_first)
  143. {
  144. tmp=(kabriolety*)L_first;
  145. L_first->zapis_kabriolety(pFile);
  146. if(L_first->nast!=NULL)
  147. {
  148. L_first=(kabriolety*)L_first->nast;
  149. while(L_first)
  150. {
  151. //fprintf(pFile, "Kabriolety");
  152. L_first->zapis_kabriolety(pFile);
  153. L_first=(kabriolety*)L_first->nast;
  154. }
  155. }
  156. L_first=(kabriolety*)tmp;}
  157. else if(current==M_first)
  158. {
  159. tmp=(terenowe*)M_first;
  160. M_first->zapis_terenowe(pFile);
  161. if(M_first->nast!=NULL)
  162. {
  163. M_first=(terenowe*)M_first->nast;
  164. while(M_first)
  165. {
  166. //fprintf(pFile, "Terenowe");
  167. M_first->zapis_terenowe(pFile);
  168. M_first=(terenowe*)L_first->nast;
  169. }
  170. }
  171. }
  172. fclose(pFile);
  173. cout<<"Zapisano"<<endl<<endl;
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement