Quipex

zadanie_3

Sep 29th, 2015
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. // zadanie_3.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <math.h>
  7. #include <cmath>
  8.  
  9. using namespace std;
  10.  
  11. float ploshad(int x1, int y1, int x2, int y2, int x3, int y3)
  12. {
  13.                                                         //cout<<"x: "<<x1<<endl;
  14.     float a=sqrt(powf((x2-x1),2)+powf((y2-y1),2));      //cout<<"a: "<<a<<endl;
  15.     float b=sqrt((powf((x3-x2),2)+powf((y3-y2),2)));    //cout<<"b: "<<b<<endl;
  16.     float c=sqrt((powf((x1-x3),2)+powf((y1-y3),2)));    //cout<<"c: "<<c<<endl;
  17.     float p=((a+b+c)/2);                                //cout<<"p: "<<p<<endl;
  18.     float s=sqrt((p*(p-a)*(p-b)*(p-c)));                //cout<<"s: "<<s<<endl;
  19.    
  20.     return s;
  21. }
  22.  
  23. void main()
  24. {
  25.     int x1=-3, x2=-1, x3=0, x4, y1=-1, y2=1, y3=-1, y4;
  26.     //int x1=-1, x2=-1, x3=0, x4, y1=0, y2=-1, y3=-1, y4; //тест работы считалки площади, ответ 0.5
  27.     cout<<"Vvedite x, y:"<<endl;
  28.     cin>>x4>>y4;
  29.     //cout<<"0^1/2="<<powf(0,1/2)<<endl; //pow чёт не пашет, пришлось подключить <cmath> и считать sqrt()
  30.     float S=ploshad(x1,y1,x2,y2,x3,y3);            
  31.     float S2=ploshad(x1,y1,x2,y2,x4,y4);            //cout<<"S2="<<S2<<endl;
  32.     float S3=ploshad(x1,y1,x3,y3,x4,y4);            //cout<<"S3="<<S3<<endl;
  33.     float S4=ploshad(x2,y2,x3,y3,x4,y4);            //cout<<"S4="<<S4<<endl;
  34.     float Ssum=S2+S3+S4;                            //cout<<"Ssum="<<Ssum<<endl<<"S="<<S<<endl;
  35.     if(S>=Ssum)
  36.     {
  37.         cout<<"To4ka lezhit v treugolnike"<<endl;
  38.     }
  39.     else
  40.     {
  41.         cout<<"To4ka ne lezhit v treugolnike"<<endl;
  42.     }
  43.     system("pause");   
  44. }
Advertisement
Add Comment
Please, Sign In to add comment