Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <sstream>
- using namespace std;
- class CTriangle
- {
- protected:
- float a;
- float b;
- float c;
- string stringInfo()
- {
- ostringstream temp;
- temp<<"Первая сторона: "<<this->a<<", ";
- temp<<"Вторая сторона: "<<this->b<<", ";
- temp<<"Третья сторона: "<<this->c<<endl;
- return temp.str();
- }
- public:
- CTriangle()
- {
- this->a = 0;
- this->b = 0;
- this->b = 0;
- }
- CTriangle(float newA, float newB, float newC)
- {
- this->a = newA;
- this->b = newB;
- this->c = newC;
- }
- float S()
- {
- float p = P()/2;
- return sqrt(p*(p-a)*(p-b)*(p-c));
- }
- float P()
- {
- return this->a + this->b + this->c;
- }
- string toString()
- {
- ostringstream temp;
- temp<<"Данные о треугольнике:"<<endl;
- temp<<this->stringInfo()<<endl;
- return temp.str();
- }
- ~CTriangle(){};
- };
- class Crectangle:CTriangle
- {
- private:
- float d;
- float e;
- float f;
- public:
- Crectangle()
- {
- this->d = 0;
- this->e = 0;
- this->f = 0;
- }
- Crectangle(float newA, float newB, float newC,
- float newD, float newE, float newF):CTriangle(
- newA, newB, newC)
- {
- this->d = newD;
- this->e = newE;
- this->f = newF;
- }
- float S()
- {
- return sqrt((4*pow(this->e,2)*pow(this->f,2)-
- (pow(this->b,2)+pow(this->d,2)-pow(this->a,2)-pow(this->c,2 )))/16);
- }
- float P()
- {
- return CTriangle::P() + this->d;
- }
- string toString()
- {
- ostringstream temp;
- temp<<"Данные о четырехугольнике:"<<endl;
- temp<<CTriangle::stringInfo();
- temp<<"Четвертая сторона: "<<this->d<<", "<<endl;
- temp<<"Первая диагональ: "<<this->e<<", ";
- temp<<"Вторая диагональ: "<<this->f<<endl;
- return temp.str();
- }
- ~Crectangle(){};
- };
- int main()
- {
- setlocale(0,"Russian");
- CTriangle * triangle = new CTriangle(3,4,5);
- Crectangle* rectangle = new Crectangle(1,1,1,1,1.414213,1.414213);
- cout<<triangle->toString();
- cout<<rectangle->toString();
- cout<<"Площадь треугольника: "<<triangle->S()<<", периметр треугольника: "<<triangle->P()<<endl;
- cout<<"Площадь четыререхугольника: "<<rectangle->S()<<", периметр четырехугольника: "<<rectangle->P()<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement