Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication14.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #define PI 3.1415
- enum Color { RED, GREEN, BLUE, YELLOW, WHITE, BLACK };
- enum Gas { N2O2, H2, He, Ne };
- class Sphere // Базовий клас Sphere
- {
- public:
- Sphere();
- Sphere(double Radius);
- void setRadius(double Radius);
- double Radius();
- double Diameter();
- double Circumference();
- double Area();
- double Volume();
- virtual void displayStatistics();
- private:
- double mRadius;
- };
- class Ball :public Sphere// Похідний клас Ball від Sphere
- {
- public:
- Ball();
- Ball(double Radius, std::string Name, Color color);
- void setName(std::string Name);
- std::string Name();
- void setColor(Color color);
- Color color();
- std::string ColorName();
- void resetBall(double Radius, std::string Name, Color color);
- virtual void displayStatistics() override;
- private:
- std::string mName;
- Color mC;
- };
- class Ballon : public Ball // Похідний клас Ballon від Ball
- {
- public:
- Ballon();
- Ballon(double Radius, std::string Name, Color color, Gas gas);
- void setGas(Gas gas);
- Gas gas();
- std::string GasName();
- void resetBallon(double Radius, std::string Name, Color color, Gas gas);
- void displayStatistics();
- private:
- Gas mG;
- };
- class WeightBall : public Ball // Похідний клас WeightBall від Ball
- {
- public:
- WeightBall();
- WeightBall(double Radius, std::string Name, Color color, double Density);
- void setDensity(double Density);
- double Density();
- virtual double Weight();
- void resetWeightBall(double Radius, std::string Name, Color color, double Density);
- virtual void displayStatistics();
- private:
- double mDensity;
- };
- class WeightBallon : public WeightBall, public Ballon // Похідний клас WeightBallon від Ballon
- {
- public:
- WeightBallon();
- WeightBallon(double Radius, std::string Name, Color color, Gas gas);
- virtual double Weight();
- void resetWeightBallon(double Radius, std::string Name, Color color, Gas gas);
- virtual void displayStatistics();
- };
- Sphere::Sphere() // Реалізація методів класу Sphere
- {
- setRadius(1.0);
- }
- Sphere::Sphere(double Radius)
- {
- setRadius(Radius);
- }
- void Sphere::setRadius(double Radius)
- {
- mRadius = Radius;
- }
- double Sphere::Radius()
- {
- return mRadius;
- }
- double Sphere::Diameter()
- {
- return 2.0*Radius();
- }
- double Sphere::Circumference()
- {
- return PI * Diameter();
- }
- double Sphere::Area()
- {
- return PI * Diameter()*Diameter();
- }
- double Sphere::Volume()
- {
- return 4 * PI*pow(Radius(), 3) / 3.0;
- }
- void Sphere::displayStatistics()
- {
- std::cout << "Radius = " << Radius() << std::endl
- << "Diameter = " << Diameter() << std::endl
- << "Circumference = " << Circumference() << std::endl
- << "Area = " << Area() << std::endl
- << "Volume = " << Volume() << std::endl << std::endl;
- }
- Ball::Ball()
- {
- setRadius(100);
- setName("ball");
- setColor(BLACK);
- }
- Ball::Ball(double Radius, std::string Name, Color сolor) :Sphere(Radius)
- {
- setName(Name);
- setColor(сolor);
- }
- void Ball::setName(std::string Name)
- {
- mName = Name;
- }
- std::string Ball::Name()
- {
- return mName;
- }
- void Ball::setColor(Color color)
- {
- mC = color;
- }
- Color Ball::color()
- {
- return mC;
- }
- std::string Ball::ColorName()
- {
- std::string ColorName;
- switch (mC)
- {
- case RED: ColorName = "RED"; break;
- case GREEN: ColorName = "GREEN"; break;
- case BLUE: ColorName = "BLUE"; break;
- case YELLOW: ColorName = "YELLOW"; break;
- case WHITE: ColorName = "WHITE"; break;
- case BLACK: ColorName = "BLACK"; break;
- }
- return ColorName;
- }
- void Ball::resetBall(double Radius, std::string Name, Color color)
- {
- setRadius(Radius);
- setName(Name);
- setColor(color);
- }
- void Ball::displayStatistics()
- {
- std::cout << "Name = " << Name() <<"\n Color Name = "<< ColorName() <<"\n radius = "<< Radius()
- <<"\n diameter = "<< Diameter() << " \n circumreference = " <<Circumference() <<"\n area = " << Area()<< std::endl;
- }
- Ballon::Ballon() :Ball() // Реалізація методів класу Ballon
- {
- setGas(N2O2);
- }
- Ballon::Ballon(double Radius, std::string Name, Color color, Gas gas) : Ball(Radius, Name, color)
- {
- setGas(gas);
- }
- void Ballon::setGas(Gas gas)
- {
- mG = gas;
- }
- Gas Ballon::gas()
- {
- return mG;
- }
- std::string Ballon::GasName()
- {
- std::string GasName;
- switch (mG)
- {
- case N2O2: GasName = "Air"; break;
- case H2: GasName = "Hydrogen"; break;
- case He: GasName = "Helium"; break;
- case Ne: GasName = "Neon"; break;
- }
- return GasName;
- }
- void Ballon::resetBallon(double Radius, std::string Name, Color color, Gas gas)
- {
- Ball::resetBall(Radius, Name, color);
- setGas(gas);
- }
- void Ballon::displayStatistics()
- {
- Ball::displayStatistics();
- std::cout << GasName();
- }
- WeightBall::WeightBall() :Ball()
- {
- setDensity(1000.0);
- }
- WeightBall::WeightBall(double Radius, std::string Name, Color color, double Density) : Ball(Radius, Name, color)
- {
- setDensity(Density);
- }
- void WeightBall::setDensity(double Density)
- {
- mDensity = Density;
- }
- double WeightBall::Density()
- {
- return mDensity;
- }
- double WeightBall::Weight()
- {
- return mDensity * Volume();
- }
- void WeightBall::resetWeightBall(double Radius, std::string Name, Color color, double Density)
- {
- resetBall(Radius, Name, color);
- setDensity(Density);
- }
- void WeightBall::displayStatistics()
- {
- Ball::displayStatistics();
- printf(" Density=%lf\n Weight=%lf\n", Density(), Weight());
- }
- WeightBallon::WeightBallon() :Ballon() // Реалізація методів класу WeightBallon
- {
- }
- WeightBallon::WeightBallon(double Radius, std::string Name, Color color, Gas gas) : Ballon(Radius, Name, color, gas)
- {
- }
- double WeightBallon::Weight()
- {
- double Density;
- switch (Gas())
- {
- case N2O2: Density = 1.225; break;
- case H2: Density = 0.09; break;
- case He: Density = 0.178; break;
- case Ne: Density = 0.901; break;
- }
- WeightBall::setDensity(Density);
- WeightBall::Density();
- return WeightBall::Weight();
- }
- void WeightBallon::resetWeightBallon(double Radius, std::string Name, Color color, Gas gas)
- {
- resetBallon(Radius, Name, color, gas);
- }
- void WeightBallon::displayStatistics()
- {
- Ballon::displayStatistics();
- std::cout<< "\n Density=" << Density() << "\n Weight= " << Weight() <<"\n";
- }
- int main()
- {
- Sphere s( 10);
- s.displayStatistics();
- std::cout << std::endl;
- Ball b(100, "ball1", BLACK);
- b.displayStatistics();
- std::cout << std::endl;
- Ballon ballon1(100, "Ballon1 ", RED , He);
- ballon1.displayStatistics();
- std::cout << std::endl;
- WeightBall wb1(20, " wb1", RED, 20);
- wb1.displayStatistics();
- std::cout << std::endl;
- WeightBallon wballon1(20, " wballon1", BLACK, H2);
- wballon1.displayStatistics();
- std::cout << std::endl;
- std::cout << std::endl;
- std::cout << std::endl;
- std::cout << std::endl;
- std::cout << wb1.Weight();
- std::cout << std::endl;
- std::cout << wballon1.Weight();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement