Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class VestackoCveke{
- protected:
- char ime[50];
- int cena;
- char boja[100];
- public:
- VestackoCveke(){}
- VestackoCveke(char ime[],int cena, char boja[]){
- strcpy(this->ime, ime);
- this->cena = cena;
- strcpy(this->boja, boja);
- }
- void setIme(char ime[]){
- strcpy(this->ime,ime);
- }
- char *getIme(){
- return ime;
- }
- void setCena(int cena){
- this->cena = cena;
- }
- int getCena(){
- return cena;
- }
- void setBoja(char boja[]){
- strcpy(this->boja, boja);
- }
- char *getBoja(){
- return boja;
- }
- virtual float vratiCena()=0;
- bool operator!=(VestackoCveke &vc){
- return strcmp(boja,vc.boja)!=0;
- }
- ~VestackoCveke(){}
- };
- class SoSaksija : public VestackoCveke{
- private:
- float masa;
- public:
- SoSaksija(){}
- SoSaksija(char ime[],int cena, char boja[], float masa) : VestackoCveke(ime, cena, boja){
- this->masa = masa;
- }
- void setMasa(float masa){
- this->masa = masa;
- }
- float getMasa(){
- return masa;
- }
- float vratiCena(){
- return (float)cena+(masa*0.3);
- }
- ~SoSaksija(){}
- };
- class BezSaksija : public VestackoCveke{
- private:
- bool cvet;
- public:
- BezSaksija(){}
- BezSaksija(char ime[],int cena, char boja[], bool cvet) : VestackoCveke(ime, cena, boja){
- this->cvet = cvet;
- }
- void setCvet(bool cvet){
- this->cvet = cvet;
- }
- bool getCvet(){
- return cvet;
- }
- float vratiCena(){
- if(cvet) return cena+50;
- return cena;
- }
- ~BezSaksija(){}
- };
- void pecatiMinCena(VestackoCveke **vc,int n,SoSaksija &novo){
- int min=9999;
- int index;
- for(int i=0;i<n;i++){
- if(*vc[i]!=novo){
- int c=vc[i]->vratiCena();
- if(c<min){
- min=c;
- index=i;
- }
- }
- }
- cout<<vc[index]->getIme()<<" "<<vc[index]->getBoja()<<" "<<vc[index]->vratiCena()<<endl;
- }
- int main(){
- char ime[20],boja[10];
- int tip,cena;
- float masa;
- bool cvet;
- int n;
- cin>>n;
- VestackoCveke **cvekinja;
- cvekinja=new VestackoCveke *[n];
- for (int i=0;i<n;i++){
- cin>>tip>>ime>>cena>>boja;
- if (tip==1) {
- cin>>masa;
- cvekinja[i]=new SoSaksija(ime,cena,boja,masa);
- }
- else {
- cin>>cvet;
- cvekinja[i]=new BezSaksija(ime,cena,boja,cvet);
- }
- }
- SoSaksija novo("ljubicici",45,"crvena",10.5);
- pecatiMinCena(cvekinja,n,novo);
- for (int i=0;i<n;i++) delete cvekinja[i];
- delete [] cvekinja;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement