Advertisement
extrica

Untitled

Jun 9th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. /*TP 16/17 (Tutorijal 13, Zadatak 2)*/
  2. #include <iostream>
  3. #include <string>
  4. #include <stdexcept>
  5. #include <vector>
  6. #include <memory>
  7.  
  8. using namespace std;
  9.  
  10. class ApstraktniStudent {
  11.  
  12. protected:
  13.  
  14. string ime, prezime;
  15. int broj_indeksa;
  16. int broj_polozenih;
  17. double prosjek;
  18.  
  19. public:
  20. ApstraktniStudent(string ime, string prezime, int broj_indeksa) : ime(ime), prezime(prezime), broj_indeksa(broj_indeksa), broj_polozenih(0), prosjek(5) {}
  21.  
  22. string DajIme() const { return ime; }
  23. string DajPrezime() const { return prezime; }
  24. int DajBrojIndeksa() const { return broj_indeksa; }
  25. int DajBrojPolozenih() const { return broj_polozenih; }
  26. double DajProsjek() const { return prosjek; }
  27.  
  28. void RegistrirajIspit(int ocjena);
  29. void PonistiOcjene();
  30. virtual ~ApstraktniStudent() {}
  31. virtual void IspisiPodatke() const =0;
  32. virtual ApstraktniStudent* DajKopiju() const =0;
  33. };
  34.  
  35. void ApstraktniStudent::RegistrirajIspit(int ocjena) {
  36.  
  37. if(ocjena < 5 || ocjena > 10) throw domain_error("Neispravna ocjena");
  38. if(ocjena == 5) return;
  39.  
  40. prosjek = (prosjek*broj_polozenih+ocjena)/(broj_polozenih+1);
  41. broj_polozenih++;
  42. }
  43.  
  44. void ApstraktniStudent::PonistiOcjene() {
  45.  
  46. broj_polozenih = 0;
  47. prosjek = 5;
  48. }
  49.  
  50.  
  51. class StudentBachelor : public ApstraktniStudent {
  52.  
  53. public:
  54. StudentBachelor(string ime, string prezime, int broj_indeksa, int broj_polozenih=0, double prosjek=5) : ApstraktniStudent(ime, prezime, broj_indeksa) {}
  55.  
  56. void IspisiPodatke() const;
  57. ApstraktniStudent* DajKopiju() const { return new StudentBachelor(*this); }
  58. };
  59.  
  60. void StudentBachelor::IspisiPodatke() const {
  61.  
  62. cout << "Student bachelor studija " << ime << " " << prezime << ", sa brojem indeksa " << broj_indeksa << "," << endl <<
  63. "ima prosjek " << prosjek << "." << endl;
  64. }
  65.  
  66.  
  67. class StudentMaster : public ApstraktniStudent {
  68.  
  69. int godina;
  70.  
  71. public:
  72. StudentMaster(string ime, string prezime, int broj_indeksa, int godina, int broj_polozenih=0, double prosjek=5) : ApstraktniStudent(ime, prezime, broj_indeksa), godina(godina) {}
  73. void IspisiPodatke() const;
  74. ApstraktniStudent* DajKopiju() const { return new StudentMaster(*this); }
  75.  
  76. };
  77.  
  78. void StudentMaster::IspisiPodatke() const {
  79.  
  80. cout << "Student master studija " << ime << " " << prezime << ", sa brojem indeksa " << broj_indeksa << "," << endl
  81. << "zavrsio bachelor studij godine " << godina << ",ima prosjek " << prosjek << "." << endl;
  82. }
  83.  
  84.  
  85. int main ()
  86. {
  87.  
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement