Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class UmetnickoDelo {
- protected:
- int godina;
- char *avtor;
- float cena;
- public:
- UmetnickoDelo(char *avtor, int godina, float cena) {
- try {
- if(cena<0) throw 1;
- this->avtor = new char [strlen(avtor) + 1];
- strcpy(this->avtor, avtor);
- this->godina=godina;
- } catch(int) {
- cout<<"Cenata ne smee da bide negativna. Faten e isklucok"<<endl;
- this->cena=0;
- }
- }
- virtual float cenaDelo()=0;
- friend ostream& operator<< (ostream& o, UmetnickoDelo& ud) {
- o<<"Avtor: "<<ud.avtor<<" godina: "<<ud.godina<<" cena: "<<ud.cenaDelo()<<endl;
- return o;
- }
- UmetnickoDelo(const UmetnickoDelo& other) {
- this->avtor = new char[strlen(other.avtor) + 1];
- strcpy(avtor, other.avtor);
- godina = other.godina;
- cena = other.cena;
- }
- UmetnickoDelo& operator=(const UmetnickoDelo& other) {
- if (this != &other) {
- delete [] avtor;
- this->avtor = new char[strlen(other.avtor) + 1];
- strcpy(avtor, other.avtor);
- godina = other.godina;
- cena = other.cena;
- }
- return *this;
- }
- virtual ~UmetnickoDelo() {
- delete[] avtor;
- }
- };
- bool operator>(UmetnickoDelo &u1, UmetnickoDelo &u2) {
- return u1.cenaDelo()>u2.cenaDelo();
- }
- class MuzickoDelo: public UmetnickoDelo {
- private:
- char zanr[30];
- static double x;
- public:
- MuzickoDelo(char *avtor, int godina, float cena, char *zanr): UmetnickoDelo(avtor, godina, cena) {
- strcpy(this->zanr, zanr);
- }
- static double getX() {
- return x;
- }
- static void setX (double x) {
- MuzickoDelo::x = x;
- }
- float cenaDelo() {
- if(godina<1700&&godina>=1600) {
- return cena+(cena*x);
- } else {
- return cena;
- }
- }
- };
- double MuzickoDelo::x = 0.1;
- class SlikarskoDelo: public UmetnickoDelo {
- private:
- char tehnika[30];
- int stepen;
- public:
- SlikarskoDelo(char *avtor, int godina, float cena, char *tehnika, int stepen): UmetnickoDelo(avtor, godina, cena) {
- strcpy(this->tehnika, tehnika);
- this->stepen=stepen;
- }
- float cenaDelo() {
- if(stepen) {
- return cena*(1-(float)stepen/100);
- } else {
- return cena;
- }
- }
- };
- float najskapoDelo(UmetnickoDelo** dela, int n) {
- float max = dela[0]->cenaDelo();
- int ind = 0;
- for(int i = 1; i < n; i++) {
- if(dela[i]->cenaDelo() > max) {
- max = dela[i]->cenaDelo();
- ind = i;
- }
- }
- cout<<*dela[ind];
- }
- int main() {
- UmetnickoDelo** dela = new UmetnickoDelo*[3];
- dela[0] = new SlikarskoDelo ("sdelo1", 1222, 1000, "tehn1", 50);
- cout<<*dela[0];
- dela[1] = new MuzickoDelo ("mdelo1", 1622, 1000, "zanr1");
- cout<<*dela[1];
- dela[2] = new MuzickoDelo ("mdelo2", 2004, 500, "zanr2");
- cout<<*dela[2];
- cout<<endl;
- cout<<"Najskapo Delo: " << endl;
- najskapoDelo(dela, 3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement