-
-
Save KrzaQ/d1c45a5265f04e4c59f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <ctime> | |
using namespace std; | |
class Klocki { | |
int rozmiar; | |
string kolor; | |
int masa; | |
public: | |
string nazwa; | |
Klocki(int roz, string kol, int mas, string nazw) | |
{ | |
rozmiar = roz; | |
kolor = kol; | |
masa = mas; | |
nazwa = nazw; | |
} | |
void wys() | |
{ | |
cout << endl << "Rozmiar: " << rozmiar << endl << "Kolor: " << kolor << endl | |
<< "Masa: " << masa << endl << "Nazwa: " << nazwa << endl << endl; | |
} | |
}; | |
class Prostopadloscian : public Klocki { | |
int a, b, c; | |
public: | |
Prostopadloscian(int mas, int aa, int bb, int cc) | |
: Klocki(aa * bb * cc, "Niebieski", mas, "Prostopadloscian") | |
{ | |
a = aa; | |
b = bb; | |
c = cc; | |
} | |
}; | |
class Walec : public Klocki { | |
int prom, wys; | |
public: | |
Walec(int mas, int pro, int wy) | |
: Klocki(pro * pro * 3 * wy, "Czerwony", mas, "Walec") | |
{ | |
prom = pro; | |
wys = wy; | |
} | |
}; | |
class Ostroslup : public Klocki { | |
int polepod, wys; | |
public: | |
Ostroslup(int mas, int pole, int wy) | |
: Klocki(pole * wy, "Zielony", mas, "Ostroslup") | |
{ | |
polepod = pole; | |
wys = wy; | |
} | |
}; | |
int main() | |
{ | |
int liczba, a; | |
srand(time(0)); | |
Klocki** tab; | |
Klocki* temp; | |
cout << "Ile klockow ma zostac wygenerowanych: "; | |
cin >> liczba; | |
for (int i = 0; i < liczba; i++) { | |
a = rand() % 3; | |
switch (a) { | |
case 0: | |
tab[i] = new Prostopadloscian(rand() % 10, rand() % 10, rand() % 10, | |
rand() % 10); | |
break; | |
case 1: | |
tab[i] = new Walec(rand() % 10, rand() % 10, rand() % 10); | |
break; | |
case 2: | |
tab[i] = new Ostroslup(rand() % 10, rand() % 10, rand() % 10); | |
break; | |
} | |
} | |
for (int h = 0; h < liczba; h++) { | |
for (int j = 0; j < liczba; j++) { | |
if (tab[j]->nazwa > tab[j + 1]->nazwa) { | |
temp = tab[j + 1]; | |
tab[j + 1] = tab[j]; | |
tab[j] = temp; | |
} | |
} | |
} | |
for (int k = 0; k < liczba; k++) { | |
tab[k]->wys(); | |
} | |
system("PAUSE"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment