Advertisement
Guest User

Untitled

a guest
May 26th, 2014
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.11 KB | None | 0 0
  1.  
  2.  
  3. #include <fstream>
  4. #include <iostream>
  5. #include <iomanip>
  6. #include <cstring>
  7. #include <cctype>
  8.  
  9.  
  10. using namespace std;
  11. string nazwa_pliku;
  12. ofstream output(nazwa_pliku.c_str());
  13.  
  14. //A - na grafie projektu
  15. class pojazd{
  16. int liczba_kol;
  17. protected:
  18. string rejestracja;
  19. public:
  20. pojazd() {};
  21. ~pojazd() {};
  22. pojazd *poprz;
  23. pojazd *nast;
  24. char nazwa[20];
  25. pojazd(int l_kol, string rejestr) : liczba_kol(l_kol), rejestracja(rejestr) {}
  26. void wyswietl()
  27. {
  28. cout<<"Liczba kol: "<<liczba_kol<<endl;
  29. cout<<"Rejestracja: "<<rejestracja<<endl;
  30. }
  31. void Modyfikuj_pojazd()
  32. {
  33. cout<<"Podaj nazwe obiektu:"<<endl;
  34. cin>>nazwa;
  35. cout<<"Jaka liczbe kol ma posiadac pojazd?"<<endl;
  36. cin>>liczba_kol;
  37. cout<<"Jaka rejestracje ma posiadac pojazd"<<endl;
  38. cin>>rejestracja;
  39. }
  40. void zapis_pojazd(FILE *pFile)
  41. {
  42. fprintf(pFile,"\n%s\n%d\n%s", nazwa, liczba_kol, rejestracja.c_str());
  43. }
  44. void czytaj_pojazd(FILE *pFile)
  45. {
  46. fscanf(pFile,"\n%s\n%d\n%s", nazwa, liczba_kol, rejestracja.c_str());
  47. }
  48.  
  49. };
  50.  
  51.  
  52. //B - na grafie projektu
  53. class jednoslady : public pojazd{
  54. int liczba_swiatel;
  55. protected:
  56. string kolor;
  57. public:
  58. jednoslady() {};
  59. ~jednoslady() {};
  60. jednoslady(int l_kol1, string rejestr1, int l_swiatel, string kol) : pojazd(l_kol1, rejestr1), liczba_swiatel(l_swiatel), kolor(kol) {}
  61.  
  62. void wyswietl1()
  63. {
  64. wyswietl();
  65. cout<<"Liczba swiatel: "<<liczba_swiatel<<endl;
  66. cout<<"Kolor: "<<kolor<<endl;
  67. }
  68. void Modyfikuj_jednoslady()
  69. {
  70. Modyfikuj_pojazd();
  71. cout<<"Jaka liczbe swiatel ma miec pojazd"<<endl;
  72. cin>>liczba_swiatel;
  73. cout<<"Jaki kolor ma miec pojazd"<<endl;
  74. cin>>kolor;
  75. }
  76.  
  77. void zapis_jednoslady(FILE *pFile)
  78. {
  79. zapis_pojazd(pFile);
  80. fprintf(pFile,"\n%d\n%s", liczba_swiatel, kolor.c_str());
  81. }
  82. void czytaj_jednoslad(FILE *pFile)
  83. {
  84. czytaj_pojazd(pFile);
  85. fscanf(pFile,"\n%d\n%s", liczba_swiatel, kolor.c_str());
  86. }
  87.  
  88. };
  89.  
  90.  
  91. //D(pochodna B)- na grafie projektu
  92. class rowery : public jednoslady{
  93. int liczba_przerzutek;
  94. protected:
  95. string rodzaj_hamulcow;
  96. public:
  97. rowery() {};
  98. ~rowery() {};
  99. rowery(int l_kol2, string rejestr2, int l_swiatel1, string kol1, int l_przerzutek, string r_ham) :
  100. jednoslady(l_kol2, rejestr2, l_swiatel1, kol1), liczba_przerzutek(l_przerzutek), rodzaj_hamulcow(r_ham) {}
  101.  
  102. void wyswietl2()
  103. {
  104. wyswietl1();
  105. cout<<"Liczba przerzutek: "<<liczba_przerzutek<<endl;
  106. cout<<"Rodzaj hamulcow: "<<rodzaj_hamulcow<<endl;
  107. }
  108. void Modyfikuj_rower()
  109. {
  110. Modyfikuj_jednoslady();
  111. cout<<"Jaka liczbe przerzutek ma miec pojazd"<<endl;
  112. cin>>liczba_przerzutek;
  113. cout<<"Jaki rodzaj hamulcow ma miec pojazd"<<endl;
  114. cin>>rodzaj_hamulcow;
  115. }
  116. void zapis_rowery(FILE *pFile)
  117. {
  118. zapis_jednoslady(pFile);
  119. fprintf(pFile,"\n%d\n%s", liczba_przerzutek, rodzaj_hamulcow.c_str());
  120. }
  121. void czytaj_rower(FILE *pFile)
  122. {
  123. czytaj_jednoslad(pFile);
  124. fscanf(pFile,"\n%d\n%s", liczba_przerzutek, rodzaj_hamulcow.c_str());
  125. }
  126. };
  127.  
  128.  
  129. //E(pochodna B)- na grafie projektu
  130. class motory : public jednoslady{
  131. int liczba_biegow;
  132. protected:
  133. int max_predkosc;
  134. public:
  135. motory() {};
  136. ~motory() {};
  137. motory(int l_kol3, string rejestr3, int l_swiatel2, string kol2, int l_bieg, int m_predkosc) :
  138. jednoslady(l_kol3, rejestr3, l_swiatel2, kol2), liczba_biegow(l_bieg), max_predkosc(m_predkosc) {}
  139.  
  140. void wyswietl3()
  141. {
  142. wyswietl1();
  143. cout<<"Liczba biegow: "<<liczba_biegow<<endl;
  144. cout<<"Maxymalna predkosc: "<<max_predkosc<<endl;
  145. }
  146. void Modyfikuj_motor()
  147. {
  148. Modyfikuj_jednoslady();
  149. cout<<"Jaka liczbe biegow ma posiadac pojazd?"<<endl;
  150. cin>>liczba_biegow;
  151. cout<<"Jaka maksymalna predkosc ma posiadac pojazd"<<endl;
  152. cin>>max_predkosc;
  153. }
  154. void zapis_motory(FILE *pFile)
  155. {
  156. zapis_jednoslady(pFile);
  157. fprintf(pFile,"\n%d\n%d", liczba_biegow, max_predkosc);
  158. }
  159. void czytaj_motor(FILE *pFile)
  160. {
  161. czytaj_jednoslad(pFile);
  162. fscanf(pFile,"\n%d\n%d", liczba_biegow, max_predkosc);
  163. }
  164. };
  165.  
  166.  
  167. //C - na grafie projektu
  168. class inne : public pojazd{
  169. int waga;
  170. protected:
  171. int liczba_siedzen;
  172. public:
  173. inne() {};
  174. ~inne() {};
  175. inne(int l_kol4, string rejestr4, int wag, int l_siedzen) : pojazd(l_kol4, rejestr4), waga(wag), liczba_siedzen(l_siedzen) {}
  176.  
  177. void wyswietl4()
  178. {
  179. wyswietl();
  180. cout<<"Waga: "<<waga<<endl;
  181. cout<<"Liczba siedzen: "<<liczba_siedzen<<endl;
  182. }
  183. void Modyfikuj_inne()
  184. {
  185. Modyfikuj_pojazd();
  186. cout<<"Jaka wage ma posiadac pojazd?"<<endl;
  187. cin>>waga;
  188. cout<<"Jaka liczbe siedzen ma posiadac pojazd"<<endl;
  189. cin>>liczba_siedzen;
  190. }
  191. void zapis_inne(FILE *pFile)
  192. {
  193. zapis_pojazd(pFile);
  194. fprintf(pFile,"\n%d\n%d", waga, liczba_siedzen);
  195. }
  196. void czytaj_inne(FILE *pFile)
  197. {
  198. czytaj_pojazd(pFile);
  199. fscanf(pFile,"\n%d\n%d", waga, liczba_siedzen);
  200. }
  201. };
  202.  
  203.  
  204. //F(pochodna C)- na grafie projektu
  205. class samochody : public inne{
  206. int ilosc_drzwi;
  207. protected:
  208. string marka_samochodu;
  209. public:
  210. samochody() {};
  211. ~samochody() {};
  212. samochody(int l_kol5, string rejestr5, int wag1, int l_siedzen1, int il_drzwi, string m_sam) : inne(l_kol5, rejestr5, wag1, l_siedzen1),
  213. ilosc_drzwi(il_drzwi), marka_samochodu(m_sam) {}
  214.  
  215. void wyswietl5()
  216. {
  217. wyswietl4();
  218. cout<<"Ilosc drzwi: "<<ilosc_drzwi<<endl;
  219. cout<<"Marka samochodu: "<<marka_samochodu<<endl;
  220. }
  221. void Modyfikuj_samochody()
  222. {
  223. Modyfikuj_inne();
  224. cout<<"Jaka ilosc drzwi ma posiadac pojazd?"<<endl;
  225. cin>>ilosc_drzwi;
  226. cout<<"Jaka marke samochodu posiadac pojazd"<<endl;
  227. cin>>marka_samochodu;
  228. }
  229. void zapis_samochody(FILE *pFile)
  230. {
  231. zapis_inne(pFile);
  232. fprintf(pFile,"\n%d\n%s", ilosc_drzwi, marka_samochodu.c_str());
  233. }
  234. void czytaj_samochod(FILE *pFile)
  235. {
  236. czytaj_inne(pFile);
  237. fscanf(pFile,"\n%d\n%s", ilosc_drzwi, marka_samochodu.c_str());
  238. }
  239. };
  240.  
  241. //G(pochodna C)- na grafie projektu
  242. class pojazdy_plywajace : public inne {
  243. int wypornosc;
  244. protected:
  245. int ilosc_turbin;
  246. public:
  247. pojazdy_plywajace() {};
  248. ~pojazdy_plywajace() {};
  249. pojazdy_plywajace(int l_kol6, string rejestr6, int wag2, int l_siedzen2,int wypor, int il_trb) : inne(l_kol6, rejestr6, wag2, l_siedzen2),
  250. wypornosc(wypor), ilosc_turbin(il_trb) {}
  251.  
  252. void wyswietl6()
  253. {
  254. wyswietl4();
  255. cout<<"Wypornosc: "<<wypornosc<<endl;
  256. cout<<"Ilosc turbin: "<<ilosc_turbin<<endl;
  257. }
  258. void Modyfikuj_pojazdy_plywajace()
  259. {
  260. Modyfikuj_inne();
  261. cout<<"Jaka wypornosc ma posiadac pojazd?"<<endl;
  262. cin>>wypornosc;
  263. cout<<"Jaka ilosc turbin ma posiadac pojazd"<<endl;
  264. cin>>ilosc_turbin;
  265. }
  266. void zapis_plywajace(FILE *pFile)
  267. {
  268. zapis_inne(pFile);
  269. fprintf(pFile,"\n%d\n%d", wypornosc, ilosc_turbin);
  270. }
  271. void czytaj_plywajace(FILE *pFile)
  272. {
  273. czytaj_inne(pFile);
  274. fscanf(pFile,"\n%d\n%d", wypornosc, ilosc_turbin);
  275. }
  276. };
  277.  
  278. //J(pochodna G)- na grafie projektu
  279. class kajaki : public pojazdy_plywajace {
  280. int ilosc_miejsc;
  281. protected:
  282. string rodzaj_wiosel;
  283. public:
  284. kajaki() {};
  285. ~kajaki() {};
  286. kajaki(int l_kol7, string rejestr7, int wag3, int l_siedzen3, int wypor1, int il_trb1, int il_msc, string r_wsl) :
  287. pojazdy_plywajace(l_kol7, rejestr7, wag3, l_siedzen3, wypor1, il_trb1), ilosc_miejsc(il_msc), rodzaj_wiosel(r_wsl) {}
  288.  
  289. void wyswietl7()
  290. {
  291. wyswietl6();
  292. cout<<"Ilosc miejsc: "<<ilosc_miejsc<<endl;
  293. cout<<"Rodzaj wiosel: "<<rodzaj_wiosel<<endl;
  294. }
  295. void Modyfikuj_kajak()
  296. {
  297. Modyfikuj_pojazdy_plywajace();
  298. cout<<"Jaka ilosc miejsc ma posiadac pojazd?"<<endl;
  299. cin>>ilosc_miejsc;
  300. cout<<"Jaki rodzaj wiosel ma posiadac pojazd"<<endl;
  301. cin>>rodzaj_wiosel;
  302. }
  303. void zapis_kajaki(FILE *pFile)
  304. {
  305. zapis_plywajace(pFile);
  306. fprintf(pFile,"\n%d\n%s", ilosc_miejsc, rodzaj_wiosel.c_str());
  307. }
  308. void czytaj_kajak(FILE *pFile)
  309. {
  310. czytaj_plywajace(pFile);
  311. fscanf(pFile,"\n%d\n%s", ilosc_miejsc, rodzaj_wiosel.c_str());
  312. }
  313. };
  314.  
  315. //K(pochodna C)- na grafie projektu
  316. class lotniskowce : public pojazdy_plywajace {
  317. int dlugosc;
  318. protected:
  319. int pasy_startowe;
  320. public:
  321. lotniskowce() {};
  322. ~lotniskowce() {};
  323. lotniskowce(int l_kol8, string rejestr8, int wag4, int l_siedzen4, int wypor2, int il_trb2, int dl, int p_st) :
  324. pojazdy_plywajace(l_kol8, rejestr8, wag4, l_siedzen4, wypor2, il_trb2), dlugosc(dl), pasy_startowe(p_st) {}
  325.  
  326. void wyswietl8()
  327. {
  328. wyswietl6();
  329. cout<<"Dlugosc: "<<dlugosc<<endl;
  330. cout<<"Pasy startowe: "<<pasy_startowe<<endl;
  331. }
  332. void Modyfikuj_lotniskowiec()
  333. {
  334. Modyfikuj_pojazdy_plywajace();
  335. cout<<"Jaka dlugosc ma posiadac pojazd?"<<endl;
  336. cin>>dlugosc;
  337. cout<<"Ile pasow startowych ma posiadac pojazd"<<endl;
  338. cin>>pasy_startowe;
  339. }
  340. void zapis_lotniskowce(FILE *pFile)
  341. {
  342. zapis_plywajace(pFile);
  343. fprintf(pFile,"\n%d\n%d", dlugosc, pasy_startowe);
  344. }
  345. void czytaj_lotniskowce(FILE *pFile)
  346. {
  347. czytaj_plywajace(pFile);
  348. fscanf(pFile,"\n%d\n%d", dlugosc, pasy_startowe);
  349. }
  350. };
  351.  
  352. //I(pochodna F) - na grafie projektu
  353. class osobowe : public samochody {
  354. int poduszki_pow;
  355. protected:
  356. int ilosc_wycieraczek;
  357. public:
  358. osobowe() {};
  359. ~osobowe() {};
  360. osobowe(int l_kol9, string rejestr9, int wag5, int l_siedzen5 ,int il_drzwi1, string m_sam1, int pod_pow, int il_wyc) :
  361. samochody(l_kol9, rejestr9, wag5, l_siedzen5, il_drzwi1, m_sam1), poduszki_pow(pod_pow), ilosc_wycieraczek(il_wyc) {}
  362.  
  363. void wyswietl9()
  364. {
  365. wyswietl5();
  366. cout<<"Poduszki powietrzne: "<<poduszki_pow<<endl;
  367. cout<<"Ilosc wycieraczek: "<<ilosc_wycieraczek<<endl;
  368. }
  369. void Modyfikuj_osobowe()
  370. {
  371. Modyfikuj_samochody();
  372. cout<<"Ile poduszek powietrznych ma posiadac pojazd?"<<endl;
  373. cin>>poduszki_pow;
  374. cout<<"Ile wycieraczek ma posiadac pojazd"<<endl;
  375. cin>>ilosc_wycieraczek;
  376. }
  377. void zapis_osobowe(FILE *pFile)
  378. {
  379. zapis_samochody(pFile);
  380. fprintf(pFile,"\n%d\n%d", poduszki_pow, ilosc_wycieraczek);
  381. }
  382. void czytaj_osobowe(FILE *pFile)
  383. {
  384. czytaj_samochod(pFile);
  385. fscanf(pFile,"\n%d\n%d", poduszki_pow, ilosc_wycieraczek);
  386. }
  387. };
  388.  
  389. //M(pochodna I) - na grafie projektu
  390. class terenowe : public osobowe {
  391. int cena;
  392. protected:
  393. string naped;
  394. public:
  395. terenowe() {};
  396. ~terenowe() {};
  397. terenowe(int l_kol10, string rejestr10, int wag6, int l_siedzen6, int il_drzwi2, string m_sam2, int pod_pow1, int il_wyc1, int cen, string nap) :
  398. osobowe(l_kol10, rejestr10, wag6, l_siedzen6, il_drzwi2, m_sam2, pod_pow1, il_wyc1),cena(cen), naped(nap) {}
  399.  
  400. void wyswietl10()
  401. {
  402. wyswietl9();
  403. cout<<"Cena: "<<cena<<endl;
  404. cout<<"Naped: "<<naped<<endl;
  405. }
  406. void Modyfikuj_terenowke()
  407. {
  408. Modyfikuj_osobowe();
  409. cout<<"Jaka cene ma posiadac pojazd?"<<endl;
  410. cin>>cena;
  411. cout<<"Jaki naped ma posiadac pojazd"<<endl;
  412. cin>>naped;
  413. }
  414. void zapis_terenowe(FILE *pFile)
  415. {
  416. zapis_osobowe(pFile);
  417. fprintf(pFile,"\n%d\n%s", cena, naped.c_str());
  418. }
  419. void czytaj_terenowke(FILE *pFile)
  420. {
  421. czytaj_osobowe(pFile);
  422. fscanf(pFile,"\n%d\n%s", cena, naped.c_str());
  423. }
  424. };
  425.  
  426. //L(pochodna I) - na grafie projektu
  427. class kabriolety : public osobowe {
  428. int pojemnosc_baku;
  429. protected:
  430. string rodzaj_swiatel;
  431. public:
  432. kabriolety() {};
  433. ~kabriolety() {};
  434. kabriolety(int l_kol11, string rejestr11, int wag7, int l_siedzen7, int il_drzwi3, string m_sam3, int pod_pow2, int il_wyc2, int p_baku, string r_swia) :
  435. osobowe(l_kol11, rejestr11, wag7, l_siedzen7, il_drzwi3, m_sam3, pod_pow2, il_wyc2), pojemnosc_baku(p_baku), rodzaj_swiatel(r_swia) {}
  436.  
  437. void wyswietl11()
  438. {
  439. wyswietl9();
  440. cout<<"Pojemnosc baku: "<<pojemnosc_baku<<endl;
  441. cout<<"Rodzaj swiatel: "<<rodzaj_swiatel<<endl;
  442. }
  443. void Modyfikuj_kabriolet()
  444. {
  445. Modyfikuj_osobowe();
  446. cout<<"Jaka pojemnosc baku ma posiadac pojazd?"<<endl;
  447. cin>>pojemnosc_baku;
  448. cout<<"Jaki rodzaj swiatel ma posiadac pojazd"<<endl;
  449. cin>>rodzaj_swiatel;
  450. }
  451. void zapis_kabriolety(FILE *pFile)
  452. {
  453. zapis_osobowe(pFile);
  454. fprintf(pFile,"\n%d\n%s", pojemnosc_baku, rodzaj_swiatel.c_str());
  455. }
  456. void czytaj_kabriolet(FILE *pFile)
  457. {
  458. czytaj_osobowe(pFile);
  459. fscanf(pFile,"\n%d\n%s", pojemnosc_baku, rodzaj_swiatel.c_str());
  460. }
  461. };
  462.  
  463.  
  464.  
  465.  
  466. template<class pnt>
  467. pnt* Dodawanie(pnt *first, pnt *last)
  468. {
  469. pnt *tmp=first;
  470. if(first==NULL)
  471. {
  472. first=new pnt;
  473. return first;
  474. }
  475. else
  476. {
  477. while(tmp->nast!=NULL)
  478. {tmp=(pnt *)tmp->nast;}
  479. last=new pnt;
  480. tmp->nast=last;
  481. last->poprz=tmp;
  482. return last;
  483. }
  484. }
  485.  
  486. pojazd *current=NULL;
  487. pojazd *A_first=NULL;
  488. pojazd *A_last=NULL;
  489. jednoslady *B_first=NULL;
  490. jednoslady *B_last=NULL;
  491. inne *C_first=NULL;
  492. inne *C_last=NULL;
  493. rowery *D_first=NULL;
  494. rowery *D_last=NULL;
  495. motory *E_first=NULL;
  496. motory *E_last=NULL;
  497. samochody *F_first=NULL;
  498. samochody *F_last=NULL;
  499. pojazdy_plywajace *G_first=NULL;
  500. pojazdy_plywajace *G_last=NULL;
  501. kajaki *J_first=NULL;
  502. kajaki *J_last=NULL;
  503. lotniskowce *K_first=NULL;
  504. lotniskowce *K_last=NULL;
  505. osobowe *I_first=NULL;
  506. osobowe *I_last=NULL;
  507. kabriolety *L_first=NULL;
  508. kabriolety *L_last=NULL;
  509. terenowe *M_first=NULL;
  510. terenowe *M_last=NULL;
  511.  
  512. template <class pnt>
  513. int pokaz_obiekt(pnt *tmp)
  514. {
  515.  
  516.  
  517. char szukana[20];
  518. cout<<"Podaj nazwe obiektu ktory chcesz znalezc"<<endl;
  519. cin>>szukana;
  520. while(strcmp(szukana, tmp->nazwa)!=0)
  521. {
  522. tmp=tmp->nast;
  523. if(tmp==NULL)
  524. {
  525. cout<<"Nie ma takiego obiektu!"<<endl;
  526. return 0;
  527. }
  528. }
  529.  
  530. if(current==A_first)
  531. {
  532. tmp->wyswietl();
  533. }
  534. else if(current==B_first)
  535. {
  536. jednoslady *wyp=(jednoslady*)tmp;
  537. wyp->wyswietl1();
  538. }
  539. else if(current==C_first)
  540. {
  541. inne *wyp=(inne*)tmp;
  542. wyp->wyswietl4();
  543. }
  544. else if(current==D_first)
  545. {
  546. rowery *wyp=(rowery*)tmp;
  547. wyp->wyswietl2();
  548. }
  549. else if(current==E_first)
  550. {
  551. motory *wyp=(motory*)tmp;
  552. wyp->wyswietl3();
  553. }
  554. else if(current==F_first)
  555. {
  556. samochody *wyp=(samochody*)tmp;
  557. wyp->wyswietl5();
  558. }
  559. else if(current==G_first)
  560. {
  561. pojazdy_plywajace *wyp=(pojazdy_plywajace*)tmp;
  562. wyp->wyswietl6();
  563. }
  564. else if(current==J_first)
  565. {
  566. kajaki *wyp=(kajaki*)tmp;
  567. wyp->wyswietl7();
  568. }
  569. else if(current==K_first)
  570. {
  571. lotniskowce *wyp=(lotniskowce*)tmp;
  572. wyp->wyswietl8();
  573. }
  574. else if(current==I_first)
  575. {
  576. osobowe *wyp=(osobowe*)tmp;
  577. wyp->wyswietl9();
  578. }
  579. else if(current==L_first)
  580. {
  581. kabriolety *wyp=(kabriolety*)tmp;
  582. wyp->wyswietl11();
  583. }
  584. else if(current==M_first)
  585. {
  586. terenowe *wyp=(terenowe*)tmp;
  587. wyp->wyswietl10();
  588. }
  589. cout<<endl;
  590. }
  591.  
  592. template <class pnt>
  593. int Pokaz_Liste(pnt *tmp)
  594. {
  595.  
  596. tmp=current;
  597. cout<<"Lista obiektow:"<<endl;
  598. while(tmp!=NULL)
  599. {
  600. cout<<tmp->nazwa<<endl;
  601. tmp=tmp->nast;
  602. }
  603.  
  604. }
  605.  
  606.  
  607. template <class pnt>
  608. int Usun_obiekt(pnt *tmp)
  609. {
  610. char nazwaobiektu[20];
  611. cout<<"Podaj nazwe obiektu ktory chcesz usunac"<<endl;
  612. cin>>nazwaobiektu;
  613. while(strcmp(nazwaobiektu, tmp->nazwa)!=0)
  614. {
  615. tmp=tmp->nast;
  616. if(tmp==NULL){break;}
  617. }
  618. if(tmp==NULL)
  619. {
  620. cout<<"Nie ma takiego obiektu!"<<endl;
  621. return 0;
  622. }
  623. if(tmp->nast==NULL && tmp->poprz==NULL)
  624. {
  625. cout<<"Nie mozna usunac liscia!"<<endl;
  626. return 0;
  627. }
  628. //SRODEK
  629. else if(tmp->nast!=NULL && tmp->poprz!=NULL)
  630. {
  631. (tmp->poprz)->nast=tmp->nast;
  632. (tmp->nast)->poprz=tmp->poprz;
  633. delete tmp;
  634. }
  635. //1 ELEM
  636. else if(tmp->poprz==NULL&& tmp->nast!=NULL)
  637. {
  638. if(current==D_first)
  639. {
  640. D_first=(rowery*)tmp->nast;
  641. current=D_first;
  642. delete tmp;
  643. D_first->poprz=NULL;
  644. }
  645. else if(current==E_first)
  646. {
  647. E_first=(motory*)tmp->nast;
  648. current=E_first;
  649. delete tmp;
  650. E_first->poprz=NULL;
  651. }
  652. else if(current==J_first)
  653. {
  654. J_first=(kajaki*)tmp->nast;
  655. current=J_first;
  656. delete tmp;
  657. J_first->poprz=NULL;
  658. }
  659. else if(current==K_first)
  660. {
  661. K_first=(lotniskowce*)tmp->nast;
  662. current=K_first;
  663. delete tmp;
  664. K_first->poprz=NULL;
  665. }
  666. else if(current==L_first)
  667. {
  668. L_first=(kabriolety*)tmp->nast;
  669. current=L_first;
  670. delete tmp;
  671. L_first->poprz=NULL;
  672. }
  673. else if(current==M_first)
  674. {
  675. M_first=(terenowe*)tmp->nast;
  676. current=M_first;
  677. delete tmp;
  678. M_first->poprz=NULL;
  679. }
  680. }
  681. //LAST ELEM
  682. else if(tmp->nast==NULL && tmp->poprz!=NULL)
  683. {
  684.  
  685. if(current==D_first)
  686. {
  687. D_last=(rowery*)tmp->poprz;
  688. delete tmp;
  689. D_last->nast=NULL;
  690. }
  691. else if(current==E_first)
  692. {
  693. E_last=(motory*)tmp->poprz;
  694. delete tmp;
  695. E_last->nast=NULL;
  696. }
  697. else if(current==J_first)
  698. {
  699. J_last=(kajaki*)tmp->poprz;
  700. delete tmp;
  701. J_last->nast=NULL;
  702. }
  703. else if(current==K_first)
  704. {
  705. K_last=(lotniskowce*)tmp->poprz;
  706. delete tmp;
  707. K_last->nast=NULL;
  708. }
  709. else if(current==L_first)
  710. {
  711. L_last=(kabriolety*)tmp->poprz;
  712. delete tmp;
  713. L_last->nast=NULL;
  714. }
  715. else if(current==M_first)
  716. {
  717. M_last=(terenowe*)tmp->poprz;
  718. delete tmp;
  719. M_last->nast=NULL;
  720. }
  721. }
  722. cout<<"Usunieto"<<endl;
  723.  
  724. }
  725.  
  726. template <class pnt>
  727. int zmien_obiekt(pnt *tmp)
  728. {
  729. char nazwaobiektu[20];
  730. cout<<"Podaj nazwe obiektu ktory chcesz zmienic"<<endl;
  731. cin>>nazwaobiektu;
  732. while(strcmp(nazwaobiektu, tmp->nazwa)!=0)
  733. {
  734. tmp=tmp->nast;
  735. if(tmp==NULL)
  736. {
  737. cout<<"Nie ma takiego obiektu!"<<endl;
  738. return 0;
  739. }
  740. }
  741. if(current==D_first)
  742. {
  743. cout<<"Wpisz nowe wartosci dla obiektu: "<<endl;
  744. rowery *wyp=(rowery*)tmp;
  745. wyp->Modyfikuj_rower();
  746. }
  747. else if(current==E_first)
  748. {
  749. cout<<"Wpisz nowe wartosci dla obiektu: "<<endl;
  750. motory *wyp=(motory*)tmp;
  751. wyp->Modyfikuj_motor();
  752. }
  753. else if(current==J_first)
  754. {
  755. cout<<"Wpisz nowe wartosci dla obiektu: "<<endl;
  756. kajaki *wyp=(kajaki*)tmp;
  757. wyp->Modyfikuj_kajak();
  758. }
  759. else if(current==K_first)
  760. {
  761. cout<<"Wpisz nowe wartosci dla obiektu: "<<endl;
  762. lotniskowce *wyp=(lotniskowce*)tmp;
  763. wyp->Modyfikuj_lotniskowiec();
  764. }
  765. else if(current==L_first)
  766. {
  767. cout<<"Wpisz nowe wartosci dla obiektu: "<<endl;
  768. kabriolety *wyp=(kabriolety*)tmp;
  769. wyp->Modyfikuj_kabriolet();
  770. }
  771. else if(current==M_first)
  772. {
  773. cout<<"Wpisz nowe wartosci dla obiektu: "<<endl;
  774. terenowe *wyp=(terenowe*)tmp;
  775. wyp->Modyfikuj_terenowke();
  776. }
  777.  
  778. }
  779.  
  780. template <class pnt>
  781. pnt* Zapisz_plik(pnt *tmp)
  782. {
  783. char naswa[20];
  784. cout<<"Podaj nazwe pliku (z dopiskiem .txt)"<<endl;
  785. cin>>naswa;
  786. FILE *pFile;
  787. pFile=fopen(naswa, "w+");
  788. if(current==D_first)
  789. {
  790. if(D_first->nast!=NULL)
  791. {
  792. D_first=(rowery*)D_first->nast;
  793. while(D_first)
  794. {
  795. // fprintf(pFile, "Rowery");
  796. D_first->zapis_rowery(pFile);
  797. D_first=(rowery*)D_first->nast;
  798. }
  799. }
  800. D_first=(rowery*)tmp;}
  801. else if(current==E_first)
  802. {
  803. tmp=(motory*)E_first;
  804. E_first->zapis_motory(pFile);
  805. if(E_first->nast!=NULL)
  806. {
  807. E_first=(motory*)E_first->nast;
  808. while(E_first)
  809. {
  810. // fprintf(pFile, "Motory");
  811. E_first->zapis_motory(pFile);
  812. E_first=(motory*)E_first->nast;
  813. }
  814. }
  815. E_first=(motory*)tmp;}
  816. else if(current==K_first)
  817. {
  818. tmp=(lotniskowce*)K_first;
  819. K_first->zapis_lotniskowce(pFile);
  820. if(K_first->nast!=NULL)
  821. {
  822. K_first=(lotniskowce*)K_first->nast;
  823. while(K_first)
  824. {
  825. // fprintf(pFile, "Lotniskowce");
  826. K_first->zapis_lotniskowce(pFile);
  827. K_first=(lotniskowce*)K_first->nast;
  828. }
  829. }
  830. K_first=(lotniskowce*)tmp;}
  831. else if(current==J_first)
  832. {
  833. tmp=(kajaki*)J_first;
  834. J_first->zapis_kajaki(pFile);
  835. if(J_first->nast!=NULL)
  836. {
  837. J_first=(kajaki*)J_first->nast;
  838. while(J_first)
  839. {
  840. // fprintf(pFile, "Kajaki");
  841. J_first->zapis_kajaki(pFile);
  842. J_first=(kajaki*)J_first->nast;
  843. }
  844. }
  845. J_first=(kajaki*)tmp;}
  846. else if(current==L_first)
  847. {
  848. tmp=(kabriolety*)L_first;
  849. L_first->zapis_kabriolety(pFile);
  850. if(L_first->nast!=NULL)
  851. {
  852. L_first=(kabriolety*)L_first->nast;
  853. while(L_first)
  854. {
  855. //fprintf(pFile, "Kabriolety");
  856. L_first->zapis_kabriolety(pFile);
  857. L_first=(kabriolety*)L_first->nast;
  858. }
  859. }
  860. L_first=(kabriolety*)tmp;}
  861. else if(current==M_first)
  862. {
  863. tmp=(terenowe*)M_first;
  864. M_first->zapis_terenowe(pFile);
  865. if(M_first->nast!=NULL)
  866. {
  867. M_first=(terenowe*)M_first->nast;
  868. while(M_first)
  869. {
  870. //fprintf(pFile, "Terenowe");
  871. M_first->zapis_terenowe(pFile);
  872. M_first=(terenowe*)L_first->nast;
  873. }
  874. }
  875. }
  876. fclose(pFile);
  877. cout<<"Zapisano"<<endl<<endl;
  878. }
  879.  
  880. template <class pnt>
  881. pnt* odczytaj_plik(pnt *tmp)
  882. {
  883. char naswa[20];
  884. cout<<"Podaj nazwe pliku z dopiskiem .txt"<<endl;
  885. cin>>naswa;
  886. FILE *pFile;
  887. pFile=fopen(naswa, "r");
  888. if(pFile==NULL)
  889. {
  890. cout<<"Nie ma takiego pliku!"<<endl;
  891. return 0;
  892. }
  893.  
  894. while(1)
  895. {
  896. if( (current=D_first)||(current=D_last) )
  897. {
  898. if(D_first==NULL)
  899. {
  900. D_first=Dodawanie(D_first, D_last);
  901. D_first->czytaj_rower(pFile);
  902. }
  903. else
  904. {
  905. D_last=Dodawanie(D_first, D_last);
  906. D_last->czytaj_rower(pFile);
  907. }
  908. }
  909. else if( (current=E_first)||(current=E_last) )
  910. {
  911. if(E_first==NULL)
  912. {
  913. E_first=Dodawanie(E_first, E_last);
  914. E_first->czytaj_motor(pFile);
  915. }
  916. else
  917. {
  918. E_last=Dodawanie(E_first, E_last);
  919. E_last->czytaj_motor(pFile);
  920. }
  921. }
  922. else if( (current=J_first) ||(current=J_last) )
  923. {
  924. if(J_first==NULL)
  925. {
  926. J_first=Dodawanie(J_first, J_last);
  927. J_first->czytaj_kajak(pFile);
  928. }
  929. else
  930. {
  931. J_last=Dodawanie(J_first, J_last);
  932. J_last->czytaj_kajak(pFile);
  933. }
  934. }
  935. else if( (current=K_first)||(current=K_last) )
  936. {
  937. if(K_first==NULL)
  938. {
  939. K_first=Dodawanie(K_first, K_last);
  940. K_first->czytaj_lotniskowce(pFile);
  941. }
  942. else
  943. {
  944. K_last=Dodawanie(K_first, K_last);
  945. K_last->czytaj_lotniskowce(pFile);
  946. }
  947. }
  948. else if(current=L_first||current=L_last)
  949. {
  950. if(L_first==NULL)
  951. {
  952. L_first=Dodawanie(L_first, L_last);
  953. L_first->czytaj_kabriolet(pFile);
  954. }
  955. else
  956. {
  957. L_last=Dodawanie(L_first, L_last);
  958. L_last->czytaj_kabriolet(pFile);
  959. }
  960. }
  961. else if(current=M_first||current=M_last)
  962. {
  963. if(M_first==NULL)
  964. {
  965. M_first=Dodawanie(M_first, M_last);
  966. M_first->czytaj_terenowke(pFile);
  967. }
  968. else
  969. {
  970. M_last=Dodawanie(M_first, M_last);
  971. M_last->czytaj_terenowke(pFile);
  972. }
  973. }
  974. fclose(pFile);
  975. }
  976. }
  977.  
  978.  
  979.  
  980.  
  981. int main()
  982. {
  983. int opcja=0;
  984. char zmiana;
  985. char nazwana[20];
  986. char sym[10];
  987.  
  988.  
  989. A_first=Dodawanie(A_first, A_last);
  990. B_first=Dodawanie(B_first, B_last);
  991. C_first=Dodawanie(C_first, C_last);
  992. D_first=Dodawanie(D_first, D_last);
  993. E_first=Dodawanie(E_first, E_last);
  994. F_first=Dodawanie(F_first, F_last);
  995. G_first=Dodawanie(G_first, G_last);
  996. I_first=Dodawanie(I_first, I_last);
  997. J_first=Dodawanie(J_first, J_last);
  998. K_first=Dodawanie(K_first, K_last);
  999. L_first=Dodawanie(L_first, L_last);
  1000. M_first=Dodawanie(M_first, M_last);
  1001.  
  1002. cout<<endl;
  1003. A:cout<<"---MENU---"<<endl;
  1004. cout<<"1.CD-zmiana wezla"<<endl;
  1005. cout<<"2.MO-tworzenie obiektu"<<endl;
  1006. cout<<"3.DO-usuwanie obiektu"<<endl;
  1007. cout<<"4.MDO-modyfikacja obiektu"<<endl;
  1008. cout<<"5.DIR-lista obiektow"<<endl;
  1009. cout<<"6.SHOW-wyswietl szczegolowo obiekt"<<endl;
  1010. cout<<"7.SAVE-zapis do pliku"<<endl;
  1011. cout<<"8.READ-czytanie z programu"<<endl;
  1012. cout<<"9.TREE-wyswietla schemat dziedziczenia klas"<<endl;
  1013. cout<<"10.END-koniec programu"<<endl;
  1014. cout<<endl<<endl;
  1015. cout<<"Wybierz nazwe polecenia ktorego chcesz uzyc:"<<endl;
  1016. cin>>sym;
  1017.  
  1018. char CD[]="CD";
  1019. char MO[]="MO";
  1020. char DO[]="DO";
  1021. char MDO[]="MDO";
  1022. char DIR[]="DIR";
  1023. char SHOW[]="SHOW";
  1024. char SAVE[]="SAVE";
  1025. char TREE[]="TREE";
  1026. char READ[]="READ";
  1027. char END[]="END";
  1028.  
  1029. while(1)
  1030. {
  1031. B: if (strcmp(sym, CD)==0)
  1032. opcja=1;
  1033. else if (strcmp(sym, MO)==0)
  1034. opcja=2;
  1035. else if (strcmp(sym, DO)==0)
  1036. opcja=3;
  1037. else if (strcmp(sym, MDO)==0)
  1038. opcja=4;
  1039. else if (strcmp(sym, DIR)==0)
  1040. opcja=5;
  1041. else if (strcmp(sym, SHOW)==0)
  1042. opcja=6;
  1043. else if (strcmp(sym, SAVE)==0)
  1044. opcja=7;
  1045. else if (strcmp(sym, READ)==0)
  1046. opcja= 8;
  1047. else if (strcmp(sym, TREE)==0)
  1048. opcja= 9;
  1049. else if (strcmp(sym, END)==0)
  1050. opcja=10;
  1051. else
  1052. {cout<<"Podaj poprawna nazwe polecenia"<<endl;
  1053. goto A;}
  1054.  
  1055. cout<<endl;
  1056. while(1)
  1057. {
  1058. switch(opcja)
  1059. {
  1060. case 1:
  1061. cout<<"Podaj znak wezla w ktorym chcesz utworzyc obiekt z mozliwych lisci:\n";
  1062. cout<<"D-rowery\n";
  1063. cout<<"E-motory\n";
  1064. cout<<"J-kajaki\n";
  1065. cout<<"K-lotniskowce\n";
  1066. cout<<"L-kabriolety\n";
  1067. cout<<"M-terenowe\n";
  1068. cout<<endl;
  1069. cout<<"Twoj wybor: ";
  1070. cin>>zmiana;
  1071. cout<<endl;
  1072. if(zmiana=='d'||zmiana=='D')
  1073. {
  1074. current=D_first;
  1075. }
  1076. else if(zmiana=='e'||zmiana=='E')
  1077. {
  1078. current=E_first;
  1079. }
  1080. else if(zmiana=='j'||zmiana=='J')
  1081. {
  1082. current=J_first;
  1083. }
  1084. else if(zmiana=='k'||zmiana=='K')
  1085. {
  1086. current=K_first;
  1087. }
  1088. else if(zmiana=='l'||zmiana=='L')
  1089. {
  1090. current=L_first;
  1091. }
  1092. else if(zmiana=='m'||zmiana=='M')
  1093. {
  1094. current=M_first;
  1095. }
  1096. goto A;
  1097. break;
  1098.  
  1099. case 2:
  1100.  
  1101. if(current==D_first)
  1102. {
  1103.  
  1104. D_last=Dodawanie(D_first, D_last);
  1105. D_last->Modyfikuj_rower();
  1106. }
  1107. else if(current==E_first)
  1108. {
  1109. E_last=Dodawanie(E_first, E_last);
  1110. E_last->Modyfikuj_motor();
  1111. }
  1112. else if(current==J_first)
  1113. {
  1114. J_last=Dodawanie(J_first, J_last);
  1115. J_last->Modyfikuj_kajak();
  1116. }
  1117. else if(current==K_first)
  1118. {
  1119. K_last=Dodawanie(K_first, K_last);
  1120. K_last->Modyfikuj_lotniskowiec();
  1121. }
  1122. else if(current==L_first)
  1123. {
  1124. L_last=Dodawanie(L_first,L_last);
  1125. L_last->Modyfikuj_kabriolet();
  1126. }
  1127. else if(current==M_first)
  1128. {
  1129. M_last=Dodawanie(M_first,M_last);
  1130. M_last->Modyfikuj_terenowke();
  1131. }
  1132. goto A;
  1133. break;
  1134. case 3:
  1135. Usun_obiekt(current);
  1136. goto A;
  1137. break;
  1138. case 4:
  1139. zmien_obiekt(current);
  1140. goto A;
  1141. break;
  1142. case 5:
  1143. Pokaz_Liste(current);
  1144. goto A;
  1145. break;
  1146. case 6:
  1147. pokaz_obiekt(current);
  1148. goto A;
  1149. break;
  1150. case 7:
  1151. Zapisz_plik(current);
  1152. goto A;
  1153. break;
  1154. case 8:
  1155. odczytaj_plik(current);
  1156. goto A;
  1157. break;
  1158. case 9:
  1159. cout<<"Drzewko projektu"<<endl;
  1160. cout<<endl<<endl;
  1161. cout<<"\t\tV-----------|Pojazd|--------------V"<<endl;
  1162. cout<<"\t\tV\t\t\t\t V"<<endl;
  1163. cout<<"\tV-|Jednoslady|-V"<<"\t\t V----|Inne|---------V"<<endl;
  1164. cout<<"\tV\t V\t\t V\t V"<<endl;
  1165. cout<<" |Rowery|"<<"\t |Motory|"<<"\t |Samochody|"<<"\t|Pojazdy Plywajace|"<<endl;
  1166. cout<<"\t\t\t\t\t V V V"<<endl;
  1167. cout<<"\t\t\t\t V-|Osobowe|-V"<<" |Kajaki| |Lotniskowce|"<<endl;
  1168. cout<<"\t\t\t\t V V"<<endl;
  1169. cout<<"\t\t\t |Terenowe| |Kabriolety|"<<endl<<endl<<endl;
  1170. goto A;
  1171. break;
  1172. case 10:
  1173. return 0;
  1174. }
  1175. }
  1176. }
  1177. return 0;
  1178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement