Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class ZicanInstrument{
- protected:
- char ime[20];
- int brZici;
- float osnCena;
- public:
- ZicanInstrument(char i[20], int br=0, float osn=0){
- strcpy(ime, i);
- brZici=br;
- osnCena=osn;
- }
- virtual float cena(){
- return osnCena;
- }
- int getBrZici(){
- return brZici;
- }
- bool operator==(ZicanInstrument &zi){
- return (brZici==zi.brZici);
- }
- friend ostream& operator<<(ostream &out, ZicanInstrument &zi){
- out<<zi.cena()<<endl;
- return out;
- }
- };
- class Mandolina: public ZicanInstrument{
- private:
- char forma[20];
- public:
- Mandolina(char i[20], int br=0, float osn=0, char f[20]=""):ZicanInstrument(i, br, osn){
- strcpy(forma, f);
- }
- float cena(){
- if (strcmp(forma, "Neapolitan")==0)
- return ZicanInstrument::cena()*1.15; //moze i obicno
- return ZicanInstrument::cena();
- }
- };
- class Violina: public ZicanInstrument{
- private:
- float golemina;
- public:
- Violina(char i[20], int br=0, float osn=0, float gol=0):ZicanInstrument(i, br, osn){
- golemina=gol;
- }
- float cena(){
- if(golemina==0.25)
- return ZicanInstrument::cena()*1.1;
- else if(golemina==1)
- return ZicanInstrument::cena()*1.2;
- else
- return ZicanInstrument::cena();
- }
- };
- void pecatiInstrumenti(ZicanInstrument &zi, ZicanInstrument **i, int n){
- for(int j=0;j<n;j++){
- if(zi==*(i[j]))
- cout<<*(i[j]);
- }
- }
- int main() {
- char ime[20];
- int brojZici;
- float cena;
- char forma[20];
- cin >> ime >> brojZici >> cena >> forma;
- Mandolina m(ime, brojZici, cena, forma);
- int n;
- cin >> n;
- ZicanInstrument **zi = new ZicanInstrument*[2 * n];
- for(int i = 0; i < n; ++i) {
- cin >> ime >> brojZici >> cena >> forma;
- zi[i] = new Mandolina(ime, brojZici, cena, forma);
- }
- for(int i = 0; i < n; ++i) {
- float golemina;
- cin >> ime >> brojZici >> cena >> golemina;
- zi[n + i] = new Violina(ime, brojZici, cena, golemina);
- }
- pecatiInstrumenti(m, zi, 2 * n);
- for(int i = 0; i < 2 * n; ++i) {
- delete zi[i];
- }
- delete [] zi;
- return 0;
- }
Add Comment
Please, Sign In to add comment