Advertisement
Guest User

ets \ cpp \ class_odgovor

a guest
May 27th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. //kreirati osnovnu klasu vozilo ciji su zasticeni atributi marka vozila, boja i godina proizvodnje
  2. //ova klasa posjeduje parametarski konstruktor i metodu za ispis.
  3. //kreirati izvedenu klasu autobuy ciji su privatni atributi broj sjedista i tip autobusa
  4. //ova klasa posjeduje parametarski konstruktor i metodu za ispis
  5.  
  6. //u main f-ji kreirati N objekata klase autobus i ispisati koliko ukupno ima mjesta u autobusima i podatke o autobusu sa najvecim i najmanjim brojem mjesta
  7. #include <iostream>
  8. #include <string>
  9. using namespace std;
  10.  
  11. class vozilo
  12. {
  13. protected:
  14. string marka;
  15. string boja;
  16. int godProizvodnje;
  17. public:
  18. vozilo()
  19. {
  20. marka = boja = "";
  21. godProizvodnje = 0;
  22. }
  23. vozilo(string m, string b, int gp)
  24. {
  25. marka = m;
  26. boja = b;
  27. godProizvodnje = gp;
  28. }
  29. void ispis()
  30. {
  31. cout<<"Marka: "<<marka<<endl;
  32. cout<<"Boja: "<<boja<<endl;
  33. cout<<"God proizvodnje: "<<godProizvodnje<<endl;
  34. }
  35. };
  36. class autobus: public vozilo
  37. {
  38. private:
  39. int sjedista;
  40. string tip;
  41. public:
  42. autobus()
  43. {
  44. sjedista = 0;
  45. tip = "";
  46. }
  47. autobus(string m, string b, int god, int sj, string t) : vozilo(m, b, god)
  48. {
  49. sjedista = sj;
  50. tip = t;
  51. }
  52. void ispis()
  53. {
  54. vozilo::ispis();
  55. cout<<"Sjedista: "<<sjedista<<endl;
  56. cout<<"Tip: "<<tip<<endl;
  57. }
  58. void unos()
  59. {
  60. cout<<"Unesi marku: ";
  61. cin>>ws;
  62. getline(cin, marka);
  63. cout<<"Unesi boju: ";
  64. getline(cin, boja);
  65. cout<<"Unesi godinu proizvodnje: ";
  66. cin>>godProizvodnje;
  67. cout<<"Unesi broj sjedista: ";
  68. cin>>sjedista;
  69. cout<<"Unesi vrstu autobusa: ";
  70. cin>>ws;
  71. getline(cin, tip);
  72. }
  73. int get_sjedista()
  74. {
  75. return sjedista;
  76. }
  77. };
  78.  
  79. int main()
  80. {
  81. int n;
  82. cout<<"Unesi N: ";
  83. cin>>n;
  84.  
  85. autobus a[n];
  86.  
  87. string marka, boja, vrsta;
  88. int god, sjedista;
  89. for(int i = 0; i < n; i++)
  90. {
  91. a[i].unos();
  92. //a[i].ispis();
  93. }
  94.  
  95. int suma = 0, indxMin = 0, indxMax = 0;
  96. for(int i = 0; i < n; i++)
  97. {
  98. if(a[i].get_sjedista() > a[indxMax].get_sjedista() ) indxMax = i;
  99. if(a[i].get_sjedista() < a[indxMin].get_sjedista() ) indxMin = i;
  100.  
  101. suma += a[i].get_sjedista();
  102. }
  103. cout<<"Ukupno sjedista: "<<suma<<endl;
  104.  
  105. cout<<"== Autobus sa najvecim brojem sjedista =="<<endl<<;
  106. a[indxMax].ispis();
  107. cout<<"== Autobus sa najmanjim brojem sjedista =="<<endl<<;
  108. a[indxMin].ispis();
  109. return 1;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement