Created
March 21, 2017 08:37
-
-
Save splitline/568772d0299997d1dd610348d3fd95a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Point{ | |
public: | |
void Set(double x, double y) ; | |
void Move(double x, double y); | |
void Rotate(); | |
double RetrieveHorizontal()const; | |
double RetrieveVertical()const; | |
private: | |
double _x, _y; | |
}; | |
void Point::Set(double x, double y){ | |
_x=x; | |
_y=y; | |
} | |
void Point::Move(double x, double y){ | |
_x+=x; | |
_y+=y; | |
} | |
void Point::Rotate(){ | |
int t; | |
t=_x; | |
_x=_y; | |
_y=-t; | |
} | |
double Point::RetrieveHorizontal()const{ | |
return _x; | |
} | |
double Point::RetrieveVertical()const{ | |
return _y; | |
} | |
int main(void) { | |
Point point; | |
point.Set(0, 5); | |
cout << point.RetrieveHorizontal() << " " << point.RetrieveVertical() << endl; | |
point.Move(1, 2); | |
cout << point.RetrieveHorizontal() << " " << point.RetrieveVertical() << endl; | |
for (int i = 0; i < 4; i++) { | |
point.Rotate(); | |
cout << point.RetrieveHorizontal() << " " << point.RetrieveVertical() << endl; | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Fraction{ | |
public: | |
double getDouble(); | |
void setNumerator(int numerator); | |
void setDenominator(int denominator); | |
void outputReducedFraction(); | |
private: | |
double _numerator,_denominator; | |
}; | |
double Fraction::getDouble(){ | |
return _numerator/_denominator; | |
} | |
void Fraction::outputReducedFraction(){ | |
int t,a=_numerator,b=_denominator; | |
while ( a != 0 ) { | |
t = a; | |
a = b % a; | |
b = t; | |
} | |
cout << _numerator/b ; | |
if(_denominator/b!=1) cout << "/" << _denominator/b; | |
} | |
void Fraction::setNumerator(int numerator){ | |
_numerator=numerator; | |
} | |
void Fraction::setDenominator(int denominator){ | |
_denominator=denominator; | |
} | |
int main(){ | |
Fraction f1, f2; | |
f1.setNumerator(4); | |
f1.setDenominator(2); | |
cout << f1.getDouble() << endl; | |
f1.outputReducedFraction(); | |
cout << endl; | |
f2.setNumerator(20); | |
f2.setDenominator(60); | |
cout << f2.getDouble() << endl; | |
f2.outputReducedFraction(); | |
cout << endl; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment