Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. struct samochod
  7. {
  8. string marka;
  9. string model;
  10. float cena;
  11. };
  12.  
  13. void pobierz_samochody(int ile, samochod* tablica_samochodow);
  14. void wypisz_samochody(int ile, samochod* tablica_samochodow);
  15. void zapisz_samochody(int ile, samochod* tablica_samochodow);
  16.  
  17. //samochod* tablica_samochodow;
  18.  
  19. int main(void)
  20. {
  21. int ile;
  22. string marka="";
  23. string model="";
  24. float cena = 00.00;
  25. samochod* tablica_samochodow;
  26.  
  27. cout << endl << "Ile samochodow bedziesz wprowadzac: ";
  28. cin >> ile;
  29. tablica_samochodow = new samochod[ile];
  30.  
  31. cout << endl;
  32. pobierz_samochody(ile, tablica_samochodow);
  33. wypisz_samochody(ile, tablica_samochodow);
  34. zapisz_samochody(ile, tablica_samochodow);
  35.  
  36. delete [] tablica_samochodow;
  37.  
  38. return 0;
  39. }
  40.  
  41. void pobierz_samochody(int ile, samochod* tablica_samochodow)
  42. {
  43. for(int i=0; i<ile; i++)
  44. {
  45. cout << "Podaj marke samochodu: " << i+1 << endl << endl;
  46. cout << " ";
  47. cin >> tablica_samochodow[i].marka;
  48. cout << endl;
  49.  
  50. cout << "Podaj model samochodu: " << i+1 << endl << endl;
  51. cout << " ";
  52. cin >> tablica_samochodow[i].model;
  53. cout << endl;
  54.  
  55. cout << "Podaj cene samochodu: " << i+1 << endl << endl;
  56. cout << " ";
  57. cin >> tablica_samochodow[i].cena;
  58. cout << endl;
  59. }
  60. }
  61.  
  62. void wypisz_samochody(int ile, samochod* tablica_samochodow)
  63. {
  64. for(int i=0; i<ile; i++)
  65. {
  66. cout << "Samochod: " << i+1 << endl << endl;
  67. cout << " " << "Marka: " << tablica_samochodow[i].marka << endl;
  68. cout << " " << "Model: " << tablica_samochodow[i].model << endl;
  69. cout << " " << "Cena: " << tablica_samochodow[i].cena << endl << endl;
  70. }
  71. }
  72.  
  73. void zapisz_samochody(int ile, samochod* tablica_samochodow)
  74. {
  75. ofstream zapis("dane.txt");
  76.  
  77. for(int i=0; i<ile; i++)
  78. {
  79. zapis << "Samochod: " << i+1 << endl << endl;
  80. zapis << " " << "Marka: " << tablica_samochodow[i].marka << endl;
  81. zapis << " " << "Model: " << tablica_samochodow[i].model << endl;
  82. zapis << " " << "Cena: " << tablica_samochodow[i].cena << endl << endl;
  83. }
  84.  
  85. zapis.close();
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement