Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Tacka.h
- #pragma once
- class Tacka {
- private:
- int *x;
- int *y;
- public:
- Tacka();
- Tacka(int a, int b);
- void setX(int a);
- void setY(int b);
- int getX();
- int getY();
- void ispisiTacku();
- bool uporedi(Tacka);
- };
- //Tacka.cpp
- #include "Tacka.h"
- #include<iostream>
- using namespace std;
- Tacka::Tacka() {
- x = new int(0);
- y = new int(0);
- }
- Tacka::Tacka(int a, int b) {
- x = new int(a);
- y = new int(b);
- }
- void Tacka::setX(int a) {
- x = new int(a);
- }
- void Tacka::setY(int b) {
- y = new int(b);
- }
- int Tacka::getX() {
- return *x;
- }
- int Tacka::getY() {
- return *y;
- }
- void Tacka::ispisiTacku() {
- cout<<"\n("<<*x<<", "<<*y<<")"<<endl;
- }
- bool Tacka::uporedi(Tacka tacka) {
- return ((*x == *tacka.x) && (*y == *tacka.y));
- }
- //Trougao.h
- #include "Tacka.h"
- class Trougao {
- private:
- Tacka a;
- Tacka b;
- Tacka c;
- double povrsina;
- public:
- Trougao();
- Trougao(Tacka, Tacka, Tacka);
- Trougao(int, int, int, int, int, int);
- void povrsinaT();
- void ispisiT();
- };
- //Trougao.cpp
- #include "Trougao.h"
- #include<iostream>
- #include<cmath>
- using namespace std;
- Trougao::Trougao() {
- a = Tacka(0, 0);
- b = Tacka(0, 5);
- c = Tacka(5, 0);
- }
- Trougao::Trougao(Tacka tacka, Tacka tacka1, Tacka tacka2) {
- a = tacka;
- b = tacka1;
- c = tacka2;
- }
- Trougao::Trougao(int x1, int y1, int x2, int y2, int x3, int y3) {
- a = Tacka(x1, y1);
- b = Tacka(x2, y2);
- c = Tacka(x3, y3);
- }
- void Trougao::povrsinaT() {
- double AB, BC, AC, s;
- AB = sqrt(pow(a.getX() - b.getX(), 2) + pow(a.getY() - b.getY(), 2));
- BC = sqrt(pow(b.getX() - c.getX(), 2) + pow(b.getY() - c.getY(), 2));
- AC = sqrt(pow(a.getX() - c.getX(), 2) + pow(a.getY() - c.getY(), 2));
- s = (AB + BC + AC) / 2;
- povrsina = sqrt(s * (s - AB) * (s - BC) * (s - AC));
- }
- void Trougao::ispisiT() {
- cout << "\n{A(" << a.getX() << ", " << a.getY()
- << "), B(" << b.getX() << ", " << b.getY()
- << "), C(" << c.getX() << ", " << c.getY()
- << ") : Povrsina = " << povrsina << " }" << endl;
- }
- //Pravougaonik.h
- #include "Tacka.h"
- class Pravougaonik {
- private:
- Tacka t1;
- Tacka t2;
- Tacka t3;
- Tacka t4;
- public:
- Pravougaonik(Tacka a, Tacka b, Tacka c, Tacka d);
- Pravougaonik();
- Pravougaonik(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
- double Povrsina();
- void ispisP();
- };
- //Pravougaonik.cpp
- #include "Pravougaonik.h"
- #include <iostream>
- #include <cmath>
- using namespace std;
- Pravougaonik::Pravougaonik(Tacka a, Tacka b, Tacka c, Tacka d){
- t1 = a;
- t2 = b;
- t3 = c;
- t4 = d;
- }
- Pravougaonik::Pravougaonik() {
- t1.setX(0); t1.setY(0);
- t2.setX(0); t2.setY(6);
- t3.setX(5); t3.setY(6);
- t4.setX(5); t4.setY(0);
- }
- Pravougaonik::Pravougaonik(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
- t1.setX(x1); t1.setY(y1);
- t2.setX(x2); t2.setY(y2);
- t3.setX(x3); t3.setY(y3);
- t4.setX(x4); t4.setY(y4);
- }
- double Pravougaonik::Povrsina() {
- double T12, T14, T23, T24, T34, s1, s2, p1, p2;
- T12 = sqrt(pow(t1.getX() - t2.getX(),2) + pow(t1.getY() - t2.getY(),2));
- T14 = sqrt(pow(t1.getX() - t4.getX(),2) + pow(t1.getY() - t4.getY(),2));
- T23 = sqrt(pow(t2.getX() - t3.getX(),2) + pow(t2.getY() - t3.getY(),2));
- T24 = sqrt(pow(t2.getX() - t4.getX(),2) + pow(t2.getY() - t4.getY(),2));
- T34 = sqrt(pow(t3.getX() - t4.getX(),2) + pow(t3.getY() - t4.getY(),2));
- s1 = (T12 + T14 + T24)/2;
- s2 = (T23 + T34 + T24)/2;
- p1 = sqrt(s2 * (s1 - T12) * (s1 - T14) * (s1 - T24));
- p2 = sqrt(s2 * (s2 - T23) * (s2 - T34) * (s2 - T24));
- return p1+p2;
- }
- void Pravougaonik::ispisP() {
- cout<<"\nPovrsina je "<<this->Povrsina()<<endl;
- }
- //Main.cpp
- #include <iostream>
- #include "Tacka.h"
- #include "Trougao.h"
- #include "Pravougaonik.h"
- using namespace std;
- int main() {
- Tacka t1;
- Tacka t2 = Tacka(3,4);
- int x1;
- int y1;
- cout<<"Tacke - pocetno stanje:"<<endl;
- t1.ispisiTacku();
- t2.ispisiTacku();
- t1.setX(5);
- t2.setY(9);
- cout<<"Nakon izmene:"<<endl;
- t1.ispisiTacku();
- t2.ispisiTacku();
- x1 = t1.getX();
- y1 = t1.getY();
- cout<<"\nx1: "<<x1<<endl<<"y1: "<<y1<<endl;
- if(t1.uporedi(t2) == true)
- cout<<"Iste"<<endl;
- else
- cout<<"Razlicite"<<endl;
- //Drugi zadatak
- Tacka tacka1 = Tacka(4,2);
- Tacka tacka2 = Tacka(3,4);
- Tacka tacka3 = Tacka(2,2);
- Trougao trougao1 = Trougao(tacka1, tacka2, tacka3);
- Trougao trougao2;
- trougao1.povrsinaT();
- trougao2.povrsinaT();
- cout<<"Prvi trougao: "<<endl;
- trougao1.ispisiT();
- cout<<"Drugi trougao: "<<endl;
- trougao2.ispisiT();
- //Treci zadatak
- Pravougaonik pravougaonik;
- pravougaonik.ispisP();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement