求助啊...错误在哪
//complex0.h
#ifndef complex0_h_
#define complex0_h_
class complex{
double x;
double y;
public:
complex() ;
complex(double, double);
~complex() ;
friend complex operator+(complex &, const complex &);//Addtion
complex operator-(const complex &);//Substraction
complex operator*(const complex &);//Multiplication
friend complex operator*(double, const complex &);//Multiplication by double
complex operator~( );//conjugate complex
friend std::istream & operator>>(std::istream &, complex &);
friend std::ostream & operator<<(std::ostream &, const complex &);
}
#endif
//complex0.cpp
#include <iostream>
#include "complex0.h"
using namespace std;
complex::complex( ){x=y=0;}
complex::complex(double a, double b)
{
x=a;
y=b;
}
complex operator+(complex &cp1, const complex& cp2)//Addtion
{
cp1.x+=cp2.x;
cp1.y+=cp2.y;
return cp1;
}
complex complex::operator-(const complex &cp2)//Substraction
{
x-=cp2.x;
y-=cp2.y;
return *this;
}
complex complex::operator*(const complex &cp2)//Multiplication
{
x*=cp2.x;
y*=cp2.y;
return *this;
}
complex operator*(double m, const complex & cp1)//Multiplication by double
{
complex temp;
temp.x=m*cp1.x;
temp.y=m*cp1.y;
return temp;
}
complex complex::operator~( )//conjugate complex
{
x=-x;
y=-y;
return *this;
}
istream & operator>>(istream & is, complex& cp1)
{
cout<<"real: ";
is>>cp1.x;
cout<<"img: ";
is>>cp1.y;
return is;
}
ostream & operator<<(ostream & os, const complex& cp1)
{
os<<"( "<<cp1.x<<" , "<<cp1.y<<"i )";
return os;
}
//complex1.cpp
#include <iostream>
#include <cstring>
#include <string>
#include<limits>
#include <cctype>
#include <fstream>
#include "complex0.h"
using namespace std;
int main( )
{
complex a(3.0, 4.0); // initialize to (3,4i)
complex c;
cout << "Enter a complex number (q to quit):\n";
while (cin >> c)
{
cout << "c is " << c << '\n';
cout << "complex conjugate is " << ~c << '\n';
cout << "a is " << a << '\n';
cout << "a + c is " << a + c << '\n';
cout << "a - c is " << a - c << '\n';
cout << "a * c is " << a * c << '\n';
cout << "2 * c is " << 2 * c << '\n';
cout << "Enter a complex number (q to quit):\n";
}
cout << "Done!\n";
return 0;
}
#ifndef complex0_h_
#define complex0_h_
class complex{
double x;
double y;
public:
complex() ;
complex(double, double);
~complex() ;
friend complex operator+(complex &, const complex &);//Addtion
complex operator-(const complex &);//Substraction
complex operator*(const complex &);//Multiplication
friend complex operator*(double, const complex &);//Multiplication by double
complex operator~( );//conjugate complex
friend std::istream & operator>>(std::istream &, complex &);
friend std::ostream & operator<<(std::ostream &, const complex &);
}
#endif
//complex0.cpp
#include <iostream>
#include "complex0.h"
using namespace std;
complex::complex( ){x=y=0;}
complex::complex(double a, double b)
{
x=a;
y=b;
}
complex operator+(complex &cp1, const complex& cp2)//Addtion
{
cp1.x+=cp2.x;
cp1.y+=cp2.y;
return cp1;
}
complex complex::operator-(const complex &cp2)//Substraction
{
x-=cp2.x;
y-=cp2.y;
return *this;
}
complex complex::operator*(const complex &cp2)//Multiplication
{
x*=cp2.x;
y*=cp2.y;
return *this;
}
complex operator*(double m, const complex & cp1)//Multiplication by double
{
complex temp;
temp.x=m*cp1.x;
temp.y=m*cp1.y;
return temp;
}
complex complex::operator~( )//conjugate complex
{
x=-x;
y=-y;
return *this;
}
istream & operator>>(istream & is, complex& cp1)
{
cout<<"real: ";
is>>cp1.x;
cout<<"img: ";
is>>cp1.y;
return is;
}
ostream & operator<<(ostream & os, const complex& cp1)
{
os<<"( "<<cp1.x<<" , "<<cp1.y<<"i )";
return os;
}
//complex1.cpp
#include <iostream>
#include <cstring>
#include <string>
#include<limits>
#include <cctype>
#include <fstream>
#include "complex0.h"
using namespace std;
int main( )
{
complex a(3.0, 4.0); // initialize to (3,4i)
complex c;
cout << "Enter a complex number (q to quit):\n";
while (cin >> c)
{
cout << "c is " << c << '\n';
cout << "complex conjugate is " << ~c << '\n';
cout << "a is " << a << '\n';
cout << "a + c is " << a + c << '\n';
cout << "a - c is " << a - c << '\n';
cout << "a * c is " << a * c << '\n';
cout << "2 * c is " << 2 * c << '\n';
cout << "Enter a complex number (q to quit):\n";
}
cout << "Done!\n";
return 0;
}
...全文
相关推荐
求助安装好dede2007后,后台登录后出现错误
求助安装好dede2007后,后台登录后出现错误
Python编程基础:错误处理与在线求助
本章介绍了Python编程中遇到错误时如何处理和获取帮助。错误消息的堆栈跟踪部分会指明问题所在,而在线搜索是解决编程疑问的常用手段。章节还强调了提出编程问题时的注意事项,并推荐了有效的提问方式。通过实际编程示例,本章进一步阐述了Python的基础概念,如表达式、运算符和操作数的使用。
求助大佬!coze新手手搓工作流运行错误无法搞定
在coze社区中,用户可以找到类似问题的解决方案,或是直接向经验丰富的社区成员求助。
Springboot_Help_Requests:将文件发送给指导者和/或指导者以进行检查,以帮助解决编码错误
**社区求助**:如果以上步骤无法解决问题,可以在Stack Overflow、GitHub或相关的开发者论坛上发布详细的问题描述,附上必要的代码片段、日志和错误信息,请求社区的帮助。
ligerui 求助
总的来说,对于“ligerui 求助”的问题,建议用户详细描述遇到的问题,包括错误信息、操作步骤和期望的结果,以便更有效地获得帮助。



