Guest User

Untitled

a guest
Mar 12th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.04 KB | None | 0 0
  1. functions.h
  2. -----------
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <conio.h>
  6. #include <stdlib.h>
  7. using namespace std;
  8.  
  9. #include "figure.h"
  10.  
  11. void zada4a();
  12. ------------
  13. figure.h
  14. ------------
  15. class point{
  16. private:
  17.     double x;
  18.     double y;
  19. public:
  20.     point(): x(0), y(0){}
  21.     point(int, int);
  22.     friend class figure;
  23.     friend istream& operator >> (istream& s, point& d);
  24. };
  25.  
  26. class figure{
  27. private:
  28.     point koor, koor1, koor2, koor3;
  29.     static char nazv[10];
  30.     static int total;
  31.     int t;
  32. public:
  33.     figure();                  //Конструктор по умолчанию
  34.     figure( point kor, point kor1, point kor2, point kor3 );
  35.     figure( const figure&);
  36.     ~figure(){
  37.         total--;
  38.     }
  39.     void proverka(figure&);
  40.  
  41.  
  42. };
  43. ------------
  44. main.cpp
  45. ------------
  46. #include "functions.h"
  47.  
  48. void main(){
  49.     setlocale(0, "RUS");
  50.     zada4a();
  51.     system("pause");
  52.     return;
  53. }
  54. ------------
  55. functions.cpp
  56. ------------
  57. #include "functions.h"
  58.  
  59. void zada4a(){
  60.     figure a1, a2,a5;
  61.     point a(1,1), b(4,4), c(6,4), d(9,1);
  62.     point aa1(1,1), bb1(2,4), cc1(6,4), dd1(9,1);
  63.     figure ak(a,b,c,d);
  64.     figure ak1(aa1,bb1,cc1,dd1);
  65.     ak.proverka(ak);
  66.     ak1.proverka(ak1);
  67.     figure ab(ak);
  68. return;
  69. }
  70. ------------
  71. figure.cpp
  72. ------------
  73. #include "functions.h"
  74.  
  75. point::point(int m_x, int m_y){
  76.     x = m_x;
  77.     y = m_y;
  78. }
  79.  
  80. figure::figure(): koor(0,0), koor1(0,0), koor2(0,0), koor3(0,0){
  81.     total++;
  82.     cout << nazv << " " << total << " ";
  83. }                     //Конструктор по умолчанию
  84. figure::figure( point kor, point kor1, point kor2, point kor3 ){
  85.     koor=kor;
  86.     koor1=kor1;
  87.     koor2=kor2;
  88.     koor3=kor3;
  89.     total++;
  90.     cout << nazv << " " << total<< " ";
  91. }
  92. figure::figure( const figure&  A ){
  93.     koor=A.koor;
  94.     koor1=A.koor1;
  95.     koor2=A.koor2;
  96.     koor3=A.koor3;
  97.     cout << endl << "Конструктор копирования " << endl;
  98. }
  99.  
  100. istream& operator>>(istream& s, point& d){                                            
  101.     s >> d.x;        
  102.     return s;                                    
  103. }
  104.  
  105. void figure::proverka(figure& A){
  106.     koor=A.koor;
  107.     koor1=A.koor1;
  108.     koor2=A.koor2;
  109.     koor3=A.koor3;
  110.     double AC = sqrt(pow(koor.x - koor2.x, 2) + pow(koor.y - koor2.y, 2));
  111.     double BD = sqrt(pow(koor1.x - koor3.x, 2) + pow(koor1.y - koor3.y, 2));
  112.     double AB = sqrt(pow(koor.x - koor1.x, 2) + pow(koor.y - koor1.y, 2));
  113.     double AD = sqrt(pow(koor.x - koor3.x, 2) + pow(koor.y - koor3.y, 2));
  114.     double BC = sqrt(pow(koor1.x - koor2.x, 2) + pow(koor1.y - koor2.y, 2));
  115.     if (AC==BD){
  116.         cout << endl << "Трапеция равнобедренная " << endl;
  117.         double h = sqrt(pow(AB,2)-((pow(BC-AD,2))/4));
  118.         double S = h*(BC+AD)/2;
  119.         cout << "Площадь трапеции - " << S << endl << "Высота трапеции - " << h << endl;
  120.     }
  121.     else{
  122.         cout << endl << "Трапеция не равнобедренная " << endl;
  123.         double Perimetr = AB*2+AD+BC;
  124.         cout << "Периметр трапеции равен " << Perimetr <<endl;
  125.     }
  126. }
  127.                                        
  128. char figure::nazv[10] = "Трапеция\0";
  129. int figure::total = 0;
Add Comment
Please, Sign In to add comment