




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、 中南大學(xué)高級程序設(shè)計實(shí)踐(C+)課程設(shè)計報告題 目 復(fù)數(shù)計算器 學(xué)生姓名 曾立弘 指導(dǎo)教師 陳麗萍 學(xué) 院 信息科學(xué)與工程學(xué)院 專業(yè)班級 電子信息工程 1401 班 完成時間 2015年6月8日 星期一 目錄第一章 需求分析.第1頁第二章 概要設(shè)計.第2頁第三章 詳細(xì)設(shè)計.第4頁第四章 調(diào)試分析.第21頁第五章 測試結(jié)果.第25頁第六章 課程設(shè)計總結(jié).第36頁第七章 參考文獻(xiàn).第37頁第八章 附錄.第37頁 C+程序設(shè)計之復(fù)數(shù)計算器 第一章 需求分析第一章 需求分析1.1程序設(shè)計的任務(wù)11.1編程目的1.本次程序設(shè)計的目的運(yùn)用面向?qū)ο蟪绦蛟O(shè)計知識,利用C+語言設(shè)計和實(shí)現(xiàn)一個復(fù)數(shù)計算器,要求具
2、備如下主要功能:(1)建立實(shí)數(shù)類、復(fù)數(shù)類(2)實(shí)現(xiàn)實(shí)數(shù)、復(fù)數(shù)信息的初始化(3)實(shí)現(xiàn)實(shí)數(shù)的加、減、乘、除、自增、自減、求平方、二次方根等操作(4)實(shí)現(xiàn)復(fù)數(shù)的加、減、乘、除、取模、求平方、求共軛復(fù)數(shù)、求單個復(fù)數(shù)的向量角、求兩個復(fù)數(shù)的夾角等運(yùn)算(5)實(shí)現(xiàn)實(shí)數(shù)、復(fù)數(shù)信息的輸出1.1.2編程要求在實(shí)現(xiàn)過程中,需利用面向?qū)ο蟪绦蛟O(shè)計理論的基礎(chǔ)知識,充分體現(xiàn)出C+語言關(guān)于類、繼承、封裝與多態(tài)等核心概念,每一個類應(yīng)包含數(shù)據(jù)成員和成員函數(shù)。1.1.3數(shù)據(jù)范圍數(shù)據(jù)輸入的形式為float型,輸出形式亦是float型,數(shù)據(jù)(實(shí)數(shù)、復(fù)數(shù)的實(shí)部、虛部)范圍是-2128 +2128,也即-3.40E+38 +3.40E+3
3、8。1.2本程序能實(shí)現(xiàn)的功能1.2.1實(shí)數(shù)類(Complex)所實(shí)現(xiàn)的功能:實(shí)數(shù)的加法運(yùn)算、減法運(yùn)算、乘法運(yùn)算、除法運(yùn)算、前置自增運(yùn)算、后置自增運(yùn)算、前置自減運(yùn)算、后置自減運(yùn)算、求平方運(yùn)算、求平方根運(yùn)算;1.2.2復(fù)數(shù)類(Complex1)所實(shí)現(xiàn)的功能:復(fù)數(shù)的加法運(yùn)算、減法運(yùn)算、乘法運(yùn)算、除法運(yùn)算、模長運(yùn)算、求平方運(yùn)算、共軛復(fù)數(shù)運(yùn)算、求單個復(fù)數(shù)的向量角運(yùn)算、求兩個復(fù)數(shù)的夾角運(yùn)算。1.2.3主函數(shù)所能實(shí)現(xiàn)的功能1.提供給操作者操作數(shù)據(jù)的類型(實(shí)數(shù)還是復(fù)數(shù))的標(biāo)識;2.操作者選擇數(shù)據(jù)類型后,提供運(yùn)算類型操作的標(biāo)識;3.運(yùn)用指針調(diào)用兩個類的各成員函數(shù)分別完成各項(xiàng)計;第52頁 C+程序設(shè)計之復(fù)數(shù)計算器
4、 第二章 概要設(shè)計 第二章 概要設(shè)計2.1構(gòu)成部分2.1.1系統(tǒng)由三部分構(gòu)成:實(shí)數(shù)類(Complex)、復(fù)數(shù)類(Complex1)、主函數(shù)main。2.1.2.構(gòu)成部分關(guān)系復(fù)數(shù)類(Complex1)由實(shí)數(shù)類(Complex)派生而來,其中兩者成員函數(shù)中的enter(輸入數(shù)據(jù))函數(shù)是虛函數(shù),用以實(shí)現(xiàn)多態(tài)性。主函數(shù)main通過指針調(diào)用實(shí)數(shù)類(Complex)、復(fù)數(shù)類(Complex1)分別完成實(shí)數(shù)運(yùn)算、復(fù)數(shù)運(yùn)算。2.1.3.類層次實(shí)數(shù)類是父類,復(fù)數(shù)類是子類。2.2主程序流程以及程序模塊之間的調(diào)用關(guān)系如圖2.21所示:輸入flag判斷flag判斷wflag=1flag=2實(shí)數(shù)運(yùn)算復(fù)數(shù)運(yùn)算判斷v w=
5、3 w=4 w=5 w=6 w=12 v=3 v=4 v=5 v=6 v=11乘法運(yùn)算減法運(yùn)算加法運(yùn)算求復(fù)數(shù)間夾角除法運(yùn)算乘法運(yùn)算減法運(yùn)算加法運(yùn)算求平方運(yùn)算除法運(yùn)算圖2.2-1主程序流程以及程序模塊之間的調(diào)用關(guān)系圖注:圖2.2-1中沒有畫出1. flag=0時退出系統(tǒng);2. flag不等于0,1,2時出現(xiàn)錯誤提示語句的選擇結(jié)構(gòu);3. w,v在選擇范圍之外時出現(xiàn)錯誤提示語句的選擇結(jié)構(gòu)。4. 特殊處理:除法運(yùn)算分母為0;求二次方根數(shù)為負(fù)數(shù);求單個復(fù)數(shù)夾角時判斷象限的過程。 C+程序設(shè)計之復(fù)數(shù)計算器 第三章 詳細(xì)設(shè)計 第三章 詳細(xì)設(shè)計3.1類層次中各個類的描述3.1.1.實(shí)數(shù)類(Complex)私有
6、部分僅數(shù)據(jù):float型數(shù)據(jù) real;公共部分包括12個成員函數(shù),分別是:類的構(gòu)造函數(shù):Complex()實(shí)數(shù)加法運(yùn)算函數(shù): Complex operator+(Complex &c1)實(shí)數(shù)減法運(yùn)算函數(shù):Complex operator-(Complex &c1)實(shí)數(shù)乘法運(yùn)算函數(shù):Complex operator*(Complex &c1)實(shí)數(shù)除法運(yùn)算函數(shù):Complex operator/(Complex &c1)實(shí)數(shù)前置自增函數(shù):Complex operator+()實(shí)數(shù)后置自增函數(shù):Complex operator+(int)實(shí)數(shù)前置自減函數(shù):Compl
7、ex operator-()實(shí)數(shù)后置自減函數(shù):Complex operator-(int)實(shí)數(shù)求平方根函數(shù):float RootOfTwo()實(shí)數(shù)求平方函數(shù):float Square()實(shí)數(shù)輸入數(shù)據(jù)函數(shù):virtual void enter()3.1.2.復(fù)數(shù)類(Complex1)私有部分僅數(shù)據(jù)成員float 型數(shù)據(jù)real和float 型數(shù)據(jù)imag,二者分別代表復(fù)數(shù)的實(shí)部和虛部;公共部分包含11個成員函數(shù),分別是:類的構(gòu)造函數(shù):Complex1()復(fù)數(shù)加法運(yùn)算函數(shù):Complex1 operator+(Complex1 &c1)復(fù)數(shù)減法運(yùn)算函數(shù):Complex1 operator-
8、(Complex1 &c1)復(fù)數(shù)乘法運(yùn)算函數(shù): Complex1 operator*(Complex1 &c1)復(fù)數(shù)除法運(yùn)算函數(shù):Complex1 operator/(Complex1 &c1)復(fù)數(shù)求模長函數(shù):float Length()復(fù)數(shù)求平方函數(shù):Complex1 Square1()求共軛復(fù)數(shù)函數(shù):Complex1 Conjugate()復(fù)數(shù)求角度函數(shù):float Angle1()復(fù)數(shù)間求角度函數(shù):float Angle2(Complex1 &c1)復(fù)數(shù)輸入數(shù)據(jù)函數(shù):void enter()3.2類中各成員函數(shù)的定義3.2.1實(shí)數(shù)類(Complex)1 類
9、的構(gòu)造函數(shù) 函數(shù)體部分:Complex();2實(shí)數(shù)加法運(yùn)算函數(shù)函數(shù)體部分Complex operator+(Complex &c1)Complex c;cout<<"the result is: "<<endl;c.real=real+c1.real;cout<<real<<"+"<<c1.real<<"="<<c.real<<endl;return c;3實(shí)數(shù)減法運(yùn)算函數(shù)函數(shù)體部分Complex operator-(Complex
10、 &c1)Complex c;cout<<"the result is: "<<endl;c.real=real-c1.real;cout<<real<<"-"<<c1.real<<"="<<c.real<<endl;return c;4實(shí)數(shù)乘法運(yùn)算函數(shù)函數(shù)體部分Complex operator*(Complex &c1)Complex c;c.real=real*c1.real;cout<<"the
11、result is: "<<endl;cout<<real<<"*"<<c1.real<<"="<<c.real<<endl;return c;5實(shí)數(shù)除法運(yùn)算函數(shù)函數(shù)體部分Complex operator/(Complex &c1)Complex c;cout<<"the result is: "<<endl;c.real=real/c1.real;cout<<real<<"/
12、"<<c1.real<<"="<<c.real<<endl;return c;6實(shí)數(shù)前置自增函數(shù)函數(shù)體部分Complex operator+() cout<<"the result is: "<<endl;cout<<"+"<<real;+real;cout<<"="<<real<<endl;return *this;7實(shí)數(shù)后置自增函數(shù)函數(shù)體部分Complex operato
13、r+(int)Complex temp(*this);cout<<"the result is: "<<endl;cout<<real<<"+"real+;cout<<"="<<real-1<<endl;cout<<real<<endl;return temp;8實(shí)數(shù)前置自減函數(shù)函數(shù)體部分Complex operator-()cout<<"the result is: "<<endl;
14、cout<<"-"<<real;-real;cout<<"="<<real<<endl;return *this;9實(shí)數(shù)后置自減函數(shù)函數(shù)體部分Complex operator-(int)Complex temp(*this);cout<<"the result is: "<<endl;cout<<real<<"-"real-;cout<<"="<<real+1<
15、;<endl;cout<<real<<endl;return temp;10實(shí)數(shù)求平方根函數(shù)函數(shù)體部分float RootOfTwo()Complex c;if(real<0)cout<<"the number is wrong!"<<endl;elsecout<<"the result is: "<<endl;c.real=sqrt(real);cout<<"sqrt"<<real<<"="&l
16、t;<c.real<<endl;return c.real;11實(shí)數(shù)求平方函數(shù)函數(shù)體部分float Square()Complex c;cout<<"the result is: "<<endl;c.real=real*real;cout<<"square"<<real<<"="<<c.real<<endl;return c.real;12實(shí)數(shù)輸入數(shù)據(jù)函數(shù)(虛函數(shù))函數(shù)體部分virtual void enter()cin>>
17、;real;3.2.2復(fù)數(shù)類(Complex1) 1.類的構(gòu)造函數(shù) 函數(shù)體部分 Complex1(); 2. 復(fù)數(shù)加法運(yùn)算函數(shù)函數(shù)體部分Complex1 operator+(Complex1 &c1)Complex1 c;cout<<"the result is: "<<endl;c.real=real+c1.real;c.imag=imag+c1.imag;cout<<"("<<real<<"+"<<imag<<"j"&l
18、t;<")"<<"+"<<"("<<c1.real<<"+"<<c1.imag<<"j"<<")"<<"="<<"("<<c.real<<"+"<<c.imag<<"j"<<")"<<endl;
19、return c;3復(fù)數(shù)減法運(yùn)算函數(shù)函數(shù)體部分Complex1 operator-(Complex1 &c1)Complex1 c;cout<<"the result is: "<<endl;c.real=real-c1.real;c.imag=imag-c1.imag;cout<<"("<<real<<"+"<<imag<<"j"<<")"<<"-"<&
20、lt;"("<<c1.real<<"+"<<c1.imag<<"j"<<")"<<"="<<"("<<c.real<<"+"<<c.imag<<"j"<<")"<<endl;return c;4復(fù)數(shù)乘法運(yùn)算函數(shù)函數(shù)體部分Complex1 operator*(Com
21、plex1 &c1)Complex1 c;cout<<"the result is: "<<endl;c.real=real*c1.real-imag*c1.imag;c.imag=real*c1.imag+imag*c1.real;cout<<"("<<real<<"+"<<imag<<"j"<<")"<<"*"<<"("<
22、;<c1.real<<"+"<<c1.imag<<"j"<<")"<<"="<<"("<<c.real<<"+"<<c.imag<<"j"<<")"<<endl;return c;5.復(fù)數(shù)除法運(yùn)算函數(shù)函數(shù)體部分Complex1 operator/(Complex1 &c1)Comp
23、lex1 c;cout<<"the result is: "<<endl;c.real=(real*c1.real+imag*c1.imag)/(c1.real*c1.real+c1.imag*c1.imag);c.imag=(imag*c1.real-real*c1.imag)/(c1.real*c1.real+c1.imag*c1.imag);cout<<"("<<real<<"+"<<imag<<"j"<<&quo
24、t;)"<<"/"<<"("<<c1.real<<"+"<<c1.imag<<"j"<<")"<<"="<<"("<<c.real<<"+"<<c.imag<<"j"<<")"<<endl;return c;6
25、.復(fù)數(shù)求模長函數(shù)函數(shù)體部分float Length()float x;cout<<"the result is: "<<endl;x=sqrt(real*real+imag*imag);cout<<"|"<<real<<"+"<<imag<<"j"<<"|"<<"="<<x<<endl;return x;7.復(fù)數(shù)求平方函數(shù)函數(shù)體部分Complex
26、1 Square1()Complex1 c;cout<<"the result is: "<<endl;c.real=real*real-imag*imag;c.imag=real*imag+imag*real;cout<<" the square of "<<"("<<real<<"+"<<imag<<"j"<<")"<<" is "&
27、lt;<"("<<c.real<<"+"<<c.imag<<"j"<<")"<<endl;return c;8.求共軛復(fù)數(shù)函數(shù)函數(shù)體部分Complex1 Conjugate()Complex1 c;cout<<"the result is: "<<endl;c.real=real;c.imag=imag*(-1);if(c.imag>=0)cout<<"conjuga
28、te complex number of"<<"("<<real<<"+"<<imag<<"j"<<")"<<" is "<<"("<<c.real<<"+"<<c.imag<<"j"<<")"<<endl;if(c.imag<0)co
29、ut<<"conjugate complex number of"<<"("<<real<<"+"<<imag<<"j"<<")"<<" is "<<"("<<c.real<<c.imag<<"j"<<")"<<endl;return c;8.復(fù)數(shù)求角
30、度函數(shù)函數(shù)體部分float Angle1()float y;cout<<"the result is: "<<endl;y=atan(imag)/(real)/i*180;if(real=0&&imag!=0)cout<<"the angle of" <<"("<<real<<"+"<<imag<<"j"<<")"<<" is &q
31、uot; <<90<<endl;if(real>0)cout<<"the angle of" <<"("<<real<<"+"<<imag<<"j"<<")"<<" is " <<y<<endl;if(real<0&&imag>0)cout<<"the angle of"
32、; <<"("<<real<<"+"<<imag<<"j"<<")"<<" is " <<y+180<<endl;if(real<0&&imag<0)cout<<"the angle of" <<"("<<real<<"+"<<imag<
33、<"j"<<")"<<" is " <<y-180<<endl;return y;9.復(fù)數(shù)間求角度函數(shù)函數(shù)體部分float Angle2(Complex1 &c1)float z,r,s,t;cout<<"the result is: "<<endl;r=(real*c1.real+imag*c1.imag);s=sqrt(real*real+imag*imag);t=sqrt(c1.real*c1.real+c1.imag*c1
34、.imag);z=acos(r/(s*t)/i*180;cout<<"the angle between"<<" ("<<real<<"+"<<imag<<"j"<<") "<<"and" <<" ("<<c1.real<<"+"<<c1.imag<<"j"<
35、;<") "<<" is " <<z<<endl;return z;10.復(fù)數(shù)輸入數(shù)據(jù)函數(shù)(虛函數(shù))函數(shù)體部分void enter()cin>>real;cin>>imag;cout<<endl;3. 3主程序和重要模塊的算法3.3.1主程序和重要模塊具體代碼如下: int main() /主函數(shù) int flag,w,v;Complex grad1,grad2;Complex *pt1,*pt2;Complex1 *pm1,*pm2;Complex1 revd1,revd2;
36、cout<<"姓名: 曾立弘"<<endl;cout<<"專業(yè): 電氣信息工程"<<endl;cout<<"班級: 1401班"<<endl;cout<<"學(xué)號: 0903140114"<<endl;while(flag!=0) /while循環(huán) ,flag=0時終止循環(huán) pt1=&grad1;pt2=&grad2;cout<<"Please choose the type of t
37、he numbers:"<<endl;cout<<"'0'-exit system"<<endl; cout<<"'1'-real number"<<endl; cout<<"'2'-plural number"<<endl; cin>>flag; if(flag=1) /條件語句:如果flag=1,則進(jìn)行實(shí)數(shù)運(yùn)算 cout<<"please choose th
38、e operation of the numbers:"<<endl;cout<<"'3'-'+'"<<endl;cout<<"'4'-'-'"<<endl;cout<<"'5'-'*'"<<endl;cout<<"'6'-'/'"<<endl;cout<<&q
39、uot;'7'-'+'"<<endl;cout<<"'8'-'-'"<<endl;cout<<"'9'-'+(int)'"<<endl;cout<<"'10'-'-(int)'"<<endl;cout<<"'11'-'root of two'"<&
40、lt;endl;cout<<"'12'-'square'"<<endl;cin>>w;if(w=3)cout<<"please enter first number: "pt1->enter();cout<<endl;cout<<"please enter second number: "pt2->enter();cout<<endl;pt1->operator+(grad2);if(w=4)cout&
41、lt;<"please enter first number: "pt1->enter();cout<<endl;cout<<"please enter second number: "pt2->enter();cout<<endl;pt1->operator-(grad2);if(w=5)cout<<"please enter first number: "pt1->enter();cout<<endl;cout<<"pl
42、ease enter second number: "pt2->enter();cout<<endl;pt1->operator*(grad2);if(w=6)cout<<"please enter first number: "pt1->enter();cout<<endl;cout<<"please enter second number: "pt2->enter();cout<<endl;pt1->operator/(grad2);if(w=7)co
43、ut<<"please enter the number: "pt1->enter();pt1->operator+();if(w=8)cout<<"please enter the number: "pt1->enter();pt1->operator-();if(w=9)cout<<"please enter the number: "pt1->enter();grad1+;if(w=10)cout<<"please enter the num
44、ber: "pt1->enter();grad1-;if(w=11)cout<<"please enter the number: "pt1->enter();pt1->RootOfTwo();if(w=12)cout<<"please enter the number: "pt1->enter();pt1->Square();if(w!=3&&w!=4&&w!=5&&w!=6&&w!=7&&w!=8&&
45、amp;w!=9&&w!=10&&w!=11&&w!=12)cout<<"please choose correct option!"<<endl; /出錯提示pt1=&revd1;pt2=&revd2;pm1=&revd1;pm2=&revd2;if(flag=2) /條件語句:如果flag=1,則進(jìn)行實(shí)數(shù)運(yùn)算 cout<<"please choose the operation of the numbers:"<<endl;
46、cout<<"'3'-'+'"<<endl;cout<<"'4'-'-'"<<endl;cout<<"'5'-'*'"<<endl;cout<<"'6'-'/'"<<endl;cout<<"'7'-'Length'"<<
47、endl;cout<<"'8'-'Square1'"<<endl;cout<<"'9'-'Conjugate'"<<endl;cout<<"'10'-'Angle1'"<<endl;cout<<"'11'-'Angle2'"<<endl;cin>>v;if(v=3)cout<&
48、lt;"please enter first number: "pt1->enter();cout<<endl;cout<<"please enter second number: "pt2->enter();cout<<endl;pm1->operator+(revd2);if(v=4)cout<<"please enter first number: "pt1->enter();cout<<endl;cout<<"please
49、 enter second number: "pt2->enter();cout<<endl;pm1->operator-(revd2);if(v=5)cout<<"please enter first number: "pt1->enter();cout<<endl;cout<<"please enter second number: "pt2->enter();cout<<endl;pm1->operator*(revd2);if(v=6)cout&l
50、t;<"please enter first number: "pt1->enter();cout<<endl;cout<<"please enter second number: "pt2->enter();cout<<endl;pm1->operator/(revd2);if(v=7)cout<<"please enter the number: "pt1->enter();cout<<endl;pm1->Conjugate();if(
51、v=8)cout<<"please enter the number: "pt1->enter();cout<<endl;pm1->Square1();if(v=9)cout<<"please enter the number: "pt1->enter();cout<<endl;pm1->Conjugate();if(v=10)cout<<"please enter the number: "pt1->enter();cout<<en
52、dl;pm1->Angle1();if(v=11)cout<<"please enter first number: "pt1->enter();cout<<endl;cout<<"please enter second number: "pt2->enter();cout<<endl;pm1->Angle2(revd2);if(v!=3&&v!=4&&v!=5&&v!=6&&v!=7&&v!=8&
53、;&v!=9&&v!=10&&v!=11)cout<<"please choose correct option!"<<endl; /出錯提示 if(flag!=1&&flag!=2&&flag!=0)cout<<"please choose correct option!"<<endl; /出錯提示if(flag!=0) cout<<"n" cout<<"Please carry
54、out the next operation:"<<endl;/繼續(xù)運(yùn)算提示 cout<<"n" cout<<"Welcome next time!"<<endl;return 0;3.4函數(shù)調(diào)用關(guān)系圖3.4.1函數(shù)調(diào)用關(guān)系圖如圖3.41所示 flag!=00 其他 輸入w ,w=? exit error 輸入v,v=?3 4 5 6 7 8 9 10 11 12 輸出 “please choose correct option!”“ 輸入flagfloat Length()Complex1 Co
55、njugate()float Angle1()Complex operator+()Complex1 operator+(Complex1 &c1)Complex1 operator-(Complex1 &c1)Complex1 operator*(Complex1 &c1)Complex1 operator/(Complex1 &c1) float Angle2(Complex1 &c1) float Square() float RootOfTwo() Complex operator-(int) Complex operator/(Complex
56、&c1) Complex operator*(Complex &c1) Complex operator-(Complex &c1) Complex operator+(Complex &c1)其他 11 10 9 8 7 6 5 4 3flag=2 復(fù)數(shù)運(yùn)算flag=1 實(shí)數(shù)運(yùn)算 Complex operator+(int) 3 4 5 6 7 8 9 10 11 12 其他 Complex operator-() Complex1 Conjugate() C+程序設(shè)計之復(fù)數(shù)計算器 第四章 調(diào)試分析 第四章 調(diào)試分析4.1調(diào)試過程遇到的問題及解決方法的得出過程
57、4.1.1問題及分析過程 1. 對輸出結(jié)果的界面沒有太注意,導(dǎo)致輸出結(jié)果不是很美觀; 2. 對字母的拼寫錯誤,導(dǎo)致前面定義的變量到后面編譯器不認(rèn)識;對固有寫法的拼寫錯誤,如將運(yùn)算符重載函數(shù)寫為operetor,導(dǎo)致運(yùn)算符重載不成功。 3.對一些模塊的編寫代碼缺乏系統(tǒng)分析,主要體現(xiàn)在以下幾個方面: (1)實(shí)數(shù)除法重載函數(shù)中沒有考慮分母為0的情況,增加了if條件語句討論; (2)實(shí)數(shù)求二次方根函數(shù)中沒有考慮被開方數(shù)為負(fù)數(shù)的情況增加了if條件語句討論; (3)求單個復(fù)數(shù)的向量角時沒有將弧度制轉(zhuǎn)化為角度制,定義了全局常變量i=3.1415927,通過弧度值除以i再乘以180將其轉(zhuǎn)化為角度值; 求單個復(fù)
58、數(shù)的向量角時沒有考慮象限的討論,最后加了if選擇結(jié)構(gòu)討論; 求單個復(fù)數(shù)的向量角時沒有分母(即實(shí)部real)為0的情況,增加了if條件語句討論; 具體討論程序如下(實(shí)部為real,虛部為 imag): float Angle1() /求單個復(fù)數(shù)的夾角度數(shù) float y;cout<<"the result is: "<<endl;y=atan(imag)/(real)/i*180;if(real=0&&imag!=0)cout<<"the angle of" <<"("&l
59、t;<real<<"+"<<imag<<"j"<<")"<<" is " <<90<<endl;if(real>0)cout<<"the angle of" <<"("<<real<<"+"<<imag<<"j"<<")"<<&
60、quot; is " <<y<<endl;if(real<0&&imag>0)cout<<"the angle of" <<"("<<real<<"+"<<imag<<"j"<<")"<<" is " <<y+180<<endl;if(real<0&&imag<0)co
61、ut<<"the angle of" <<"("<<real<<"+"<<imag<<"j"<<")"<<" is " <<y-180<<endl;return y; (4)在調(diào)用虛函數(shù)時,修改之前是基類指針指向子類指針的這一步驟寫在基類、子類的定義部分,導(dǎo)致下面先調(diào)用基類虛函數(shù),后調(diào)用子類虛函數(shù)時會出現(xiàn)調(diào)用的時同一部分,即基類的數(shù)據(jù)。修改后時將基類指針指向子類指針的這一步驟寫在調(diào)用基類虛函數(shù)和調(diào)用子類虛函數(shù)之間,從而實(shí)現(xiàn)了虛函數(shù)和多態(tài)性。(5)為使程序可以連續(xù)運(yùn)算而不是每算一次就得重新運(yùn)行使用了while 循環(huán),初始時將對象的地址賦給指針這一步驟寫在while 循環(huán)之外,發(fā)現(xiàn)經(jīng)過多次循環(huán)后指針?biāo)傅膶ο笠呀?jīng)不是原來的了,為使指針總是指向要求的對象,就必須在每一次循環(huán)開始時將其重新定位,即指向?qū)ο蟮拈_頭。綜上述原因,最后將將對象的
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- T/ZBH 027-2023晶硅光伏組件用材料第4部分:玻璃標(biāo)準(zhǔn)尺寸
- T/YNIA 010-2022呼吸器用聚丙烯熔噴法非織造材料
- 2025年綜合素質(zhì)評價與個人發(fā)展能力測試的考試試題及答案
- 會展策劃師職業(yè)資格考試題及答案2025年
- 2025年外語翻譯專業(yè)考試題及答案
- 2025年現(xiàn)代投資理論與實(shí)踐考核試卷及答案
- 2025年數(shù)據(jù)分析師職業(yè)考試試卷及答案
- 2025年數(shù)字營銷實(shí)務(wù)與策略考試試題及答案
- 2025年風(fēng)景園林設(shè)計師執(zhí)業(yè)資格考試模擬題及答案
- 2025年城市規(guī)劃與設(shè)計課程畢業(yè)考試試題及答案
- 2024年江蘇省無錫市中考?xì)v史真題(原卷版)
- 金礦合作協(xié)議書
- 山東科技大學(xué)投資經(jīng)濟(jì)學(xué)(專升本)期末復(fù)習(xí)題
- 2025年公共安全與管理相關(guān)考試題及答案
- 《守株待兔》“課本劇”背景PPT
- 流體包裹體及應(yīng)用PPT演示課件
- 防波堤課程設(shè)計
- 主動脈夾層PPT課件
- 甲狀腺相關(guān)性眼病(2)
- (完整版)拉管施工工藝
- 工程部績效考核表94061
評論
0/150
提交評論