Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Ucesnik{
- int _id;
- char * _imePrezime;
- char * _datumPrijave;
- public:
- Ucesnik(int id = 0, char * imePrezime = "----- -----", char * datumPrijave = "--/--/--"){
- _id = id;
- int vel = strlen(imePrezime) + 1;
- _imePrezime = new char[vel];
- strcpy_s (_imePrezime, vel, imePrezime);
- vel = strlen(datumPrijave)+1;
- _datumPrijave = new char[vel];
- strcpy_s (_datumPrijave, vel, datumPrijave);
- }
- Ucesnik(const Ucesnik & obj){
- _id = obj._id;
- int vel = strlen(obj._imePrezime) + 1;
- _imePrezime = new char[vel];
- strcpy_s(_imePrezime, vel, obj._imePrezime);
- vel = strlen(obj._datumPrijave) + 1;
- _datumPrijave = new char[vel];
- strcpy_s(_datumPrijave, vel, obj._datumPrijave);
- }
- ~Ucesnik(){
- delete[]_imePrezime;
- delete[]_datumPrijave;
- _imePrezime = nullptr;
- _datumPrijave = nullptr;
- }
- ////////////////////////////////////////////////////////
- void info(){
- cout << "------------------------------------\n" << _id << " " << _imePrezime << " " << _datumPrijave << endl;
- }
- bool operator == (const Ucesnik & obj){
- if (this == &obj) return true;
- else if (_id == obj._id && strcmp(_imePrezime, obj._imePrezime) == 0) return true;
- else return false;
- }
- Ucesnik & operator = (Ucesnik & obj){
- _id = obj._id;
- delete[] _imePrezime;
- int vel = strlen(obj._imePrezime) + 1;
- _imePrezime = new char[vel];
- strcpy_s(_imePrezime, vel, obj._imePrezime);
- delete[]_datumPrijave;
- vel = strlen(obj._datumPrijave) + 1;
- _datumPrijave = new char[vel];
- strcpy_s(_datumPrijave, vel, obj._datumPrijave);
- return *this;
- }
- friend ostream & operator << (ostream & COUT, Ucesnik & obj);
- };
- ostream & operator << (ostream & COUT, Ucesnik & obj){
- COUT << obj._id << " " << obj._imePrezime << " " << obj._datumPrijave << endl;
- return COUT;
- }
- ////////////////
- ////////////////
- ////////////////
- ////////////////
- class Predavac : public Ucesnik {
- char * _institucija;
- char * _oblast;
- int _godineIskustva;
- public:
- Predavac(){
- _institucija = nullptr;
- _oblast = nullptr;
- _godineIskustva = 0;
- }
- Predavac(int id = 0, char * imePrezime = "----- -----", char * datumPrijave = "--/--/--", char * institucija = "----" , char * oblast = "------", int godineIskustva=0) :Ucesnik(id,imePrezime,datumPrijave){
- int vel = strlen(institucija) + 1;
- _institucija = new char[vel];
- strcpy_s(_institucija, vel, institucija);
- vel = strlen(oblast) + 1;
- _oblast = new char[vel];
- strcpy_s(_oblast, vel, oblast);
- _godineIskustva = godineIskustva;
- }
- Predavac(Predavac & obj):Ucesnik(obj){
- int vel = strlen(obj._institucija) + 1;
- _institucija = new char[vel];
- strcpy_s(_institucija, vel, obj._institucija);
- vel = strlen(obj._oblast) + 1;
- _oblast = new char[vel];
- strcpy_s(_oblast, vel, obj._oblast);
- _godineIskustva = obj._godineIskustva;
- }
- ~Predavac(){
- delete[]_institucija;
- delete[]_oblast;
- _institucija = nullptr;
- _oblast = nullptr;
- }
- void info(){
- Ucesnik::info();
- cout << "Instucija: " << _institucija << endl;
- cout << "Oblast: " << _oblast << endl;
- cout << "Godine iskustva: " << _godineIskustva << endl;
- }
- Predavac & operator = (const Predavac & obj){
- if (this != &obj){
- Ucesnik::operator=((Ucesnik)obj);
- delete[]_institucija;
- int vel = strlen(obj._institucija) + 1;
- _institucija = new char[vel];
- strcpy_s(_institucija, vel, obj._institucija);
- delete[]_oblast;
- vel = strlen(obj._oblast) + 1;
- _oblast = new char[vel];
- strcpy_s(_oblast, vel, obj._oblast);
- _godineIskustva = obj._godineIskustva;
- }
- return *this;
- }
- friend ostream & operator <<(ostream & COUT, const Predavac & obj);
- };
- ostream & operator <<(ostream & COUT, const Predavac & obj){
- cout << (Ucesnik)obj;
- cout << "Instucija: " << obj._institucija << endl;
- cout << "Oblast: " << obj._oblast << endl;
- cout << "Godine iskustva: " << obj._godineIskustva << endl;
- return COUT;
- }
- //////////////////////////////////////////////////////////////
- int main(){
- Predavac p1(1, "Denis Music", "09/04/1994", "FIT", "Informatika", 10);
- Predavac p2(2,"Nedim Fejzic", "10/04/1995","FIT","Informatika",0);
- Predavac p3 = p2;
- p1 = p3;
- //p1.info();
- cout << p1 << p2;
- system("pause > null");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement