ElectriQ: A Benchmark for Assessing the Response Capability of Large Language Models in Power Mar...
2026/10/3 8:32:06
作者 xiesonghua
单位 武汉理工大学
设计一个复数类CComplex,包含实部和虚部的数据,类中对其构造函数进行重载。要求完成类的外部实现。
类定义如下:
class CComplex { double real,imag; public: CComplex(); CComplex(double real1); CComplex(double real1,double imag1); void display(); }; /* 请在这里填写答案 */#include <iostream> using namespace std; int main() { int x,y; cin>>x>>y; // 输入 CComplex A; A.display(); CComplex B(x); B.display(); CComplex C(x,y); C.display(); return 0; }2 3real:0,imag:0 real:2,imag:0 real:2,imag:3参考示例:
CComplex::CComplex(){ real=0; imag=0; } CComplex::CComplex(double real1){ real=real1; imag=0; } CComplex::CComplex(double real1,double imag1){ real=real1; imag=imag1; } void CComplex::display(){ cout<<"real:"<<real<<",imag:"<<imag<<endl; }