Advertisement
nex036ara

phdStudent

Apr 18th, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.57 KB | None | 0 0
  1.  
  2. //formitaj klasu
  3. //prvi konstruktor -argumenti su dva stringa (argumenti tipa char)
  4. //drugi konstruktor - argumenti su dva stringa (reference)
  5. //treci konstruktor, konstruktor kopije
  6. //spreciti curenje memorije - destruktor
  7. //sobaslobodna funkcija void predstavi se
  8.  
  9. #ifndef OSOBA_DEF
  10. #define OSOBA_DEF
  11. #include "dinstring.hpp"
  12. #include <iostream>
  13. using namespace std;
  14.  
  15. class Osoba{
  16.     private:
  17.     DinString ime, prezime;
  18.  
  19.     public:
  20.         //da li se stringovi se u ovom konstruktoru inicijalizuju sa  ="" ?
  21.         Osoba(const char *s1="", const char *s2=""): ime(s1), prezime(s2) {}
  22.         Osoba(const DinString &ds1, const DinString &ds2): ime(ds1), prezime(ds2) {}
  23.         Osoba(const Osoba &os): ime(os.ime), prezime(os.prezime) {}
  24.         ~Osoba() {}
  25.         //ugradjeni destruktor brise samo objekte, ne oslobadja alociranu memoriju?! sha sad?
  26.         //ali se memorija oslobadja u klasi DinString
  27.  
  28.         //slobodna funkcija koja je slicna void printResult
  29.         void predstaviSe() {cout<<"Zovem se "<<ime<<" "<<prezime<<". "<<endl;}
  30.  
  31.  
  32. };
  33. #endif
  34.  
  35.  
  36.  
  37. //iz klase osoba(ime,prezime) izvesti klasu student(ime,prezime,broj indexa), a iz klase student izvesti
  38. //klasu phd student(ime,prezime,broj indexa, prosecna ocena)
  39. //iskoristiti klasu dinstring iz prethodog zadatka
  40.  
  41. #ifndef STUDENT_DEF
  42. #define STUDENT_DEF
  43. #include "osoba.hpp"
  44.  
  45. class Student: public Osoba {
  46.  
  47.     protected:
  48.         int brIndexa;
  49.     public:
  50.         Student(const char *s1="",const char *s2="", int i=0): Osoba(s1,s2), brIndexa(i)
  51.         {
  52.  
  53.         }
  54.         Student(const DinString &ds1, const DinString &ds2, int i): Osoba(ds1,ds2), brIndexa(i)
  55.         {
  56.  
  57.         }
  58.         Student(const Osoba &os, int i): Osoba(os), brIndexa(i)
  59.         {
  60.  
  61.         }
  62.         Student(const Student &st): Osoba((Osoba)st), brIndexa(st.brIndexa)
  63.         {
  64.  
  65.             }
  66.         ~Student() {}
  67.         void predstaviSe() {
  68.         Osoba:: predstaviSe();
  69.         cout<<"Broj indexa: "<<brIndexa<<endl;
  70.         }
  71. };
  72. #endif
  73.  
  74.  
  75.  
  76.  
  77. #ifndef PHD_DEFINE
  78. #define PHD_DEFINE
  79. #include "student.hpp"
  80.  
  81.  
  82. class Phd: public Student{
  83.     protected:
  84.         double prosek;
  85.     public:
  86.         Phd(const char *s1,const char *s2, int i=0, double po=0): Student(s1,s2,i), prosek(po)
  87.         {}
  88.  
  89.         Phd(const DinString &ds1, const DinString &ds2, int i,double po): Student(ds1,ds2,i), prosek(po)
  90.          {}
  91.  
  92.         Phd(const Osoba &os, int i, double po): Student(os,i), prosek(po)
  93.         {}
  94.  
  95.         Phd(const Student &st, double po): Student(Student(st)), prosek(po)
  96.         {}
  97.  
  98.         Phd(const Phd &phd): Student((Student)phd), prosek(phd.prosek)
  99.         {}
  100.  
  101.  
  102.         ~Phd() {}
  103.  
  104.         void predstaviSe(){
  105.         Student:: predstaviSe();
  106.         cout<<"Prosecna ocena: "<<prosek<<endl;
  107.         }
  108.     };
  109. #endif
  110.  
  111.  
  112. #ifndef PLATA_DEF
  113. #define PLATA_DEF
  114. #include "phdstudent.hpp"
  115.  
  116. class Plata: public Phd{
  117.     protected:
  118.         double plata;
  119.     public:
  120.  
  121.     Plata(const char *s1,const char *s2, int i=0, double po=0, double pl=0): Phd(s1,s2,i,po), plata(pl)
  122.         {}
  123.  
  124.         Plata(const DinString &ds1, const DinString &ds2, int i,double po, double pl): Phd(ds1,ds2,i,po), plata(pl)
  125.          {}
  126.  
  127.         Plata(const Osoba &os, int i, double po, double pl): Phd(os,i,po), plata(pl)
  128.         {}
  129.  
  130.         Plata(const Phd &p, double po, double pl): Phd(Phd(p)), plata(pl)
  131.         {}
  132.         Plata(const Plata &pl): Phd((Phd)pl), plata(pl.plata)
  133.         {
  134.         }
  135.  
  136. void predstaviSe(){
  137.     Phd:: predstaviSe();
  138.     cout<< "Moja plata iznosi: "<< plata<<endl;
  139.         }
  140. };
  141. #endif
  142.  
  143. //iz klase osoba(ime,prezime) izvesti klasu student(ime,prezime,broj indexa), a iz klase student izvesti
  144. //klasu phd student(ime,prezime,broj indexa, prosecna ocena)
  145. //iskoristiti klasu dinstring iz prethodog zadatka
  146.  
  147. #include "plata.hpp"
  148.  
  149. int main(){
  150.     const char *s1 = "Branislav";
  151.     const char *s2 = "Nikolic";
  152.     const char *s3 = "Jelena";
  153.     const char *s4 = "Ivanovic";
  154.  
  155.     DinString ds1(s1), ds2(s2), ds3(s3), ds4(s4); //(text)
  156.     Osoba osoba1(s1,s2), osoba2(s3,s4); //(ime,prezime)
  157.     Student st1(osoba1, 13592), st2(ds3,ds4, 13582), st3(s3,s4, 13589); // -||- + index)
  158.     Phd ph1(osoba1, 13592, 9.44), ph2(ds3,ds4,13582, 9.63), ph3(s3,s4,13589, 9.61); //-||- +prosek
  159.     Plata plata1(osoba1, 13592, 9.44, 45000), plata2(ds3,ds4,13582,9.63, 65000);
  160.  
  161.     osoba1.predstaviSe();
  162.     osoba2.predstaviSe();
  163.     st1.predstaviSe();
  164.     st2.predstaviSe();
  165.     ph2.predstaviSe();
  166.     ph1.predstaviSe();
  167.     plata1.predstaviSe();
  168.     plata2.predstaviSe();
  169.  
  170.  
  171. return 0;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement