Advertisement
BrokeMansPC

trougao - 28.5.2021

May 28th, 2021
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. class Trougao{
  7.     float x,y,z,s;
  8.     float povrsina,obim;
  9.     bool jelTrougao = false;
  10.  
  11. public:
  12.     Trougao(){
  13.         x = 0;
  14.         y = 0;
  15.         z = 0;
  16.     }
  17.  
  18.     Trougao(float xu, float yu, float zu) {
  19.         x = xu;
  20.         y = yu;
  21.         z = zu;
  22.         s = (x+y+z) / 2;
  23.  
  24.         if (DaLiJeTrougao(x, y, z)) {
  25.             cout << "Trougao postoji.\n";
  26.         } else cout << "Trougao ne postoji.\n";
  27.  
  28.         povrsina = sqrt(s * (s-x)* (s-y)* (s-z));
  29.         cout << "Povrsina je " << povrsina;
  30.         obim = x + y + z;
  31.         cout << "\nObim je " << obim;
  32.     }
  33.  
  34.     bool DaLiJeTrougao(float a, float b, float c) {
  35.         if (a < b+c && b < a+c && c < b+c) {
  36.                 jelTrougao = true;
  37.             return true;
  38.         } else {
  39.             jelTrougao = false;
  40.             return false;
  41.         }
  42.     }
  43.  
  44.     void unesiStranice(float a, float b, float c){
  45.         x = a;
  46.         y = b;
  47.         z = c;
  48.         s = (x+y+z) / 2;
  49.  
  50.         DaLiJeTrougao(x, y, z);
  51.         povrsina = sqrt(s * (s-x)* (s-y)* (s-z));
  52.         obim = x + y + z;
  53.     }
  54.  
  55.     float vratiPovrsinu(){
  56.         return povrsina;
  57.     }
  58.  
  59.     float vratiObim(){
  60.         return obim;
  61.     }
  62.  
  63.  
  64. };
  65. int main()
  66. {
  67.     float a,b,c;
  68.     cout << "Unesi stranicu A:";
  69.     cin >> a;
  70.     cout << "Unesi stranicu B:";
  71.     cin >> b;
  72.     cout << "Unesi stranicu C:";
  73.     cin >> c;
  74.  
  75.     Trougao tr(a, b, c);
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement