Skip to content

Instantly share code, notes, and snippets.

@KrystianGraba
Created May 13, 2020 20:34
Show Gist options
  • Select an option

  • Save KrystianGraba/8598ddf23ee9b7bc234a8fdc365ce989 to your computer and use it in GitHub Desktop.

Select an option

Save KrystianGraba/8598ddf23ee9b7bc234a8fdc365ce989 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <math.h>
class Trojkat{
private:
float x, y, z;//boki trojkata
float obw2;//polowa obwodu trojkata
float pole;//obwod trojkata
public:
Trojkat();
Trojkat(float _x, float _y, float _z);
bool SprawdzXYZ(float a, float b, float c);
void UstawXYZ(float _x, float _y, float _z);
void ObliczObw2();
void ObliczPole();
float retX() { return x;}
float retY() { return y;}
float retZ() { return z;}
void setpole(float res) {
pole = res;
}
void setobw2(float res) {
obw2 = res;
}
float retpole() { return pole; }
float retobw2() { return obw2; }
};
Trojkat::Trojkat() {
x = 0;
y = 0;
z = 0;
}
Trojkat::Trojkat(float _x, float _y, float _z) {
x = _x;
y = _y;
z = _z;
}
bool Trojkat::SprawdzXYZ(float a, float b, float c) {
if ((a > 0) && (b > 0) && (c > 0)) {
if (((a + b) > c) && ((a + c) > b) && ((b + c) > a)) {return true;}
} else {
return false;
}
}
void Trojkat::UstawXYZ(float _x, float _y, float _z) {
if ((SprawdzXYZ(_x, _y, _z) == true)) {
x = _x;
y = _y;
z = _z;
std::cout << "Ustawiono, kolejno x,y,z" << _x << _y << _z;
} else {
std::cout << "Zle wymiary trojkata";
}
}
void Trojkat::ObliczPole() {
float _x = retX();
float _y = retY();
float _z = retZ();
float p = (_x + _y + _z)/2;
float res= sqrt(p * (p - _x) * (p - _y) * (p - _z));
setpole(res);
}
void Trojkat::ObliczObw2() {
float _x = retX();
float _y = retY();
float _z = retZ();
float res = (_x + _y + _z) / 2;
setobw2(res);
}
using namespace std;
int main()
{
Trojkat test;
test.UstawXYZ(3, 4, 5);
test.ObliczPole();
test.ObliczObw2();
cout << endl <<"Pole: "<<test.retpole();
cout << endl << "Obwod: " << test.retobw2();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment