Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib> // Standard General Utilities Library
- #include <cstdio> // Input/Output operations (C)
- #include <iostream> // Input/Output stream objects
- #include <fstream> // File input and output
- #include <ctime> // Date and time information
- #include <cmath> // Mathematical operations and transformations
- using namespace std;
- #define pi 3.14
- // Classes
- class line {
- protected:
- double a;
- public:
- line() {a = 1;}
- line(double var1) {a = var1;}
- };
- class circle: public line {
- protected:
- double r;
- public:
- double area() {return pi * pow(r, 2);}
- circle():line() {r = a;}
- circle(double var1) {r = var1;}
- };
- class cylinder: public circle {
- private:
- double h;
- public:
- void assign(double var1, double var2) {r = var1; h = var2;}
- double volume() {return area() * h;}
- void print() { cout << "Cylinder information:" << endl;
- cout << "r = " << r << ", h = " << h << endl;
- cout << "Volume: " << volume() << endl << endl;}
- cylinder() {h = 1;}
- cylinder(double var1) {h = var1;}
- cylinder(double var1, double var2):circle(var1) {h = var2;}
- };
- class cone: public circle {
- private:
- double h;
- public:
- void assign(double var1, double var2) {r = var1; h = var2;}
- double volume() {return 1.0 / 3.0 * area() * h;}
- void print() { cout << "Cone information:" << endl;
- cout << "r = " << r << ", h = " << h << endl;
- cout << "Volume: " << volume() << endl << endl;}
- cone() {h = 1;}
- cone(double var1) {h = var1;}
- cone(double var1, double var2):circle(var1) {h = var2;}
- };
- class rectangle: public line {
- protected:
- double b;
- public:
- double area() {return a * b;}
- rectangle():line() {b = 1;}
- rectangle(double var1):line(var1) {b = var1;}
- rectangle(double var1, double var2):line(var1) {b = var2;}
- };
- class parallelepiped: public rectangle{
- private:
- double c;
- public:
- double volume() {return area() * c;}
- void print() { cout << "Parallelepiped rectangle information:" << endl;
- cout << "a = " << a << ", b = " << b << ", c = " << c << endl;
- cout << "Volume: " << volume() << endl << endl;}
- parallelepiped():rectangle() {c = 1;}
- parallelepiped(double var1):rectangle(var1) {c = var1;}
- parallelepiped(double var1, double var2):rectangle(var1) {c = var2;}
- parallelepiped(double var1, double var2, double var3):rectangle(var1, var2) {c = var3;}
- };
- // Main program
- int main(int argc, char *argv[]) {
- parallelepiped G(4, 2, 3);
- G.print();
- cylinder R(2, 3);
- R.print();
- cone K(2, 3);
- K.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement