Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class GeoException : public exception {
- private:
- double mA, mB, mC;
- public:
- GeoException(double, double, double);
- double getA();
- double getB();
- double getC();
- };
- GeoException::GeoException(double A, double B, double C) : mA(A), mB(B), mC(C) {}
- double GeoException::getA() {
- return mA;
- }
- double GeoException::getB() {
- return mB;
- }
- double GeoException::getC() {
- return mC;
- }
- class Trokut {
- private:
- double mA, mB, mC;
- public:
- Trokut();
- Trokut(double, double, double);
- double povrsina();
- double opseg();
- bool pravokutan();
- };
- Trokut::Trokut() : mA(0), mB(0), mC(0) {}
- Trokut::Trokut(double A, double B, double C) : mA(A), mB(B), mC(C) {
- if (mC >= mA + mB || mB >= mA + mC || mA >= mB + mC) {
- throw GeoException(mA, mB, mC);
- }
- }
- double Trokut::povrsina() {
- double s = (mA + mB + mC) / 2;
- return sqrt(s*(s - mA)*(s - mB)*(s - mC));
- }
- double Trokut::opseg() {
- return mA + mB + mC;
- }
- bool Trokut::pravokutan() {
- if (mC == sqrt(mA * mA + mB * mB)) {
- return true;
- }
- return false;
- }
- int main() {
- try {
- Trokut T1, T2(7, 5, 6);
- cout << "Prvi trokut: " << endl;
- cout << "Opseg: " << T1.opseg() << "\nPovrsina: " << T1.povrsina() << endl;
- cout << "Drugi trokut: " << endl;
- cout << "Opseg: " << T2.opseg() << "\nPovrsina: " << T2.povrsina() << endl;
- if (T2.pravokutan()) {
- cout << "Trokut je pravokutan." << endl;
- }
- else {
- cout << "Trokut nije pravokutan." << endl;
- }
- }
- catch (GeoException& iznimka) {
- cout << "Trokut sa stranicama: " << iznimka.getA() << ", " << iznimka.getB() << ", " << iznimka.getC() << " nije moguc." << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement