Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- class InstrumentTypeAlreadyExists {
- char msg[100];
- };
- using namespace std;
- class MusicalInstrument {
- private:
- char *niza; //име: динамички алоцирана низа од знаци
- char instrument[10];//вид на музичкиот инструмент: низа од најмногу 10 знаци
- int cena;//цена на чинење на музичкиот инструмент: цел број
- int godini;//години на старост на музичкиот инструмент: цел број
- bool muzejskaVrednost//променлива што означува дали музичкиот инструмент има музејска вредност: boolean вредност
- public:
- MusicalInstrument(){
- strcpy(this->instrument,"");
- this->cena = 0;
- this->godini = 0;
- this->muzejskaVrednost = False;
- }
- MusicalInstrument(char *niza){
- strcpy(this->instrument,instrument);
- this->cena = cena;
- this->godini = godini;
- }
- MusicalInstrument(const MusicalInstrument ©){
- strcpy(this->instrument,copy.instrument);
- this->cena = copy.cena;
- this->godini = copy.godini;
- }
- MusicalInstrument(©){
- if(this!= ©){
- strcpy(this->instrument,copy.instrument);
- this->cena = copy.cena;
- this->godini = copy.godini;
- }return *this;
- }
- MusicalInstrument& operator+=(const dodatok &c){
- if(muzejskaVrednost == True)
- cena = dodatok + cena;
- return cena;
- }
- friend ostream &operator<<(ostream &o, MusicalInstrument &m){
- o<<print.niza<<" - "<<print.instrument<<endl;
- o<<print.godini<<", "<<print.cena<<endl;
- return o;
- }
- };
- class Band{
- private:
- char ime[100];//име: низа од најмногу 100 знаци
- MusicalInstrument instrumenti;//инструменти: динамички алоцирана низа од објекти од класата MusicalInstrument
- int br;//број на музички инструменти
- public:
- Band(){
- strcpy(this->ime,"");
- }
- Band(char *ime){
- strcpy(this->ime,ime);
- this->instrumenti = new MusicalInstrument[0];
- this->br = 0;
- }
- Band(const Band ©){
- this->instrumenti = new MusicalInstrument[copy.br];
- for(int i = 0; i<br; i++)
- this->instrumenti[i] = copy.instrumenti[i];
- }
- Band(©){
- if(this!= ©){
- this->instrumenti = new MusicalInstrument[copy.br];
- for(int i = 0; i<br; i++)
- this->instrumenti[i] = copy.instrumenti[i];
- }return *this;
- }
- friend ostream &operator<<(ostream &o, MusicalInstrument &m){
- o<<print.ime<<endl;
- for(int i = 0; i<br; i++){o<<print.instrumenti[i]<<endl;}
- return o;}
- Band &operator+=( instrumenti &add){
- if(this->instrumenti == instrumenti)
- throw InstrumentTypeAlreadyExists
- else{
- MusicalInstrument *tmp = new MusicalInstrument[br + 1];
- for(int i = 0; i < br; i++){
- tmp[i] = niza[i];
- tmp[br++] = add;
- niza = tmp;
- }
- return *this;
- }
- }
- };
- void oldest_valuable_instrument(Band *bend, int br){
- }
- int main(){
- int test;
- cin >> test;
- if(test == 1){
- cout << "Testing class MusicalInstrument" << endl;
- char name[50], type[50];
- int price, age;
- bool museumValue;
- cin >> name >> type >> price >> age >> museumValue;
- MusicalInstrument a;
- MusicalInstrument b(name, type, price, age, museumValue);
- a=b;
- cout << a.getName() << endl;
- cout << b.getPrice() << endl;
- cout << b.getAge() << endl;
- }
- else if(test == 2){
- cout << "Testing operators += and << in the class MusicalInstrument" << endl;
- char name[50], type[50];
- int price, age;
- bool muaseumValue;
- cin >> name >> type >> price >> age >> muaseumValue;
- MusicalInstrument a(name, type, price, age, muaseumValue);
- a += 100;
- cout << a << endl;
- }
- else if(test == 3){
- cout << "Testing class Band constructor" << endl;
- char name[50];
- cin >> name;
- Band b(name);
- cout << b.getName() << endl;
- }
- else if(test == 4){
- cout << "Testing class Band operator<<" << endl;
- char ime[50], tip[50];
- int cena_cinenje, godini_starost;
- bool muzejska_vrednost;
- cin>>ime;
- Band b(ime);
- for(int i = 0; i < 2; i++){
- cin >> ime >> tip >> cena_cinenje >> godini_starost >> muzejska_vrednost;
- MusicalInstrument a(ime, tip, cena_cinenje, godini_starost, muzejska_vrednost);
- b+=a;
- }
- cout << b;
- }
- else if(test == 5){
- cout << "Testing operator+= and class InstrumentTypeAlreadyExists" << endl;
- char name[50], type[50];
- int price, age;
- bool museumValue;
- cin>>name;
- Band band(name);
- cin >> name >> type >> price >> age >> museumValue;
- MusicalInstrument a(name, type, price, age, museumValue);
- cin >> name >> type >> price >> age >> museumValue;
- MusicalInstrument b(name, type, price, age, museumValue);
- band += a;
- band += b;
- cout << band;
- }
- else if(test == 6){
- cout << "Testing class Band operator==" << endl;
- char name[50], type[50];
- int price, age;
- bool museumValue;
- cin>>name;
- Band band1(name);
- cin>>name;
- Band band2(name);
- for(int i = 0; i < 2; i++){
- cin >> name >> type >> price >> age >> museumValue;
- MusicalInstrument a(name, type, price, age, museumValue);
- band1+=a;
- band2+=a;
- }
- int c;
- cin>>c;
- if (c){
- cin >> name >> type >> price >> age >> museumValue;
- MusicalInstrument a(name, type, price, age, museumValue);
- band1+=a;
- }
- if(band1 == band2){
- cout << "True";
- } else{
- cout<<"False";
- }
- }
- else if(test == 7){
- cout << "Testing oldest_valuable_instrument" << endl;
- Band b[2];
- char name[50], type[50];
- int price, age;
- bool museumValue;
- for(int i=0;i<2;i++){
- cin>>name;
- b[i].setIme(name);
- for(int j=0;j<2;j++){
- cin >> name >> type >> price >> age >> museumValue;
- MusicalInstrument a(name, type, price, age, museumValue);
- b[i]+=a;
- }
- }
- oldest_valuable_instrument(b,2);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement