Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. /*
  2.  * File:   main.cpp
  3.  * Author: roman
  4.  *
  5.  * Created on October 6, 2019, 1:21 PM
  6.  */
  7.  
  8. #include <iostream>
  9. #include <fstream>
  10. #include <string>
  11. #include <stdlib.h>
  12. #include <time.h>
  13. #include <cmath>
  14. #include <complex>
  15.  
  16. using namespace std;
  17.  
  18. struct Punkt{
  19.     double x;
  20.     double y;
  21.    
  22.     Punkt() {
  23.     }
  24.        
  25.     Punkt(double x, double y) :
  26.         x(x), y(y) {
  27.     }
  28. };
  29.  
  30. class Trojkat {
  31.     Punkt a,b,c;
  32.     int ab, bc, ca;
  33.    
  34.    
  35.     void computeLenght(){
  36.         ab = sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2));
  37.         bc = sqrt(pow(c.x - b.x, 2) + pow(c.y - b.y, 2));
  38.         ca = sqrt(pow(a.x - c.x, 2) + pow(a.y - c.y, 2));
  39.     }
  40.    
  41. public:
  42.  
  43.     Trojkat() : a(Punkt()), b(Punkt()), c(Punkt()) {
  44.     }
  45.  
  46.     Trojkat(Punkt a, Punkt b, Punkt c) :
  47.         a(a), b(b), c(c) {
  48.         computeLenght();
  49.     }
  50.    
  51.     Trojkat(double ax, double ay, double bx, double by, double cx, double cy)
  52.     : a(Punkt(ax,ay)), b(Punkt(bx,by)), c(Punkt(cx, cy)) {
  53.         computeLenght();
  54.     }
  55.    
  56.     bool isTrojkat(){
  57.         return ab+bc>ca || bc+ca>ab || ca+bc>ab;
  58.     }
  59.    
  60.     bool isRownoboczny(){
  61.         if(!isTrojkat()){
  62.             return false;
  63.         }
  64.         return ab == bc == ca;
  65.     }
  66.    
  67.     bool isRownoramienny(){
  68.         if(!isTrojkat()){
  69.             return false;
  70.         }
  71.         return (ab == bc) || (bc == ca) || (ca== ab);
  72.     }
  73.    
  74.     bool isProstokatny(){
  75.         if(!isTrojkat()){
  76.             return false;
  77.         }
  78.        
  79.         return pow(ab,2) + pow(bc,2) == pow(ca,2) ||
  80.             pow(bc,2) + pow(ca,2) == pow(ab,2) ||
  81.             pow(ca,2) + pow(ab,2) == pow(bc,2);  
  82.     }
  83.    
  84. };
  85.        
  86. int main(int argc, char** argv) {
  87.  
  88.     Trojkat a(6.0,1.0,1.0,1.0,6.0,1.0);
  89.     cout<< a.isTrojkat()<<endl;
  90.    
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement