Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //by Aksenoff
- //geom.h
- #ifndef MNOG_H //Директивы #ifndef, #define, #endif служат для защиты от многократного копирования
- #define MNOG_H
- class Mnog //Класс многоугольников - в данном примере используется как класс-предок.
- {
- protected: //защищённые члены класса могут использоваться при наследовании, а приватные - нет
- double shirina, visota;
- Mnog(double, double);
- };
- #endif
- //=======================================
- //pram.h
- #ifndef PRAM_H
- #define PRAM_H
- #include "geom.h"
- class Pram: public Mnog //Создаём класс прямоугольник - потомок класса многоугольников
- {
- public:
- double ploshad();
- Pram(double a, double b): Mnog(a, b) {};
- };
- #endif
- //=======================================
- //treug.h
- #ifndef TREUG_H
- #define TREUG_H
- #include "geom.h"
- class Treug: public Mnog {
- public:
- double ploshad();
- Treug(double a, double b): Mnog(a, b) {};
- };
- #endif
- //=======================================
- //geom.cpp
- #include "geom.h"
- Mnog::Mnog(double x, double y)
- {
- shirina = x;
- visota = y;
- }
- //=======================================
- //pram.cpp
- #include "pram.h"
- double Pram::ploshad()
- {
- return shirina*visota;
- }
- //=======================================
- //treug.cpp
- #include "treug.h"
- double Treug::ploshad()
- {
- return shirina*visota*0.5;
- }
- //=======================================
- //main.cpp
- #include "pram.h"
- #include "treug.h"
- #include "iostream"
- int main()
- {
- Treug tr1(10, 20);
- std::cout << tr1.ploshad();
- std::cin.sync();
- std::cin.clear();
- std::cin.get();
- return 0;
- }
- //========================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement