Zdrojáky - objektové 1/5

#include<iostream>
using namespace std;

enum nota {C,D,E,F,G,A,H};

class Instrument{
public:
Instrument()
{
cout << "Konstruktor Instrument" << endl;
}

~Instrument()
{
cout << "Destruktor Instrument" << endl;
}

void play(nota n)
{
cout << n << endl;
}

};

class Dychove:public Instrument
{
public:
Dychove()
{
cout << "Konstruktor Dychove" << endl;
}

~Dychove()
{
cout << "Destruktor Dychove" << endl;
}

};


class Drevene:public Dychove
{
public:
Drevene()
{
cout << "Konstruktor Drevene" << endl;
}

~Drevene()
{
cout << "Destruktor Drevene" << endl;
}

};

void ton(Instrument&i)
{
cout << "Hram C" << endl;
i.play(C);
}



int main()
{
Dychove flauta;
flauta.play(E);
ton(flauta);

Drevene *zobcova_flauta=new Drevene();

zobcova_flauta->play(G);
ton(*zobcova_flauta);

delete zobcova_flauta;

return 0;
}



#include <iostream>
#include <iomanip>
using namespace std;


void main()
{
cout << "velkost int: " << sizeof(int) << "B" << endl;
cout << "velkost char: " << sizeof(char) << "B" << endl;
cout << "velkost long: " << sizeof(long) << "B" << endl;
cout << "velkost short: " << sizeof(short) << "B" << endl;
cout << "velkost doble: " << sizeof(double) << "B" << endl;
cout << "velkost float: " << sizeof(float) << "B" << endl;

int i;
cout << "Zadaj cislo" << endl;
cin >> i;

cout.width(10);
cout.fill('/');
cout << i;
cout << endl << "cislo v osmickovej sustave" << oct << i;
cout << endl << "cislo v setnastkovej sustave" << hex << i;
}


/*void main()
{
char meno[20];
int vek,j;
float plat;

cout << "Zadaj meno" << endl;
cin >> meno;


cout << "Zadaj vek" << endl;
cin >> vek;

cout << "Zadaj plat" << endl;
cin >> plat;

cout << "Chces komentar? " << endl;
cin >> ws;

char c;
c=toupper(cin.get());

char komentar[81];

if(c=='A')

{
cin.get(komentar,80);

}

cout << setw(20) << meno << endl << vek << endl << plat << endl << komentar << endl;


}*/

#include <iostream>
using namespace std;


class Zlomok
{
public:
int citatel;
int menovatel;
int vypis()
{
cout << this->citatel << "/" << this->menovatel;
return 0;
}
};


void main()
{
//staticka alokacia
Zlomok z1;

z1.citatel=1;
z1.menovatel=2;
z1.vypis();

//dynamicka alokacia
Zlomok *zsmer;

zsmer=new Zlomok();
zsmer -> citatel = 3;
zsmer -> menovatel = 5;
zsmer -> vypis();

delete zsmer;
}