#pragma once
class Pojazd
{
const int nrVIN;
char* nazwa;
public:
Pojazd(const char* naz, int nr);
virtual ~Pojazd();
Pojazd(const Pojazd &p);
Pojazd & operator=(const Pojazd &p);
virtual void Wypisz(); //czysto wirtualna
const char* Nazwa()const;
int NrVIN()const;
};
#include "pch.h"
#include "Pojazd.h"
#include <string.h>
using namespace std;
Pojazd::Pojazd(const char* naz, int nr):nrVIN(nr)
{
nazwa = new char[strlen(naz)+1];
strcpy(nazwa,naz);// (gdzie ma skopiowac,skad ma skopiowac)
}
Pojazd::~Pojazd()
{
delete[] nazwa;
}
Pojazd::Pojazd(const Pojazd &p):nrVIN(p.nrVIN)
{
nazwa = new char[strlen(p.nazwa) + 1];
strcpy(nazwa, p.nazwa);
}
Pojazd & Pojazd::operator=(const Pojazd &p)
{
if (this != &p)
{
if (this->nazwa != NULL) delete this->nazwa; //zwalnianie pamieci jesli juz mielismy jakas nazwa do tego obiketu do ktorego przypisuje
nazwa = new char[strlen(p.nazwa) + 1];
strcpy(nazwa, p.nazwa);
}
return *this;
}
void Pojazd::Wypisz() //czysto wirtualna metoda wiec zostawiamy
{
}
const char* Pojazd::Nazwa()const
{
return this->nazwa;
}
int Pojazd::NrVIN()const
{
return this->nrVIN;
}
#pragma once
#include "Pojazd.h"
class Samochod : protected Pojazd
{
protected:
char* nrRejestr;
public:
Samochod(const char* nrRej, const char* nazwa, int nVIN);
~Samochod();
Samochod(const Samochod &wzor);
Samochod & operator=(const Samochod &wzor);
void Wypisz();
};
#include "pch.h"
#include "Samochod.h"
#include <iostream>
#include <string.h>
using namespace std;
Samochod::Samochod(const char* nrRej, const char* nazwa, int nVIN):Pojazd(nazwa,nVIN)
{
nrRejestr = new char[strlen(nrRej) + 1];
strcpy(nrRejestr, nrRej);
}
Samochod::~Samochod()
{
delete[] nrRejestr;
}
Samochod::Samochod(const Samochod &wzor) :Pojazd(wzor.Nazwa(), wzor.NrVIN())
{
nrRejestr = new char[strlen(wzor.nrRejestr) + 1];
strcpy(nrRejestr, wzor.nrRejestr);
}
Samochod & Samochod::operator=(const Samochod &wzor)
{
if (this != &wzor)
{
(Pojazd)(*this) = (Pojazd)(wzor); //uzycie operatora przypisania dla klasy poprawwic
if (this->nrRejestr != NULL) delete[] nrRejestr;
nrRejestr = new char[strlen(wzor.nrRejestr) + 1];
strcpy(nrRejestr, wzor.nrRejestr);
}
return *this;
}
void Samochod::Wypisz()
{
cout << this->Nazwa() << "\t" << this->NrVIN() << "\t" << nrRejestr;
}
#include "pch.h"
#include <iostream>
#include "Samochod.h"
int main()
{
Samochod a("rej1", "naz1", 1);
Samochod b("rej2", "naz2", 2);
Samochod c("rej3", "naz3", 3);
Samochod d(b);
Samochod e("nic", "nic", 0);
e = a = c;
a.Wypisz();
std::cout << std::endl;
b.Wypisz();
std::cout << std::endl;
c.Wypisz();
std::cout << std::endl;
d.Wypisz();
std::cout << std::endl;
e.Wypisz();
return 0;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}