复数四则运算
请问各位高手,这个程序怎么样改才可以输入一个表达式,然后运行#include<iostream.h>classcomplex{ (){real=imag=0;}complex(doubler,doublei){real=r,imag=i;}complexoperator+(constcomplex&c);complexoperator-(constcomplex&c);complexoperator*(constcomplex&c);complexoperator/(constcomplex&c);friendvoidprint(constcomplex&c); ,imag;};inlinecomplexcomplex::operator+(constcomplex&c){returncomplex(real+c.real,imag+c.imag);}inlinecomplexcomplex::operator-(constcomplex&c){returncomplex(real-c.real,imag-c.imag);}inlinecomplexcomplex::operator*(constcomplex&c){returncomplex(real*c.real-imag*c.imag,real*c.imag+imag*c.real);}inlinecomplexcomplex::operator/(constcomplex&c){returncomplex((real*c.real+imag+c.imag)/(c.real*c.real+c.imag*c.imag),(imag*c.real-real*c.imag)/(c.real*c.real+c.imag*c.imag));}voidprint(constcomplex&c){if(c.imag<0)cout<<c.real<<c.imag<<'i';elsecout<<c.real<<'+'<<c.imag<<'i';}voidmain(){complexcn;constclasscomplex&cn;cout<<"输入表达式"<<endl;cin>>cn;cout<<cn;print(cn);cout<<endl;}
重载运算符>
答:http://wenwen.soso.com/z/q218010441.htm这里有解释详情>>
问:挺简单的一C函数,不过我是初学者,暂时还不会写,请好心人多多帮忙!
答:int mystrlen(char *str) { int n = 0; while (*str) { n++; str++;} return n; } voi...详情>>