Всем спасибо. Класс написал, вот код, если кому интересно:
Код:
#include <iostream.h>
const SIZE = 100;
struct Item {
float x;
float y;
int n;
};
class O {
private:
Item a[SIZE];
void create(Item &x) {x.n = 0;}
public:
O();
O(float[],float[],int);
O operator+=(Item);
void show(int) ;
void center(int);
void povorot(int, int, float, float);
void peremeshenie(int, float, float);
void operator [] (int);
friend ostream& operator<<(ostream&, O&);
friend istream& operator>>(istream&, O&);
};
O::O() {
for (int i = 0; i < SIZE; i++) create(a[i]);
}
O::O(float x1[], float y1[], int num) {
for (int i = 0; i < num; i++){
a[i].x=x1[i];
a[i].y=y1[i];
a[i].n=num;
}
}
void O::show(int num){
cout<<endl<<"Mnogougolnik s vershinami:\n";
for (int i=0; i<num; i++){
cout<<"("<<a[i].x<<","<<a[i].y<<"), ";
}
}
void O::center(int num){
cout<<endl<<"Mnogougolnik s koordinatami centra tyazesti:\n";
float x=0,y=0;
for (int i=0; i<num; i++){
x=x+a[i].x;
y=y+a[i].y;
}
x=x/num;
y=y/num;
cout<<"("<<x<<","<<y<<")"<<endl;
}
void O::povorot(int num, int ugol, float x, float y){
float q,w;
for (int i=0;i<num;i++){
if (ugol==90){
q=x+(y-a[i].y);
w=y+(a[i].x-x);
cout<<"("<<q<<","<<w<<") ";
}
if (ugol==180){
q=x+(x-a[i].x);
w=y+(y-a[i].y);
cout<<"("<<q<<","<<w<<") ";
}
if (ugol==270){
q=x+(a[i].y-y);
w=y+(x-a[i].x);
cout<<"("<<q<<","<<w<<") ";
}
}
}
void O::peremeshenie(int num, float x, float y){
for (int i=0; i<num; i++)
//float q=a[i].x+x, w=
cout<<"("<<a[i].x+x<<","<<a[i].y+y<<") ";
}
void O::operator [] (int num){
cout<<"("<<a[num].x<<","<<a[num].y<<") ";
}
O O::operator +=(Item item){
for (int i=0; i<SIZE; i++){
if (a[i].n==-858993460||a[i].n==0) {
a[i]=item;
break;
}
}
return *this;
}
ostream& operator<<(ostream& os, O& P){
for (int i=0; i<SIZE; i++){
if (P.a[i].n>0){
os<<"("<<P.a[i].x<<","<<P.a[i].y<<"), ";}
}
return os;
}
istream& operator>>(istream& is, O& P){
Item item;
int kol=0;
cout<<"Please, enter number of corners:\n"<<"->";
cin>>kol;
cout<<"Please, enter a kordinati\n";
for (int i=0;i<kol;i++){
cout<<"Enter a "<<i<<" koord x\n"<<"->";
cin>>item.x;
cout<<"Enter a "<<i<<" koord y\n"<<"->";
cin>>item.y;
item.n=kol;
P+=item;
}
cout<<"New mnogoug sformirovan\n";
return is;
}
void main() {
int choice, choise2=-1;
O P;
Item item;
int kol=0;
float xx[SIZE], yy[SIZE], povorot_x, povorot_y, rv_x,rv_y;
int i=0;
do {
cout<<"\nPlease, select a choise"<<endl;
cout << "1.New"<<endl<<"2.Add a mnogoug"<<endl<<"3.Vivod koordinat\n"<<"4.Opredelenie centra tyazesti\n"<<"5.Povorot figuri na ugol kratnii 90\n"<<"6.Peremeshenie\n"<<"7.Vivod koordinat vershin\n"<<"8.Dobavlenie tochki (+=)\n";
cout<<"9.Exit\n";
cin >> choice;
cout << endl;
switch (choice) {
case 1:
P = O();
cout<<"New pustoy mnogoug is created"<<endl;
break;
//////////////////
case 2:
cin>>P;
break;
/////////////////////////
case 3:
//P.show(kol);
cout<<P;
break;
////////////////////////
case 4:
P.center(kol);
break;
////////////////////////
case 5:
cout<<"Vvedite koordinati tochki, otnositelno kotoroy nuzno osushestvit povorot\n";
cout<<"X=";
cin>>povorot_x;
cout<<"Y=";
cin>>povorot_y;
cout<<"Viberite ugol:\n1.90 gradusov\n2.180 gradusov\n3.270 gradusov\n";
cin>>choise2;
switch (choise2) {
case 1:
cout<<"1.90 gradusov"<<endl;
P.povorot(kol,90,povorot_x,povorot_y);
break;
////////
case 2:
cout<<"2.180 gradusov"<<endl;
P.povorot(kol,180,povorot_x,povorot_y);
break;
////////
case 3:
cout<<"3.270 gradusov"<<endl;
P.povorot(kol,270,povorot_x,povorot_y);
break;
////////
}
break;
/////////////////////////
case 6:
cout<<"Peremeshenie na radius-vector\nVvedite koordinati radius-vectora:\nX=";
cin>>rv_x;
cout<<"Y=";
cin>>rv_y;
P.peremeshenie(kol,rv_x,rv_y);
break;
////////////////////////
case 7:
cout<<"Vvedite nomer vershini\n->";
cin>>rv_x;
P[rv_x];
break;
////////////////////////
case 8:
cout<<"Please, enter a kordinati\n X=";
cin>>item.x;
cout<<"Y=";
cin>>item.y;
item.n=1;
P+=item;
kol++;
break;
}
}
while (choice != 9);
}