0% found this document useful (0 votes)
23 views4 pages

MIPS

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

MIPS

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#ifndef COORDINATE_H_

#define COORDINATE_H_
#include<iostream>
using namespace std;
class Coordinate
{
private:
int x; // abscissa
int y; // ordinate
public:
Coordinate();
Coordinate(int a,int b);
int GetterX();
int GetterY();
void SetterX(int a);
void SetterY(int b);
void MoveCoordinate(int a,int b);
//void DrawingCoordinate() -> library is not supported
friend ostream & operator<<(ostream & os,Coordinate & Coor);
friend istream & operator>>(istream & is,Coordinate & Coor);
~Coordinate();
};
#endif

#include<iostream>
#include"Coordinate.h"
using namespace std;

Coordinate::Coordinate(){
SetterX(0);
SetterY(0);
}
Coordinate::Coordinate(int a,int b){
SetterX(a);
SetterY(b);
}
int Coordinate::GetterX(){
return x;
}
int Coordinate::GetterY(){
return y;
}
void Coordinate::SetterX(int a){
x=a;
}
void Coordinate::SetterY(int b){
y=b;
}
void Coordinate::MoveCoordinate(int a,int b){
SetterX(GetterX()+a);
SetterY(GetterY()+b);
}
//void DrawingCoordinate() -> library is not supported
ostream & operator<<(ostream & os,Coordinate & Coor){
os<<"( "<<Coor.GetterX()<<" , "<<Coor.GetterY()<<" )";
return os;
}
istream & operator>>(istream & is,Coordinate & Coor){
is>>Coor.x>>Coor.y;
return is;
}
Coordinate::~Coordinate(){
}

#include<iostream>
#include"Coordinate.h"
using namespace std;
int main(){
Coordinate Coor1; //call default constuctor
Coordinate Coor2(2,3); //Call contructor
cout<<"Show coordinate 1: "<<Coor1<<endl;
cout<<"Show coordinate 2:"<<Coor2<<endl;
cout<<"Set value to coordinate 1 :";
cin>>Coor1;
cout<<"Move coordinate 2 (-5,7): "<<endl;
Coor2.MoveCoordinate(-5,7);
cout<<"Show coordinate 1: "<<Coor1<<endl;
cout<<"Show coordinate 2:"<<Coor2<<endl;
return 0;
}

#ifndef MULTIANGLE_H_
#define MULTIANGLE_H_
#include"Coordinate.h"
#include<iostream>
class MultiAngle
{
private:
Coordinate *coor;
int NumberOfAngle;
public:
MultiAngle(int n);
void MoveMultiAngle(double a,double b);
void ZoomMultiAngle(double k);
void RotateMultiAngle(double angle);
void InputMultiAngle();
friend ostream & operator<<(ostream & os, MultiAngle & Tri);
//void DrawingMultiAngle() -> library is not supported
~MultiAngle();
};
#endif

#include"MultiAngle.h"
#include<iostream>
#include<cmath>
#define PI 3.1416
using namespace std;

MultiAngle::MultiAngle(int n){
this->NumberOfAngle=n;
this->coor=new Coordinate[this->NumberOfAngle];
for(int i =0;i<this->NumberOfAngle;i++){
this->coor[i].SetterX(0);
this->coor[i].SetterY(0);
}
}
void MultiAngle::MoveMultiAngle(double a,double b){
for(int i=0;i<this->NumberOfAngle;i++){
this->coor[i].MoveCoordinate(a,b);
}
}

void MultiAngle::ZoomMultiAngle(double k){


for(int i=0;i<this->NumberOfAngle;i++){
this->coor[i].SetterX(this->coor[i].GetterX()*k);
this->coor[i].SetterY(this->coor[i].GetterY()*k);
}
}

void MultiAngle::RotateMultiAngle(double angle){


angle=angle*PI/180;
for(int i=0;i<this->NumberOfAngle;i++){
int a=this->coor[i].GetterX();
int b =this->coor[i].GetterY();
this->coor[i].SetterX(a*cos(angle)-b*sin(angle));
this->coor[i].SetterY(a*sin(angle)+b*cos(angle));
}
}
void MultiAngle::InputMultiAngle(){
using std::cout;
using std::cin;
cout<<"("<<this->NumberOfAngle<<"):"<<endl;
for(int i=0;i<this->NumberOfAngle;i++){
cout<<"Input coordinate "<<i+1<<": ";
cin>>this->coor[i];
}
}
ostream & operator<<(ostream & os, MultiAngle & Mul){
using std::endl;
os<<"Multiangle with "<<Mul.NumberOfAngle<<endl;
for(int i=0;i<Mul.NumberOfAngle;i++){
os<<Mul.coor[i]<<" ";
}
return os;
}
MultiAngle::~MultiAngle(){
this->NumberOfAngle=0;
delete [] this->coor;
}
#include<iostream>
#include"MultiAngle.h"
using namespace std;

int main(){
MultiAngle MultiAngleA(3); //constructor 3 angle
MultiAngle MultiAngleB(4); //constructor 4 angle
cout<<"Show MultiAngle A (after constructor): "<<MultiAngleA<<endl;
cout<<"Show MultiAngle B (after constrcutor):"<<MultiAngleB<<endl;
cout<<"Set MultiAngle A ";
MultiAngleA.InputMultiAngle();
cout<<"Move MultiAngle 2 (-5,7)!"<<endl;
MultiAngleB.MoveMultiAngle(-5,7);
cout<<"Show MultiAngle A (after set angle): "<<MultiAngleA<<endl;
cout<<"Show MultiAngle B (after move (-5,7)):"<<MultiAngleB<<endl;
cout<<"Zoom in 5 value MultiAngle A! "<<endl;
MultiAngleA.ZoomMultiAngle(5);
cout<<"Rotate MultiAngle B 30 degree!"<<endl;
MultiAngleB.RotateMultiAngle(90);
cout<<"Show MultiAngle A (after Zoom in 5): "<<MultiAngleA<<endl;
cout<<"Show MultiAngle B (after Rotate 30 degree):"<<MultiAngleB<<endl;
return 0;
}

You might also like