struct vector2 p1,p2; float distance; p1.x = 1.0; p1.y = 1.0; p2.x = 2.0; p2.y = 3.0; distance = sqrt(pow(p2.x-p1.x, 2.)+pow(p2.y-p1.y, 2.));
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
char *tm_zone;
long tm_gmtoff;
};
練習問題
運賃の計算で作成したプログラムで受け渡されている
引数、戻り値を全て大域変数にしてプログラムを書きなさい
(大域変数の利用を推奨しているわけでは無いので誤解しないように)
class complex {
double re, im;
public:
complex() { re=0.0; im=0.0; }
complex(double r, double i = 0.0) { re=r; im=i; }
friend double real(const complex&);
friend double imag(const complex&);
friend double abs(complex);
friend double norm(complex);
friend double arg(complex);
friend complex conj(complex);
friend complex cos(complex);
friend complex cosh(complex);
friend complex exp(complex);
friend complex log(complex);
friend complex pow(double, complex);
friend complex pow(complex, int);
friend complex pow(complex, double);
friend complex pow(complex, complex);
friend complex polar(double, double = 0);
friend complex sin(complex);
friend complex sinh(complex);
friend complex sqrt(complex);
friend complex operator+(complex, complex);
friend complex operator-(complex);
friend complex operator-(complex, complex);
friend complex operator*(complex, complex);
friend complex operator/(complex, complex);
friend int operator==(complex, complex);
friend int operator!=(complex, complex);
void operator+=(complex);
void operator-=(complex);
void operator*=(complex);
void operator/=(complex);
};
例
2次元ベクトルとその距離計算を C++ で書いたもの。