Create a gist now

Instantly share code, notes, and snippets.

#include <cmath>
#include <iostream>
struct Coordinate {
void Set( double x, double y );
double GetX(){ return x; }
double GetY(){ return y; }
double Distance();
private:
double x;
double y;
};
void Coordinate::Set( double tX, double tY ){
x = tX;
y = tY;
}
double Coordinate::Distance(){
double t = x * x + y * y;
return std::sqrt( t );
}
int main(){
Coordinate p;//点P
p.Set( 4.0f, 3.0f );
// p.x = 5.0f ←不正なコード
std::cout << "X: " << p.GetX();
std::cout << " / Y: " << p.GetY() << std::endl;
std::cout << "Distance: " << p.Distance() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment