Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*TP 16/17 (Tutorijal 13, Zadatak 2)*/
- #include <iostream>
- #include <string>
- #include <stdexcept>
- #include <vector>
- #include <memory>
- using namespace std;
- class ApstraktniStudent {
- protected:
- string ime, prezime;
- int broj_indeksa;
- int broj_polozenih;
- double prosjek;
- public:
- ApstraktniStudent(string ime, string prezime, int broj_indeksa) : ime(ime), prezime(prezime), broj_indeksa(broj_indeksa), broj_polozenih(0), prosjek(5) {}
- string DajIme() const { return ime; }
- string DajPrezime() const { return prezime; }
- int DajBrojIndeksa() const { return broj_indeksa; }
- int DajBrojPolozenih() const { return broj_polozenih; }
- double DajProsjek() const { return prosjek; }
- void RegistrirajIspit(int ocjena);
- void PonistiOcjene();
- virtual ~ApstraktniStudent() {}
- virtual void IspisiPodatke() const =0;
- virtual ApstraktniStudent* DajKopiju() const =0;
- };
- void ApstraktniStudent::RegistrirajIspit(int ocjena) {
- if(ocjena < 5 || ocjena > 10) throw domain_error("Neispravna ocjena");
- if(ocjena == 5) return;
- prosjek = (prosjek*broj_polozenih+ocjena)/(broj_polozenih+1);
- broj_polozenih++;
- }
- void ApstraktniStudent::PonistiOcjene() {
- broj_polozenih = 0;
- prosjek = 5;
- }
- class StudentBachelor : public ApstraktniStudent {
- public:
- StudentBachelor(string ime, string prezime, int broj_indeksa, int broj_polozenih=0, double prosjek=5) : ApstraktniStudent(ime, prezime, broj_indeksa) {}
- void IspisiPodatke() const;
- ApstraktniStudent* DajKopiju() const { return new StudentBachelor(*this); }
- };
- void StudentBachelor::IspisiPodatke() const {
- cout << "Student bachelor studija " << ime << " " << prezime << ", sa brojem indeksa " << broj_indeksa << "," << endl <<
- "ima prosjek " << prosjek << "." << endl;
- }
- class StudentMaster : public ApstraktniStudent {
- int godina;
- public:
- StudentMaster(string ime, string prezime, int broj_indeksa, int godina, int broj_polozenih=0, double prosjek=5) : ApstraktniStudent(ime, prezime, broj_indeksa), godina(godina) {}
- void IspisiPodatke() const;
- ApstraktniStudent* DajKopiju() const { return new StudentMaster(*this); }
- };
- void StudentMaster::IspisiPodatke() const {
- cout << "Student master studija " << ime << " " << prezime << ", sa brojem indeksa " << broj_indeksa << "," << endl
- << "zavrsio bachelor studij godine " << godina << ",ima prosjek " << prosjek << "." << endl;
- }
- int main ()
- {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement