1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
#include <iostream>
#include <stdlib.h>
#include <math.h>
#define n 10 //pososto apo to arxiko emvado
#define m 10 //xrimata gia kathe t.m. se periptwsh pou meta thn meiwsh tou emvadou menoun ligotera apo 100 t.m.
#define y 10 //xrimata gia kathe metro pou vlepei sth thalassa
using namespace std;
int i;
class site
{
char name[30];
int code, vertices, **coordinates;
int plus; //posa t.m. gia na sumplirwthoun 100 wste na vroume to poso pou tha katavallei o idioktitis
site();
public:
float area(); //emvado
float decrease(); //meiwsh arxikou emvadou
int money(); //poso pou prepei na katavallei o idioktitis
void print(); //ektupwsh stoixeiwn
};
site::site()
{
cout<<"Enter name, code and vertices:",'\n';
cin>>name, code, vertices;
coordinates=(int**)malloc(2*sizeof(int)); //mnhmh gia 2 grammes
for (i=0; i<2;i++)
{
coordinates[i]=(int*)malloc(vertices*sizeof(int)); //mnhmh gia 10 kelia se kathe grammh
}
for (i=0; i<vertices; i++)
{
cout<<"Enter coordinates x, y of "<<i<<" vertice",'\n';
cin>>coordinates[0][i]>>coordinates[1][i]; //prwth grammh x, defterh grammh y
}
}
float site::area()
{
float emvado=0;
for (i=0;i<vertices;i++)
{
emvado=emvado+((coordinates[0][i+1]-coordinates[0][i])*(coordinates[1][i+1]+coordinates[1][i]))/2;
}
return emvado;
}
float site::decrease()
{
float decrease;
plus=0;
decrease=area()-n*area();
if (decrease<100)
{
do
{
decrease++;
plus++;
}
while (decrease<100);
}
return decrease;
}
int site::money()
{
int money;
money=m*plus;
return money;
}
void site::print()
{
cout<<"Site stats: \n"<<name<<"\n"<<code<<"\n"<<vertices<<"\n"<<area<<"\n";
cout<<"Area remaining: \n"<<area()-decrease()<<"\n";
cout<<"To be paid: "<<money<<"\n";
}
class sea_site
{
char name[30];
int code, vertices, s_vertices, **coordinates, **coordinates_s;
int plus;
sea_site();
public:
float area(); //emvado
float decrease(); //meiwsh arxikou emvadou
int money(); //poso pou prepei na katavallei o idioktitis
void print(); //ektupwsh stoixeiwn
float mhkos();
};
sea_site::sea_site()
{
cout<<"Enter name, code vertices and sea vertices:",'\n';
cin>>name>>code>>vertices>>s_vertices;
coordinates=(int**)malloc(2*sizeof(int)); //mnhmh gia 2 grammes
coordinates_s=(int**)malloc(2*sizeof(int)); //mnhmh gia suntetagmenes twn korufwn pou vlepoun sth thalassa wste na vroume to mhkos
for (i=0; i<2;i++)
{
coordinates[i]=(int*)malloc(vertices*sizeof(int)); //mnhmh gia "vertices" kelia se kathe grammh
coordinates_s[i]=(int*)malloc(s_vertices*sizeof(int));
}
for (i=0; i<vertices; i++)
{
cout<<"Enter coordinates x, y of "<<i<<" vertice",'\n';
cin>>coordinates[0][i]>>coordinates[1][i]; //prwth grammh x, defterh grammh y
}
for (i=0; i<s_vertices; i++)
{
cout<<"Enter coordinates x, y of"<<i<<" sea vertice \n";
cin>>coordinates_s[0][i]>>coordinates_s[1][i];
}
}
float sea_site::area()
{
float emvado=0;
for (i=0;i<vertices;i++)
{
emvado=emvado+((coordinates[0][i+1]-coordinates[0][i])*(coordinates[1][i+1]+coordinates[1][i]))/2;
}
return emvado;
}
float sea_site::decrease()
{
float decrease;
plus=0;
decrease=area()-n*area();
if (decrease<100)
{
do
{
decrease++;
plus++;
}
while (decrease<100);
}
return decrease;
}
int sea_site::money()
{
int money;
money=m*plus+y*mhkos();
return money;
}
void sea_site::print()
{
cout<<"Site stats: \n"<<name<<"\n"<<code<<"\n"<<vertices<<"\n"<<area<<"\n";
cout<<"Area remaining: \n"<<area()-decrease()<<"\n";
cout<<"To be paid: "<<money<<"\n";
}
float sea_site::mhkos()
{
float mhkos=0;
for (i=0; i<s_vertices; i++)
{
mhkos=mhkos+sqrt((coordinates_s[0][i+1]-coordinates_s[0][i])*(coordinates_s[0][i+1]-coordinates_s[0][i])+((coordinates_s[1][i+1]-coordinates_s[1][i])*(coordinates_s[1][i+1]-coordinates_s[1][i])));
}
return mhkos;
}
void calk(site_n, site_t, sea_site_n, sea_site_t, n, m, y, *total_m, *total_l) //arithmos oikopedwn, pinakas site, arithmos parathalassiwn oikopedwn, pinakas parathalassiwn, pososto x3, sunoliko xrimata, sunolikh gh
{
&total_m=0;
&total_l=0;
for (i=0; i<site_n; i++)
{
&total_m=&total_m+site_t[i].decrease();
&total_l=&total_l+site_t[i].money();
}
for (i=0; i<sea_site_n; i++)
{
&total_m=&total_m+sea_site_t[i].decrease();
&total_l=&total_l+sea_site_l[i].money();
}
}
int main()
{
int site_n, site_sea_n, *total_m, *total_l;
site *site_t;
sea_site *sea_site_t;
cout<<"Enter number of sites and sites by the sea: \n";
cin>>site_n>>site_sea_n
site_t=(site*)malloc(site_n*sizeof(site));
sea_site_t=(sea_site*)malloc(sea_site*sizeof(sea_site));
calk(site_n, site_t, site_sea_n, site_sea_t, n, m, y, *total_m, *total_l);
for (i=0; i<site_n; i++)
{
site_t[i].print();
}
for(i=0; i<sea_site_n; i++)
{
sea_site_t[i].print();
}
}
|