/****************************/
/* クラスと継承 */
/* coded by Y.Suganuma */
/****************************/
#include <iostream>
#include <string>
using namespace std;
class Number
{
protected :
string feat;
public :
string name;
Number(string str = "数") // コンストラクタ
{
name = str;
feat = "数とは,・・・";
}
void out()
{
cout << "Number クラスの定義です\n";
}
};
class Complex : public Number
{
private :
double r_part;
double i_part;
public :
Complex(double x, double y, string str = "複素数") : Number(str) // コンストラクタ
{
r_part = x;
i_part = y;
}
void out()
{
cout << feat << endl;
cout << "(" << r_part << ", " << i_part << ")\n";
}
};
int main()
{
Number y;
cout << y.name << endl;
y.out();
Complex x(1.0, 2.0);
cout << x.name << endl;
x.out();
return 0;
}