作业帮 > 综合 > 作业

实现复数的+、-、*、/运算.要求:1.+、*为类运算符; 2.-、/为友元运算符

来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/04/19 15:36:45
实现复数的+、-、*、/运算.要求:1.+、*为类运算符; 2.-、/为友元运算符
实现复数的+、-、*、/运算.
要求:
1.+、*为类运算符;
2.-、/为友元运算符;
3.复数的实部和虚部为实数;
4.输入输出格式如下:
请输入一个复数的实部 虚部
1 1
请输入一个复数的实部 虚部
2 2
实现复数的+、-、*、/运算.要求:1.+、*为类运算符; 2.-、/为友元运算符
#include<iostream>
using namespace std;
// 声明一个共同的基类Person
class Person
{
protected:
float age;
char name[20], sex;
public:
Person()
{
cin >> name >> age >> sex;
}
void output()   // 定义信息输出函数output
{
cout << "  " << name << "  " << sex << "  " << age;
}
};
// 声明虚基类Person的派生类——大学生类Student
class Student:virtual public Person
{
protected:
char major[20];
public:
Student()
{
cin >> major;
}
void printf()
{
cout << endl << endl << "";
}
};
int main()
{
cout << "Please input a student information:" << endl << "Name  Age  Sex  Major" << endl;
Student a;
cout << endl<<"Please input a employee information:" << endl << "Name  Age  Sex  Department" << endl;
Emploree b;
cout << endl << "Please input a working student:" << endl << "Name  Age  Sex  Department  Tutor" << endl;
E_student c;
a.printf();
b.printf();
    c.printf();
return 0;
}