任务一
1 #include <iostream> 2 #include<math.h> 3 #include"Complex.h" 4 using namespace std; 5 Complex::string doc={"a simple class"}; 6 7 Complex::Complex(double r=0,double i=0):real(r),imag(i){} 8 Complex::Complex(const Complex& c):real(c.real),imag(c.imag){}; 9 10 Complex Complex::add(const Complex& c1,const Complex &c2); 11 { 12 Complex c3; 13 c3.real=c1.real+c2.real; 14 c3.imag=c1.imag+c2.imag; 15 return c3; 16 } 17 Complex::Complex(double r=0,double i=0):real(r),imag(i){} 18 Complex::Complex(const Complex& c):real(c.real),imag(c.imag){}; 19 double Complex::get_real(); 20 { 21 return real; 22 } 23 double Complex::get_imag(); 24 { 25 return imag; 26 } 27 Complex Complex::add(const Complex& c); 28 { 29 Complex c2; 30 c2.real=real+c.real; 31 c2.imag=imag+c.imag; 32 return c2; 33 } 34 Complex Complex::add(const Complex& c1,const Complex &c2); 35 { 36 Complex c3; 37 c3.real=c2.real+c1.real; 38 c3.imag=c2.imag+c1.imag; 39 return c3; 40 } 41 bool Complex::is_equal(const Complex&c1,const Complex&c2); 42 { 43 if(c1.real==c2.real) 44 if(c1.imag==c2.imag)return true; 45 46 return false; 47 } 48 bool Complex::is_not_equal(const Complex&c1,const Complex&c2); 49 { 50 if(is_equal())return false; 51 52 return true; 53 } 54 void Complex::output(const Complex&c1,const Complex&c2); 55 { 56 cout<<real<<"+"<<imag<<"i"<<endl; 57 } 58 double Complex::abs(const Complex&c); 59 { 60 return sqrt(c.real*c.real+c.imag*c.imag); 61 } 62 63 64 65 66
1 #programe once 2 3 #include<string> 4 5 class Complex 6 { 7 prviate: 8 static std::string doc; 9 double real,imag; 10 public: 11 12 13 Complex(double r=0,double i=0); 14 Complex(const Complex& c); 15 double get_real(); 16 double get_imag(); 17 Complex add(const Complex& c); 18 friend Complex add(const Complex& c1,const Complex &c2); 19 friend bool is_equal(const Complex&c1,const Complex&c2); 20 friend bool is_not_equal(const Complex&c1,const Complex&c2); 21 friend void output(const Complex&c1,const Complex&c2); 22 friend double abs(const Complex&c); 23 }; 24 25 Complex add(const Complex& c1,const Complex &c2); 26 bool is_equal(const Complex&c1,const Complex&c2); 27 bool is_not_equal(const Complex&c1,const Complex&c2); 28 void output(const Complex&c1,const Complex&c2); 29 double abs(const Complex&c);
#pragma once #include <string> class Fraction { private: int up,down; public: static std::string doc; Fraction(int aa,int bb=1); Fraction(const Fraction& f):a(f.up),b(f.down); int get_up(); int get_down(); Fraction negative() { up=-up; Fraction Fra() return } }
标签:real,opp,imag,Complex,实验,c2,c1,const From: https://www.cnblogs.com/xuyi5448/p/18494456