所涉及的复数计算器可以进行+ -乘运算2.设计重载函数,要求能接收从键盘输入a+bi形式的复数,在程序中可以识别出实部、虚部并进行赋值3.设计计算器测试程序,对加减法进行测试,要求在两位数以内,对乘法进行测试,乘法要求为一位数的运算。
c.real=real-c2.real;
c.imag=imag-c2.imag;
return c;
}
//----------------------------------------------
Complex Complex::operator*(Complex &c2)
{
Complex c;
c.real=real*c2.real-imag*c2.imag;
c.imag=imag*c2.real+real*c2.imag;
return c;
}
//----------------------------------------------
Complex Complex::operator/(Complex &c2)
{
Complex c;
c.real=(real*c2.real+imag*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag); c.imag=(imag*c2.real-real*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag); return c;
}
//-----------------------------------------------
ostream & operator<<(ostream &output,Complex &c)
{
if(c.imag>=0)
output<<"("<<c.real<<"+"<<c.imag<<"i)";
else
output<<"("<<c.real<<" "<<c.imag<<"i)";
return output;
}
//--------------------------------------------------
istream & operator>>(istream &input,Complex &c)
{
cout<<"请输入一个复数,实部和虚部,中间用空格隔开:";
input>>c.real>>c.imag;
return input;
}
//======================================================================= //=================功能函数(普通函数)的定义============================ //复数加法
void complexAdd()
{
#include<iostream> #include<cmath> #include<cstdlib> #include<cstring> #...{ user=user1; user.nTime++; cout<<"欢迎您再次使用复数计算器!"; ...
复数计算器C++_IT/计算机_专业资料。课程设计报告课程设计题目: 课程设计题目:...c:Crational&):ostream& <<friend>>+operator>>(in:istream&,c:Crational&...
C++课程设计复数计算器_工学_高等教育_教育专区。C++课程设计C++课程设计实验...=(CComplex&com); int operator>(CComplex&com); int operator<(CComplex&...
《C++程序设计实践指导》 * * 第 2 章 2.1 一个复数计算器程序 * * (c) yrmuhon, 2009 2.9 ***/ #include <iostream> #include <cmath> #include ...
C++课程设计一份……... 计算机科学与技术专业 复数计算器 A级 njust_smalllion *** *** 2010 年八月底...
二、课程设计任务及要求 1、 任务: 课程设计选题是 “小型复数计算器” 其...[0]=='c'
C++课程设计报告——复数计算器_工学_高等教育_教育专区。用C++编写简单的复数...=(Complex &c) { if(real==c.real&&imag==c.imag) return 0; else ...
{ Complex a,b,c; //cin>>a; //cout<<a; for(int i=0;;) { cout<<"………欢迎使用复数计算器………"<<endl; cout<<"………"<<endl; cout<...
复数计算器!"<<endl; complex c1,c2,c3; c1.input(); cout<<"c1="; print(c1); c2.input(); cout<<"c2="; print(c2);4; Com[0]=c1;...
c++课程设计 复数计算器 源代码_工学_高等教育_教育专区。亲,自己做的课程...()%20-10; CComplex c(real3,image3),d(real4,image4); op=rand()%3...
热门文档