Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Predmet {
- protected:
- char *sopstvenik;
- char ime[100];
- int cena;
- public:
- Predmet(char *sopstvenik="",char *ime="",int cena=0) {
- this->sopstvenik=new char[strlen(sopstvenik)];
- strcpy(this->sopstvenik,sopstvenik);
- strcpy(this->ime,ime);
- this->cena=cena;
- }
- virtual ~Predmet() {
- delete []sopstvenik;
- }
- Predmet(Predmet& obj) {
- sopstvenik=new char[strlen(obj.sopstvenik)];
- strcpy(sopstvenik,obj.sopstvenik);
- strcpy(ime,obj.ime);
- cena=obj.cena;
- }
- Predmet& operator=(Predmet& obj) {
- if (this==&obj)
- return *this;
- delete []sopstvenik;
- sopstvenik=new char[strlen(obj.sopstvenik)];
- strcpy(sopstvenik,obj.sopstvenik);
- strcpy(ime,obj.ime);
- cena=obj.cena;
- return *this;
- }
- int getCena() {
- return cena;
- }
- friend ostream& operator<<(ostream& co,Predmet& obj) {
- return co<<obj.sopstvenik<<"#"<<obj.ime<<"#"<<obj.cena<<endl;
- }
- virtual double prodazna_cena()=0;
- };
- class TehnichkiPredmet:public Predmet {
- private:
- bool garancija;
- public:
- TehnichkiPredmet(char *sopstvenik="",char *ime="",int cena=0, bool garancija=true):Predmet(sopstvenik,ime,cena) {
- this->garancija=garancija;
- }
- double prodazna_cena() {
- if (garancija==true) {
- return 1000.0+cena;
- } else {
- return 0.2*1000+cena;
- }
- }
- };
- class ObichenPredmet:public Predmet {
- private:
- double masa;
- public:
- ObichenPredmet(char *sopstvenik="",char *ime="",int cena=0, double masa=0):Predmet(sopstvenik,ime,cena) {
- this->masa=masa;
- }
- double prodazna_cena() {
- return masa*500+cena*2;
- }
- };
- class Rasprodazhba {
- private:
- Predmet **p;
- int elem;
- public:
- Rasprodazhba(Predmet **p=NULL,int elem=0) {
- this->p=new Predmet*[elem];
- for (int i=0; i<elem; i++)
- this->p[i]=p[i];
- this->elem=elem;
- }
- ~Rasprodazhba() {
- delete []p;
- }
- void dodadiPredmet(Predmet *p) {
- Predmet **tmp=new Predmet*[elem+1];
- for (int i=0; i<elem; i++)
- tmp[i]=this->p[i];
- tmp[elem]=p;
- elem++;
- delete []this->p;
- this->p=tmp;
- }
- Predmet& vratiNajevtinPredmet() {
- Predmet *tmp=p[0];
- for (int i=0; i<elem; i++)
- if (tmp->getCena()>p[i]->getCena())
- tmp=p[i];
- return *tmp;
- }
- };
- int main() {
- Rasprodazhba r;
- char sopstvenik[100],ime[100];
- bool garancija;
- int kupen,masa;
- int n;
- cin>>n;
- for (int i=0; i<n; i++) {
- int tip;
- cin>>tip;
- if (tip==0) {
- cin>>sopstvenik>>ime>>kupen>>garancija;
- r.dodadiPredmet(new TehnichkiPredmet(sopstvenik, ime, kupen, garancija));
- } else {
- cin>>sopstvenik>>ime>>kupen>>masa;
- r.dodadiPredmet(new ObichenPredmet(sopstvenik, ime, kupen, masa));
- }
- }
- cout<<r.vratiNajevtinPredmet();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment