1.定義復(fù)數(shù)Complex類,使用友元,完成復(fù)數(shù)的加法、減法、乘法和除法運算,以及對復(fù)數(shù)的輸出.
1.定義復(fù)數(shù)Complex類,使用友元,完成復(fù)數(shù)的加法、減法、乘法和除法運算,以及對復(fù)數(shù)的輸出.
其他人氣:788 ℃時間:2020-04-27 00:03:35
優(yōu)質(zhì)解答
#pragma once#include using namespace std;class Complex{public:Complex(double re=0.,double im=0.){real=re;imag=im;}void setreal(const double r);void setimag(const double i);friend Complex operator-(con...我用的VS2010怎么運行不了呢1>e:\編程軟件\自編程序\新程序\新程序\xsjz.cpp(31): fatal error C1083: 無法打開包括文件:“Complex.h”: No such file or directory上面一個是.h頭文件 一個是CPP 實現(xiàn)文件是兩個文件 ?。?!你自己分開一下!?。≈罏槭裁催\行不了了~~~這不是C++寫的吧。。。怎么是in out不是cincout 嗎?LZ 這真是C++寫的受不了等下 我給你改下。。。in out 是i,ostream類型 用來重載輸入輸出的??!下面的代碼 你貼一下自己寫個main函數(shù) #include using namespace std;class Complex{public: Complex(double re=0.,double im=0.) {real=re;imag=im; } void setreal(const double r); void setimag(const double i); friend Complex operator-(const Complex &); friend istream& operator>>(istream &in,Complex &c); friend ostream& operator<<(ostream &,const Complex &); friend Complex operator+(const Complex&,const Complex&); friend Complex operator-(const Complex&,const Complex&); friend Complex operator*(const Complex&,const Complex&); friend Complex operator/(const Complex&,const Complex&); const double getreal(){return real;} const double getimag(){return imag;} ~Complex(void);private: double real; double imag;};Complex::~Complex(void){}inline void Complex::setreal(const double r){real=r;}inline void Complex::setimag(const double i){imag=i;}istream& operator>>(istream &in,Complex &c){ return in>>c.real>>c.imag;}ostream& operator<<(ostream &out,const Complex &c){ if(c.imag<1E-14&&c.imag>-1E-14)return out<-1E-14) return out<0)return out<
我來回答
類似推薦
- 定義一個復(fù)數(shù)類COMPLEX,重載運算符“+”使之用于復(fù)數(shù)的加減運算
- 用java定義一個復(fù)數(shù)類Complex,能夠創(chuàng)建復(fù)數(shù)對象,并且實現(xiàn)復(fù)數(shù)之間的加、減運算
- 定義一個復(fù)數(shù)類Complex,使得下面的代碼能夠工作
- 定義復(fù)數(shù)類complex,并使用友元函數(shù)實現(xiàn)復(fù)數(shù)的加法,減法,乘法,所有函數(shù)都返回c
- 請編寫一個類Complex,定義復(fù)數(shù)的加法、減法、乘法和除法運算,要求在編寫該類時重載這些運算操作符,并重載I/O操作符,
- i believe that that that that that student says is right.
- 薄煙的薄應(yīng)該怎么念?這個字的兩種讀音又該怎樣分辨?
- 一九七九年那是一個春天,有一個老人在中國南海邊……
- i used to think that i could not go on的手語
- 文言文題目【王充市肆博覽】
- 翻譯句子:如果明天下雨怎么辦?用What if.(另外,what if后面用陳述語序,必須用一般現(xiàn)在時態(tài)嗎?)
- 怎樣寫自然景觀