Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<cstring>
- #include <cmath>
- using namespace std;
- class Igrachka {
- public:
- virtual float getVolumen() = 0;
- virtual float getMasa() = 0;
- //дополнително барање 1
- virtual float getPlostina() = 0;
- };
- class Forma {
- protected:
- char boja[100];
- int gustina;
- public:
- Forma() {}
- Forma(char* b, int g) {
- strcpy(boja, b);
- gustina = g;
- }
- // да се имплементираат потребните методи
- };
- class topka:public Forma,public Igrachka{
- private:
- int radius;
- public:
- topka() {}
- topka(char *b,int g,int r):Forma(b,g) {
- radius = r;
- }
- float pi = 3.14;
- float getMasa(){
- return getVolumen() * gustina;
- }
- float getVolumen() {
- return pi * 4 / 3 * radius*radius*radius;
- }
- float getPlostina() {
- return 4 * pi * pow(radius, 2);
- }
- };
- class kocka:public Forma,public Igrachka{
- private:
- int visina, sirina, dlabocina;
- public:
- kocka() {}
- kocka(char *b,int g,int vis,int sir,int dlab):Forma(b,g) {
- visina = vis;
- sirina = sir;
- dlabocina = dlab;
- }
- float pi = 3.14;
- float getMasa() {
- return getVolumen() * gustina;
- }
- float getVolumen() {
- return visina * sirina * dlabocina;
- }
- float getPlostina() {
- return 2 * (visina * sirina + visina * dlabocina + sirina * dlabocina);
- }
- };
- int main() {
- int n;
- cin >> n;
- int radius, visina, sirina, dolzina, gustina;
- char boja[50];
- //vnesi informacii za kupche
- Igrachka** kupche = new Igrachka * [n];
- int p;
- for (int i = 0; i < n; i++) {
- cin >> p;
- if (p == 1) {
- cin >> boja >> gustina >> radius;
- kupche[i] = new topka(boja, gustina, radius);
- }
- else if (p == 2) {
- cin >> boja >> gustina >> visina >> sirina >> dolzina;
- kupche[i] = new kocka(boja, gustina, visina, sirina, dolzina);
- }
- }
- //vnesi informacii za igrachkata na
- cin >> boja >> gustina >> visina >> dolzina >> sirina;
- kocka petra(boja, gustina, visina, sirina, dolzina);
- double maxMasa;
- for (int i = 0; i < n; i++) {
- maxMasa += kupche[i]->getMasa();
- }
- if (maxMasa > petra.getMasa())
- cout << "DA" << endl;
- else
- cout << "NE" << endl;
- //baranje 1
- double maxvolumen = kupche[0]->getVolumen();
- for (int i = 1; i < n; i++)
- {
- if (maxvolumen < kupche[i]->getVolumen())
- {
- maxvolumen = kupche[i]->getVolumen();
- }
- }
- cout << "Razlikata e: " << abs(maxvolumen - petra.getVolumen()) << endl;
- //baranje 2
- //дополнително барање 2
- double minPlostina = kupche[0]->getPlostina();
- for (int i = 1; i < n; i++) {
- if (minPlostina > kupche[i]->getPlostina())
- minPlostina = kupche[i]->getPlostina();
- }
- cout << "Razlikata e: " << abs(petra.getPlostina()-minPlostina) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement