Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <cmath>
- using namespace std;
- class Poligon{
- protected:
- vector<double> x;
- vector<double> y;
- int n;
- public:
- void setPoligon(int r, double s, double t){
- n=r;
- x.push_back(s);
- y.push_back(t);
- }
- };
- class Segitiga : public Poligon{
- private:
- double L[100];
- public:
- double luas(){
- double Det, Luas=0;
- for(int i=0;i<n;i++){
- Det=0;
- Det+=x[i*3]*y[1+(i*3)] + x[2+(i*3)]*y[i*3] + x[1+(i*3)]*y[2+(i*3)] - (x[2+(i*3)]*y[1+(i*3)] + x[i*3]*y[2+(i*3)] + x[1+(i*3)]*y[i*3]);
- L[i]=abs(Det/2);
- Luas+=L[i];
- }
- return Luas/n;
- }
- int besar(){
- int besar=0;
- for(int i=0;i<n;i++){
- if(L[i]>luas()) besar++;
- }
- return besar;
- }
- void print(){
- cout << fixed << setprecision(2) << luas()<< " ";
- }
- void printBesar(){
- cout << besar() << " ";
- }
- };
- class Segiempat : public Poligon{
- private:
- double P[100];
- public:
- double luas(){
- double Px,Py,Pz,Luas=0,index=0;
- for(int i=0;i<n;i++){
- P[i]=0;
- for(int j=0;j<3;j++){
- Px =((x[index+j+1]-x[index+j])*(x[index+j+1]-x[index+j]));
- Py =((y[index+j+1]-y[index+j])*(y[index+j+1]-y[index+j]));
- P[i]+=sqrt(Px+Py);
- }
- Pz=sqrt((x[i*4]-x[(i*4)+3])*(x[i*4]-x[(i*4)+3]) + (y[i*4]-y[(i*4)+3])*(y[i*4]-y[(i*4)+3]));
- P[i]+=Pz;
- Luas+=(P[i]/4)*(P[i]/4);
- index+=4;
- }
- return Luas/n;
- }
- int besar(){
- int besar=0;
- for(int i=0;i<n;i++){
- if(P[i]>luas()) besar++;
- }
- return besar;
- }
- void print(){
- cout << fixed << setprecision(2) << luas() << endl;
- }
- void printBesar(){
- cout << besar() << endl;
- }
- };
- int main (){
- int n,m;
- Segiempat E;
- Segitiga T;
- double x,y;
- cin >> n;
- for(int i=0;i<n*3;i++){
- cin >> x >> y;
- T.setPoligon(n,x,y);
- }
- cin >> m;
- for(int i=0;i<m*4;i++){
- cin >> x >> y;
- E.setPoligon(m,x,y);
- }
- T.print();
- E.print();
- T.printBesar();
- E.printBesar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement