Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //formitaj klasu
- //prvi konstruktor -argumenti su dva stringa (argumenti tipa char)
- //drugi konstruktor - argumenti su dva stringa (reference)
- //treci konstruktor, konstruktor kopije
- //spreciti curenje memorije - destruktor
- //sobaslobodna funkcija void predstavi se
- #ifndef OSOBA_DEF
- #define OSOBA_DEF
- #include "dinstring.hpp"
- #include <iostream>
- using namespace std;
- class Osoba{
- private:
- DinString ime, prezime;
- public:
- //da li se stringovi se u ovom konstruktoru inicijalizuju sa ="" ?
- Osoba(const char *s1="", const char *s2=""): ime(s1), prezime(s2) {}
- Osoba(const DinString &ds1, const DinString &ds2): ime(ds1), prezime(ds2) {}
- Osoba(const Osoba &os): ime(os.ime), prezime(os.prezime) {}
- ~Osoba() {}
- //ugradjeni destruktor brise samo objekte, ne oslobadja alociranu memoriju?! sha sad?
- //ali se memorija oslobadja u klasi DinString
- //slobodna funkcija koja je slicna void printResult
- void predstaviSe() {cout<<"Zovem se "<<ime<<" "<<prezime<<". "<<endl;}
- };
- #endif
- //iz klase osoba(ime,prezime) izvesti klasu student(ime,prezime,broj indexa), a iz klase student izvesti
- //klasu phd student(ime,prezime,broj indexa, prosecna ocena)
- //iskoristiti klasu dinstring iz prethodog zadatka
- #ifndef STUDENT_DEF
- #define STUDENT_DEF
- #include "osoba.hpp"
- class Student: public Osoba {
- protected:
- int brIndexa;
- public:
- Student(const char *s1="",const char *s2="", int i=0): Osoba(s1,s2), brIndexa(i)
- {
- }
- Student(const DinString &ds1, const DinString &ds2, int i): Osoba(ds1,ds2), brIndexa(i)
- {
- }
- Student(const Osoba &os, int i): Osoba(os), brIndexa(i)
- {
- }
- Student(const Student &st): Osoba((Osoba)st), brIndexa(st.brIndexa)
- {
- }
- ~Student() {}
- void predstaviSe() {
- Osoba:: predstaviSe();
- cout<<"Broj indexa: "<<brIndexa<<endl;
- }
- };
- #endif
- #ifndef PHD_DEFINE
- #define PHD_DEFINE
- #include "student.hpp"
- class Phd: public Student{
- protected:
- double prosek;
- public:
- Phd(const char *s1,const char *s2, int i=0, double po=0): Student(s1,s2,i), prosek(po)
- {}
- Phd(const DinString &ds1, const DinString &ds2, int i,double po): Student(ds1,ds2,i), prosek(po)
- {}
- Phd(const Osoba &os, int i, double po): Student(os,i), prosek(po)
- {}
- Phd(const Student &st, double po): Student(Student(st)), prosek(po)
- {}
- Phd(const Phd &phd): Student((Student)phd), prosek(phd.prosek)
- {}
- ~Phd() {}
- void predstaviSe(){
- Student:: predstaviSe();
- cout<<"Prosecna ocena: "<<prosek<<endl;
- }
- };
- #endif
- #ifndef PLATA_DEF
- #define PLATA_DEF
- #include "phdstudent.hpp"
- class Plata: public Phd{
- protected:
- double plata;
- public:
- Plata(const char *s1,const char *s2, int i=0, double po=0, double pl=0): Phd(s1,s2,i,po), plata(pl)
- {}
- Plata(const DinString &ds1, const DinString &ds2, int i,double po, double pl): Phd(ds1,ds2,i,po), plata(pl)
- {}
- Plata(const Osoba &os, int i, double po, double pl): Phd(os,i,po), plata(pl)
- {}
- Plata(const Phd &p, double po, double pl): Phd(Phd(p)), plata(pl)
- {}
- Plata(const Plata &pl): Phd((Phd)pl), plata(pl.plata)
- {
- }
- void predstaviSe(){
- Phd:: predstaviSe();
- cout<< "Moja plata iznosi: "<< plata<<endl;
- }
- };
- #endif
- //iz klase osoba(ime,prezime) izvesti klasu student(ime,prezime,broj indexa), a iz klase student izvesti
- //klasu phd student(ime,prezime,broj indexa, prosecna ocena)
- //iskoristiti klasu dinstring iz prethodog zadatka
- #include "plata.hpp"
- int main(){
- const char *s1 = "Branislav";
- const char *s2 = "Nikolic";
- const char *s3 = "Jelena";
- const char *s4 = "Ivanovic";
- DinString ds1(s1), ds2(s2), ds3(s3), ds4(s4); //(text)
- Osoba osoba1(s1,s2), osoba2(s3,s4); //(ime,prezime)
- Student st1(osoba1, 13592), st2(ds3,ds4, 13582), st3(s3,s4, 13589); // -||- + index)
- Phd ph1(osoba1, 13592, 9.44), ph2(ds3,ds4,13582, 9.63), ph3(s3,s4,13589, 9.61); //-||- +prosek
- Plata plata1(osoba1, 13592, 9.44, 45000), plata2(ds3,ds4,13582,9.63, 65000);
- osoba1.predstaviSe();
- osoba2.predstaviSe();
- st1.predstaviSe();
- st2.predstaviSe();
- ph2.predstaviSe();
- ph1.predstaviSe();
- plata1.predstaviSe();
- plata2.predstaviSe();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement