Advertisement
neogz

Nasljedjivanje LT YT

Feb 5th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.29 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Ucesnik{
  5.     int _id;
  6.     char * _imePrezime;
  7.     char * _datumPrijave;
  8. public:
  9.     Ucesnik(int id = 0, char * imePrezime = "----- -----", char * datumPrijave = "--/--/--"){
  10.         _id             = id;
  11.  
  12.         int vel         = strlen(imePrezime) + 1;
  13.         _imePrezime     = new char[vel];
  14.         strcpy_s        (_imePrezime, vel, imePrezime);
  15.  
  16.         vel             = strlen(datumPrijave)+1;
  17.         _datumPrijave   = new char[vel];
  18.         strcpy_s        (_datumPrijave, vel, datumPrijave);
  19.     }
  20.     Ucesnik(const Ucesnik & obj){
  21.         _id = obj._id;
  22.  
  23.         int vel = strlen(obj._imePrezime) + 1;
  24.         _imePrezime = new char[vel];
  25.         strcpy_s(_imePrezime, vel, obj._imePrezime);
  26.  
  27.         vel = strlen(obj._datumPrijave) + 1;
  28.         _datumPrijave = new char[vel];
  29.         strcpy_s(_datumPrijave, vel, obj._datumPrijave);
  30.     }
  31.     ~Ucesnik(){
  32.         delete[]_imePrezime;
  33.         delete[]_datumPrijave;
  34.         _imePrezime = nullptr;
  35.         _datumPrijave = nullptr;
  36.     }
  37.     ////////////////////////////////////////////////////////
  38.     void info(){
  39.         cout << "------------------------------------\n" << _id << " " << _imePrezime << " " << _datumPrijave << endl;
  40.    
  41.     }
  42.     bool operator == (const Ucesnik & obj){
  43.         if      (this == &obj) return true;
  44.         else if (_id == obj._id && strcmp(_imePrezime, obj._imePrezime) == 0) return true;
  45.         else    return false;
  46.     }
  47.     Ucesnik & operator = (Ucesnik & obj){
  48.         _id = obj._id;
  49.  
  50.         delete[] _imePrezime;
  51.         int vel = strlen(obj._imePrezime) + 1;
  52.         _imePrezime = new char[vel];
  53.         strcpy_s(_imePrezime, vel, obj._imePrezime);
  54.  
  55.         delete[]_datumPrijave;
  56.         vel = strlen(obj._datumPrijave) + 1;
  57.         _datumPrijave = new char[vel];
  58.         strcpy_s(_datumPrijave, vel, obj._datumPrijave);
  59.         return *this;
  60.     }
  61.     friend ostream & operator << (ostream & COUT, Ucesnik & obj);
  62. };
  63. ostream & operator << (ostream & COUT, Ucesnik & obj){
  64.     COUT << obj._id << " " << obj._imePrezime << " " << obj._datumPrijave << endl;
  65.     return COUT;
  66. }
  67. ////////////////
  68. ////////////////
  69. ////////////////
  70. ////////////////
  71. class  Predavac  :  public Ucesnik {
  72.     char  * _institucija;
  73.     char * _oblast;
  74.     int _godineIskustva;
  75. public:
  76.     Predavac(){
  77.         _institucija = nullptr;
  78.         _oblast = nullptr;
  79.         _godineIskustva = 0;
  80.     }
  81.     Predavac(int id = 0, char * imePrezime = "----- -----", char * datumPrijave = "--/--/--", char * institucija = "----" , char * oblast =  "------", int godineIskustva=0) :Ucesnik(id,imePrezime,datumPrijave){
  82.        
  83.         int vel = strlen(institucija) + 1;
  84.         _institucija = new char[vel];
  85.         strcpy_s(_institucija, vel, institucija);
  86.  
  87.         vel = strlen(oblast) + 1;
  88.         _oblast = new char[vel];
  89.         strcpy_s(_oblast, vel, oblast);
  90.  
  91.         _godineIskustva = godineIskustva;
  92.     }
  93.     Predavac(Predavac & obj):Ucesnik(obj){
  94.         int vel = strlen(obj._institucija) + 1;
  95.         _institucija = new char[vel];
  96.         strcpy_s(_institucija, vel, obj._institucija);
  97.  
  98.         vel = strlen(obj._oblast) + 1;
  99.         _oblast = new char[vel];
  100.         strcpy_s(_oblast, vel, obj._oblast);
  101.  
  102.         _godineIskustva = obj._godineIskustva;
  103.     }
  104.     ~Predavac(){
  105.         delete[]_institucija;
  106.         delete[]_oblast;
  107.         _institucija = nullptr;
  108.         _oblast = nullptr;
  109.     }
  110.     void info(){
  111.         Ucesnik::info();
  112.         cout << "Instucija: " << _institucija << endl;
  113.         cout << "Oblast: " << _oblast << endl;
  114.         cout << "Godine iskustva: " << _godineIskustva << endl;
  115.     }
  116.     Predavac & operator = (const Predavac & obj){
  117.         if (this != &obj){
  118.             Ucesnik::operator=((Ucesnik)obj);
  119.  
  120.             delete[]_institucija;
  121.             int vel = strlen(obj._institucija) + 1;
  122.             _institucija = new char[vel];
  123.             strcpy_s(_institucija, vel, obj._institucija);
  124.  
  125.             delete[]_oblast;
  126.             vel = strlen(obj._oblast) + 1;
  127.             _oblast = new char[vel];
  128.             strcpy_s(_oblast, vel, obj._oblast);
  129.  
  130.             _godineIskustva = obj._godineIskustva;
  131.         }
  132.         return *this;
  133.     }
  134.     friend ostream & operator <<(ostream & COUT, const Predavac & obj);
  135. };
  136. ostream & operator <<(ostream & COUT, const Predavac & obj){
  137.  
  138.     cout << (Ucesnik)obj;
  139.     cout << "Instucija: " << obj._institucija << endl;
  140.     cout << "Oblast: " << obj._oblast << endl;
  141.     cout << "Godine iskustva: " << obj._godineIskustva << endl;
  142.  
  143.     return COUT;
  144. }
  145. //////////////////////////////////////////////////////////////
  146. int main(){
  147.     Predavac p1(1, "Denis Music", "09/04/1994", "FIT", "Informatika", 10);
  148.     Predavac p2(2,"Nedim Fejzic", "10/04/1995","FIT","Informatika",0);
  149.    
  150.     Predavac p3 = p2;
  151.     p1 = p3;
  152.     //p1.info();
  153.  
  154.  
  155.     cout << p1 << p2;
  156.     system("pause > null");
  157.     return 0;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement