1)编写复数类,重载加法+、减法-、乘法*等运算符,其中加法+为友元函数,其他为复数类成员函数 2)设计评
1)编写复数类,重载加法+、减法-、乘法*等运算符,其中加法+为友元函数,其他为复数类成员函数
2)设计评选优秀学生和优秀教师的程序:当输入一系列教师或学生的记录后,可将优秀学生及优秀教师的姓名列出来.要求设计如下三个类:
1.类Base:包含学生和教师的共有信息、虚函数isgood()
2.类Student:如果考试成绩超过90分,则isgood()返回best
3.类Teacher:如果一年课时数超过400学时,则isgood()返回best
用虚函数的 好的我再加分
人气:108 ℃ 时间:2020-05-04 22:20:26
解答
第一题
class Complex
{
public:
Complex():real(0),imag(0) {}
Complex(double r,double i):real(r),imag(i) {}
friend Complex operator + (Complex &,Complex &);
Complex operator - ( Complex &);
Complex operator * ( Complex &);
void display();
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{
return Complex(c1.real+c2.real,c1.imag+c2.imag);
}
Complex Complex::operator - (Complex &c)
{
return Complex(real-c.real,imag-c.imag);
}
Complex Complex::operator * ( Complex &c)
{
Complex temp;
temp.real = real * c.real - imag * c.imag;
temp.imag = real * c.imag + c.real * imag;
return temp;
}
void Complex::display()
{
cout
推荐
- 14、设计一个完整的复数complex类,要求利用运算符重载实现复数的加法(+)、减法(-)、乘法(*)运算
- 定义复数类complex,并使用友元函数实现复数的加法,减法,乘法,所有函数都返回c
- C++定义描述复数的结构体类型变量,是想复数的输入输出.设计三个函数实现复数的加法,减法和乘法运算.
- Drren,my friend from San Francisco,is coming to visit me.谁能给我解释下为什么不是be from 或者come from
- 解答题,当a>b>0,比较a+2和b-1的大小
- 2100年有多少天A 364天还是366天还是C 365天
- 实数abc,满足a>b>c,且a+b+c=1,a^2+b^2+c^2=1,求证a+b大于1小于4/3
- 郑和下西洋时去过哪些国家?
猜你喜欢
- 阅读理解Jane was a nurse.When she came to our house with some beautiful flowers in her hand,she smiled and said,“I’m here to
- 西方经济学作业4中的计算题
- 已知函数y=kx²-6k+6;[1]当k为何值时,为正比例函数了【2】当k为何值时,
- 谁能给我几道二元一次方程组的题,只要计算,最好简单点,但也别但简单了!
- 一条绳子,剪去全长的60%,还剩下12米,原来绳子长多少米?
- 二人同心,其利断金;同心之言,其臭如兰.
- 1;一个广场上有10个同样的花坛,每个花坛的高是0.9米,底面是边长为1.2米的正方形,四周用木板围成,中
- I don't want to be the third wheel.