歡迎來到裝配圖網(wǎng)! | 幫助中心 裝配圖網(wǎng)zhuangpeitu.com!
裝配圖網(wǎng)
ImageVerifierCode 換一換
首頁 裝配圖網(wǎng) > 資源分類 > DOC文檔下載  

復數(shù)計算器課程設計

  • 資源ID:23766460       資源大?。?span id="5cccys5" class="font-tahoma">299.91KB        全文頁數(shù):26頁
  • 資源格式: DOC        下載積分:9.9積分
快捷下載 游客一鍵下載
會員登錄下載
微信登錄下載
三方登錄下載: 微信開放平臺登錄 支付寶登錄   QQ登錄   微博登錄  
二維碼
微信掃一掃登錄
下載資源需要9.9積分
郵箱/手機:
溫馨提示:
用戶名和密碼都是您填寫的郵箱或者手機號,方便查詢和重復下載(系統(tǒng)自動生成)
支付方式: 支付寶    微信支付   
驗證碼:   換一換

 
賬號:
密碼:
驗證碼:   換一換
  忘記密碼?
    
友情提示
2、PDF文件下載后,可能會被瀏覽器默認打開,此種情況可以點擊瀏覽器菜單,保存網(wǎng)頁到桌面,就可以正常下載了。
3、本站不支持迅雷下載,請使用電腦自帶的IE瀏覽器,或者360瀏覽器、谷歌瀏覽器下載即可。
4、本站資源下載后的文檔和圖紙-無水印,預覽文檔經(jīng)過壓縮,下載后原文更清晰。
5、試題試卷類文檔,如果標題沒有明確說明有答案則都視為沒有答案,請知曉。

復數(shù)計算器課程設計

目 錄1 題目內(nèi)容及設計要求12 總體設計12.1 總體功能框圖12.2 類的設計說明12.3 主要算法流程圖13程序清單及注釋14運行結(jié)果與分析15總結(jié)26參考文獻21 題目內(nèi)容及設計要求題目17 復數(shù)計算器內(nèi)容及要求:(1)所設計的復數(shù)計算器可以進行+ - * += -= *= + - >= <= = !=運算符,其中>= <=是針對復數(shù)的模進行運算。(2)設計輸入重載函數(shù),要求能接收從鍵盤輸入a+bi形式的復數(shù),在程序中可以識別出實部虛部并正確賦值。(3) 設計計算器測試程序,對加減法進行測試,要求在兩位數(shù)以內(nèi)進行,對乘法進行測試,乘法要求為一位數(shù)的運算。(4) 設計記錄功能,可以記錄下不同用戶使用計算器的情況,記錄以文件的形式保存在計算機內(nèi),開機時要求用戶輸入用戶名,顯示該名戶以前的記錄。用戶記錄用包括:做了多少次加減法、乘法、進行測試的次數(shù),后3次的測試平均分等,在退出計算器程序時用心的用戶記錄代替原有的記錄。2 總體設計2.1 總體功能框圖根據(jù)題中任務的功能,首先要搞清復數(shù)的運算法則,并使用c+語言表達。復數(shù)包含實部與虛部,如何將這兩部分表達出來也使關(guān)鍵定義一個復數(shù)類complex。聲明所需成員函數(shù)和友元函數(shù)對各運算符進行重載。定義各成員函數(shù)。定義主函數(shù),實現(xiàn)對整個程序的控制。編譯、運行并調(diào)試2.2 類的設計說明class CComplex /定義命名空間NameCComplexprivate: double Real,Image;public: CComplex(double real=0,double image =0) /構(gòu)造函數(shù) Real=real;Image=image;friend istream & operator>>(istream &is,CComplex &com ); /重載輸入friend ostream & operator<<(ostream &os,CComplex &com); /重載輸出CComplex operator+(CComplex &com); /加法重載CComplex operator-(CComplex &com); /減法重載CComplex operator*(CComplex &com); /乘法重載CComplex operator+=(CComplex &com); /加法賦值重載CComplex operator-=(CComplex &com); /減法賦值重載CComplex operator*=(CComplex &com); /乘法賦值重載CComplex operator+(); /自加CComplex operator-(); /自減double mod (void); /求復數(shù)的模int operator>(CComplex &com);int operator<(CComplex &com);int operator!=(CComplex &com);int operator=(CComplex &com);2.3 主要算法流程圖開始聲明一個complex類,并定義double,real,image;聲明類的函數(shù),構(gòu)造函數(shù),加減乘除和取模運算c.real=real+c2.real;c.imag=imag+c2.imag;c.real=real-c2.real;c.imag=imag-c2.imag;c.real=(real*c2.real+imag*c2.imag)/a;c.imag=(imag*c2.real-real*c2.imag)/ac.real=real*c2.real-imag*c2.imag;c.imag=real*c2.imag+imag*c2.real;Sqrt(real*real=imag*imag);輸出c1,c2,c1+c2,c1-c2,c1*c2,c1/c2, c1的值終止。圖21 算法流程圖3 程序清單及注釋#include <iostream>#include <cmath>#include <cstdlib>#include <cstring>#include <fstream>#include <ctime>/#define EPS len-5 / 定義精度常數(shù)using namespace std;namespace NameCComplex / 定義命名空間 NameCComplex/*-|部分A:| 復數(shù)類 CComplex 的聲明和定義,以及結(jié)構(gòu)體類型 用戶 User 的定義| -*/*- | 復數(shù)類 CComplex 的聲明 -*/class CComplexprivate:double Real, Image; / 分別為復數(shù)的實部和虛部public:CComplex(double real=0, double image=0) / 構(gòu)造函數(shù)Real = real; Image = image;friend istream & operator >> (istream & is, CComplex & com); / 重載輸入friend ostream & operator << (ostream & os, CComplex & com); / 重載輸出CComplex operator + (CComplex & com); / 加法重載CComplex operator - (CComplex & com); / 減法重載CComplex operator * (CComplex & com); / 乘法重載CComplex operator += (CComplex & com); / 加法賦值重載CComplex operator -= (CComplex & com); / 減法賦值重載CComplex operator *= (CComplex & com); / 乘法賦值重載CComplex operator + (); / 自加CComplex operator - (); / 自減double mod(void);int operator > (CComplex & com);int operator < (CComplex & com);int operator != (CComplex & com);int operator = (CComplex & com);/*- | 結(jié)構(gòu)體類型 用戶 User 的定義 -*/struct Userchar szName20; / 用戶名int nTime; / 使用次數(shù)int nTest; / 測試次數(shù)double dlAve; / 平均成績int nAdd; / 加法次數(shù)int nSub; / 減法次數(shù)int nMul; / 乘法次數(shù)double dlScore3; / 3次測試得分 user;/*- | 復數(shù)類 CComplex 的類外定義部分 -*/ 重載運算符“+”,實部與虛部均加 1CComplex CComplex:operator + ()Real+;Image+;return *this;/ 重載運算符“-”,實部與虛部均減 1CComplex CComplex:operator - ()Real-;Image-;return *this;/ 求復數(shù)的模,返回 實部2 + 虛部2double CComplex:mod()return Real * Real + Image * Image;/ 重載運算符“>”,比較模的大小int CComplex:operator > (CComplex & com)if ( mod() > com.mod() )return 1; / 若大,則返回 1elsereturn 0;/ 重載運算符“<”,比較模的大小int CComplex:operator < (CComplex & com)if ( mod() < com.mod() )return 1; / 若小,則返回 1elsereturn 0;/ 重載運算符“!=”,分別判斷復數(shù)的實部與虛部int CComplex:operator != (CComplex & com)if ( *this=com )return 0;else return 1;/ 重載復數(shù)的輸入, a+bi 的形式istream & operator >> (istream & is, CComplex & com) cout << "輸入復數(shù):"char s80;is >> s; / 用字符串的形式接收復數(shù)int len = strlen(s); / 求出字符串的長度int n = 0, sign = 1; / 其中的 n 值 為當前從字符串中提取出的數(shù)字,會在下面的 while 語句中得到確定的值 / sign 為狀態(tài)變量,表示數(shù)值的正負符號,以輔助辨認正負值com.Image = com.Real = 0;/ 判斷接收的字符串是否合法for(int k=0; k<len; k+)if ( (sk<0 | sk>9) && (sk!=+ && sk!=- && sk!=i) )cout << "error" << endl;return is; / 錯誤,輸出出錯信息并返回/ 順序識別字符串中各字符for(int k=0; k<len;)if ( n!=0 && (sk=- | sk=+) ) / 當前字符是否為符號位com.Real = sign * n; / 是符號位,且 n!=0,即 n 已被賦值(通過下面的whlie語句),表明當前讀取的是虛部的符號n = 0; / 將原 n*sign 值(帶正負號的數(shù)值)賦給實部后,將 n 清零,準備下一次繼續(xù)接收并判斷是否為虛部的值if ( sk = -) / 當前字符若為負號sign = -1; k+; / 給符號標志變量 sign 賦值,表示為負數(shù)if ( sk = +) / 當前字符若為正號sign = 1; k+; / 給符號標志變量 sign 賦值,表示為正數(shù)if ( sk=i ) / 若當前字符為“i”if ( k!=len-1 ) / 判斷字符 i 是否為字符串中最后一個字符cout << "errorn" / 如果不是,說明復數(shù)數(shù)據(jù)格式錯誤elsecom.Image = sign * n; / 是最后一個字符,復數(shù)對象已接收完,用 sign*n 為虛部賦值break;while ( sk>=0 && sk<=9 ) / 當前字符若在 09 之間,則將數(shù)字字符轉(zhuǎn)換成數(shù)字數(shù)值n = n * 10 + sk - 0;k+;if ( slen-1!=i && n!=0 ) / 如果最后一個字符不是 i,表示復數(shù)對象內(nèi)只有實部,沒有虛部,如:-acom.Real = n * sign;return is;/ 重載復數(shù)的輸出ostream & operator << (ostream & os, CComplex & com)if ( fabs(com.Image)=0 ) / 如果虛部為 0os << com.Real; / 只輸出實部else if ( fabs(com.Real)=0 ) / 如果實部為 0os << com.Image << "i" / 只輸出虛部else if ( com.Image>0 )os << com.Real << "+" << com.Image << "i" / 虛部為正elseos << com.Real << com.Image << "i" / 如 實部為 3,虛部為 -6i,就變?yōu)?3 - 6i,而不是 3 + -6ireturn os;/ 加法重載CComplex CComplex:operator + (CComplex & com)CComplex sum;sum.Real = Real + com.Real; / 實部相加sum.Image = Image + com.Image; / 虛部相加return sum;/ 乘法重載CComplex CComplex:operator * (CComplex & com)CComplex multi;multi.Real = Real * com.Real - Image * com.Image; / 乘積實部multi.Image = Real * com.Image + Image * com.Real; / 乘積虛部return multi;/ 減法重載CComplex CComplex:operator - (CComplex & com)CComplex sub;sub.Real = Real - com.Real; / 實部相減sub.Image = Image - com.Image; / 虛部相減return sub;/ 加法賦值重載CComplex CComplex:operator += (CComplex & com)Real = Real + com.Real; / 實部Image = Image + com.Image; / 虛部return *this;/ 減法賦值重載CComplex CComplex:operator -= (CComplex & com)Real = Real - com.Real; / 實部Image = Image - com.Image; / 虛部return *this;/ 乘法賦值重載CComplex CComplex:operator *= (CComplex & com)double nReal = Real * com.Real - Image * com.Image; / 乘積實部double nImage = Real * com.Image - Image * com.Real; / 乘積虛部Real = nReal;Image = nImage;return *this;/ 重載 = 運算符,分別比較兩個復數(shù)對象的實部和虛部int CComplex:operator = (CComplex & com)if ( Real=com.Real && Image=com.Image )return 1; / 實部與虛部部分相等,則返回 1elsereturn 0;/*-|部分B:|測試函數(shù) void Test(void)|實現(xiàn)復數(shù)的加法函數(shù) void Add()|實現(xiàn)復數(shù)的減法函數(shù) void Sub()|實現(xiàn)復數(shù)的乘法函數(shù) void Mul()|實現(xiàn)復數(shù)的自加函數(shù) void Add1()|比較兩個復數(shù)的大小函數(shù) void Compare()|輸出本次用戶使用計算器的情況記錄 void userprint()|當前用戶使用完計算器,保存或更新用戶資料函數(shù) void SaveFile()| -*/ 測試函數(shù),隨機出 10 道運算題,可以打分void Test(void)user.nTest+; / 用戶測試次數(shù)加 1cout << "共10道題,作10以內(nèi)的加減運算,滿分 100分:n"double real1, real2, image1, image2, real3, real4, image3, image4; / 1 和 2 分別代表兩個待相加的復數(shù)的實部和虛部,3 和 4 則為相乘CComplex answer, temp;int score = 0;char op;for(int i=0; i<=9; i+)real1 = rand()%200 - 100; / 產(chǎn)生的隨機數(shù)是兩位數(shù),可以是正數(shù)或負數(shù)image1 = rand()%200 - 100;real2 = rand()%200 - 100;image2 = rand()%200 - 100;CComplex a(real1, image1), b(real2, image2); / 用產(chǎn)生的隨機數(shù)對象分別初始化兩個復數(shù)對象real3 = rand()%20 - 10; / 產(chǎn)生的隨機數(shù)是一位數(shù),可以是正數(shù)或負數(shù)image3 = rand()%20 - 10;real4 = rand()%20 - 10;image4 = rand()%20 - 10;CComplex c(real3, image3), d(real4, image4);op = rand()%3; / 隨機產(chǎn)生 3 種運算符switch(op)case 0:answer = a + b;cout << a << "加上" << b << "等于"break;case 1:answer = a - b;cout << a << "減去" << b << "等于"break;case 2: / 乘法運算,用實部和虛部都是 1 位數(shù)的對象操作answer = c * d;cout << c << "乘以" << d << "等于"break;cin >> temp; / 接收用戶輸入的結(jié)果if ( answer=temp ) score+=10; / 正確則加 10分elsecout << "此題做錯了n"cout << "正確答案為:" << answer << endl;cout << "你的最后得分是:" << score << endl;/ 計算最后 3次的平均分if ( user.nTest<=3 ) / 若累計次數(shù)沒有超過 3次user.dlAve = 0;user.dlScoreuser.nTest-1 = score; / 將本次測試成績添加進記錄中for(int i=0; i<user.nTest; i+)user.dlAve += user.dlScorei; / 若以前有記錄,將其與本次記錄累計相加起來,用以計算平均分user.dlAve = user.dlAve / user.nTest; / 計算平均分,user.dlAve 從累計的分數(shù) 變成了平均分else / 如果累計測試超過 3次user.dlScore0 = user.dlScore1; / 最前面的一次記錄將被覆蓋,即:刪除user.dlScore1 = user.dlScore2;user.dlScore2 = score; / 將本次記錄添加進測試記錄的尾部user.dlAve=0;for(int i=0; i<3; i+) / 計算最新 3次的平均分user.dlAve += user.dlScorei;user.dlAve = user.dlAve / 3;cout << "按任意鍵繼續(xù)n"cout .flush();cin.get();cin.get();/ 實現(xiàn)復數(shù)的加法void Add()user.nAdd+;CComplex num1, num2, sum, Zero(0, 0);cout << "加法計算n" << "最少輸入兩個復數(shù),輸入“0”結(jié)束n"cout << "第1個復數(shù):"cin >> num1; / 輸入第 1個復數(shù)cout << "第2個復數(shù):"cin >> num2; / 輸入第 2個復數(shù)sum = num1 + num2;cout << "第3個復數(shù):"cin >> num1; / 輸入第 3個復數(shù)int i = 4;while ( !(num1=Zero) )sum = sum + num1; / 實現(xiàn)復數(shù)相加cout << "第" << i << "個復數(shù):"cin >> num1; / 輸入第 i個復數(shù)i+;cout << "結(jié)果是:" << sum << endl;cout << "按任意鍵繼續(xù)n"cout.flush();cin.get();cin.get();/ 實現(xiàn)復數(shù)的減法void Sub()user.nSub+;CComplex num1, num2, sub, Zero(0, 0);cout << "減法計算n" << "最少輸入兩個復數(shù),輸入“0”結(jié)束n"cout << "第1個復數(shù):"cin >> num1; / 輸入第 1個復數(shù)cout << "第2個復數(shù):"cin >> num2; / 輸入第 2個復數(shù)sub = num1 - num2;cout << "第3個復數(shù):"cin >> num1; / 輸入第 3個復數(shù)int i = 4;while ( !(num1=Zero) )sub = sub - num1; / 實現(xiàn)復數(shù)減法cout << "第" << i << "個復數(shù):"cin >> num1; / 輸入第 i個復數(shù)i+;cout << "結(jié)果是:" << sub << endl;cout << "按任意鍵繼續(xù)n"cin.get();cin.get();/ 實現(xiàn)復數(shù)的乘法void Mul()user.nMul+;CComplex num1, num2, mul, Zero(0, 0);cout << "乘法計算n" << "最少輸入兩個復數(shù),輸入“0”結(jié)束n"cout << "第1個復數(shù):"cin >> num1; / 輸入第 1個復數(shù)cout << "第2個復數(shù):"cin >> num2; / 輸入第 2個復數(shù)mul = num1 + num2;cout << "第3個復數(shù):"cin >> num1; / 輸入第 3個復數(shù)int i = 4;while ( !(num1=Zero) )mul *= num1; / 實現(xiàn)復數(shù)的減法cout << "第" << i << "個復數(shù):"i+; cin >> num1; / 輸入第 i個復數(shù)cout << "結(jié)果是:" << mul << endl;cout << "按任意鍵繼續(xù)n"cin.get();cin.get();/ 實現(xiàn)復數(shù)的自加,實部與虛部均自加 1void Add1()user.nAdd+; / 用戶加法記錄次數(shù)加 1CComplex num1;cin >> num1; / 這里 輸入的數(shù)可能是虛部為0的數(shù),原書代碼未作判斷num1+; / 實部與虛部分別加 1cout << "自加結(jié)果為" << num1 << endl;cout << "按任意鍵繼續(xù)n"cout.flush();cin.get();cin.get();/ 實現(xiàn)復數(shù)的自減void Sub1()user.nSub+; / 用戶減法記錄次數(shù)加 1CComplex num1;cin >> num1;num1-;cout << "自減結(jié)果為" << num1 << endl;cout << "按任意鍵繼續(xù)n"cout.flush();cin.get();cin.get();/ 比較兩個復數(shù)的大小void Compare()CComplex num1, num2;cout << "輸入兩個復數(shù)n"cout << "第1個復數(shù):"cin >> num1;cout << "第2個復數(shù):"cin >> num2;if ( num1=num2 )cout << " 這兩個復數(shù)相等n"else if ( num1>num2 )cout << num1 << "的模大于" << num2 << "的模n"else if ( num1<num2 )cout << num2 << "的模大于" << num1 << "的模n"elsecout << "這兩個復數(shù)的模相等n"cout << "按任意鍵繼續(xù)n"cin.get();cin.get();/ 輸出本次用戶使用計算器的情況記錄void userprint()cout << user.szName << "使用的次數(shù)為:" << user.nTime << "次" << endl;cout << "其中:t 加法次數(shù):" << user.nAdd << "次n" << "t 減法次數(shù):" << user.nSub << "次n" << "t 乘法次數(shù):" << user.nMul << "次n" << "t 測試次數(shù):" << user.nTest << "次n" << "t 平均成績:" << user.dlAve << "次" << endl;/ 用戶登陸,開始啟動計算器void Login()char szName20;cout << "請輸入您的姓名:"cin.getline(szName, 20);ifstream infile;User user1;infile.open("user.dat", ios:binary|ios:in); / 打開用戶資料文件 (這個地方 若沒有文件,則不會創(chuàng)建新文件,不知何問題if ( !infile ) / 若沒有用戶資料文件cout << "沒有原始記錄文件, 您是第 1位用戶!n"strcpy(user.szName, szName); / 為全局變量 user 中 szName 成員賦值user.nTime+;return; / 函數(shù)返回/ 讀取用戶資料文件(從該文件的第1個字節(jié)開始逐個讀取信息)/ 如果用戶資料中找到了當前姓名的用戶,則說明是老用戶,顯示一些信息,并作一些使用次數(shù)的記錄。infile.read( (char *)&user1, sizeof(User) ); while ( !infile.eof() ) / 只要沒到文件末尾(未遇文件結(jié)束符),則一直進行此循環(huán)if ( strcmp(user.szName, szName)=0 ) / 將用戶資料文件中的用戶名與讀取的用戶名進行比較user = user1; / 若該用戶以前使用計算器,將原資料賦值給全局變量 useruser.nTime+; / 用戶使用次數(shù)加 1cout << "歡迎您再次使用復數(shù)計算器!"userprint(); / 輸出用戶資料中的信息cin.get();infile.close();return;infile.read( (char *)&user1, sizeof(User) );/ 如果用戶資料中沒有當前用戶,表明該用戶是第 1次使用計算器cout << "歡迎您使用復數(shù)計算器!"strcpy(user.szName, szName); / 為全局變量 user 中 szName 成員賦值user.nTime+; /用戶使用次數(shù)加 1infile.close();return;/ 當前用戶使用完計算器后,保存或更新用戶資料void SaveFile()userprint(); / 輸出當前用戶使用計算器的詳細信息fstream file;User user1;file.open("user.dat", ios:binary|ios:in|ios:out); / 打開用戶資料if (!file)cout << "文件打開錯誤,不能將記錄更新n"return;file.seekg(0, ios:beg); / 文件指針指向文件頭while( !file.eof() )file.read( (char *)&user1, sizeof(User) ); / 逐個讀取用戶資料文件中的用戶信息/ 將用戶資料文件中的用戶名依次與當前用戶名進行比較if ( strcmp(user1.szName, user.szName)=0 ) / 若在用戶資料文件中找到該用戶file.seekp(-(sizeof(User), ios:cur); / 文件指針退回到該用戶資料信息的首位置file.write( (char *)&user, sizeof(User) ); / 將全局變量 user 的內(nèi)容寫到用戶資料文件中,即更新該用戶的資料file.close();return; / 程序返回file.close();fstream outfile;/ 若在用戶資料文件中找不到當前用戶的資料,表明當前用戶是第 1次使用計算器outfile.open("user.dat", ios:binary|ios:app); / 以添加的方式打開用戶資料文件outfile.write( (char *)&user, sizeof(User) ); / 將當前用戶的資料添加在用戶資料文件中outfile.close();return;using namespace NameCComplex; / 使用標準命名空間 NameCComplex/*-| | 主函數(shù)部分| -*/int main(void)srand( time(NULL) ); / 初始化隨機數(shù)種子Login(); / 打開文件,登記用戶int Choice;dosystem("cls"); / 系統(tǒng)執(zhí)行命令:cls 為清屏cout << " 這是一個簡單的復數(shù)計算器程序,可以實現(xiàn)以下功能,請按下對應的鍵(1 7)進入nnn"cout << "t=主菜單=n"cout << "t 1:多復數(shù)加法n"cout << "t 2:多復數(shù)減法n"cout << "t 3:測試 100以內(nèi)的復數(shù)加減乘法運算,1次測試10道題n"cout << "t 4:多復數(shù)乘法n"cout << "t 5:復數(shù)自加n"cout << "t 6:復數(shù)自減n"cout << "t 7:復數(shù)比較n"cout << "t 0:退出計算器程序nn"cout << "t 請輸入您的選擇:"cin >> Choice;/ 下面用 switch - case 語句實現(xiàn)多現(xiàn)選擇,當然也可以用 if - else 語句實現(xiàn)多項選擇switch(Choice)case 1:Add(); break;case 2:Sub(); break;case 3:Test(); break;case 4:Mul(); break;case 5:Add1(); break;case 6:Sub1(); break;case 7:Compare(); break;case 0:cout << "nt 歡迎下次繼續(xù)使用復數(shù)計算器!nn"break;default:cout << "nt 輸入錯誤,請按任意鍵后重新輸入!n"cin.get();cin.get();while(Choice); / 當 Choice 值為 0時, 結(jié)束循環(huán)SaveFile(); / 退出程序前,保存或更新當前用戶的使用情況system("pause");return 0;/* 書上的主函數(shù)寫法:int main(void)srand( time(NULL) ); / 初始化隨機數(shù)種子Login(); / 打開文件,登記用戶char strChoice20;dosystem("cls"); / 系統(tǒng)執(zhí)行命令:cls 為清屏cout << " 這是一個簡單的復數(shù)計算器程序,可以實現(xiàn)以下功能,請按下對應的鍵(17)進入nnn"cout << "t=主菜單=n"cout << "t 1:多復數(shù)加法n"cout << "t 2:多復數(shù)減法n"cout << "t 3:測試 100以內(nèi)的復數(shù)加減乘法運算,1次測試10道題n"cout << "t 4:多復數(shù)乘法n"cout << "t 5:復數(shù)自加n"cout << "t 6:復數(shù)自減n"cout << "t 7:復數(shù)比較n"cout << "t 0:退出計算器程序nn"cout << "t 請輸入您的選擇:"cin >> strChoice;/ 下面用 if - else 語句實現(xiàn)多現(xiàn)選擇,當然也可以用 switch - case 語句實現(xiàn)多項選擇if ( strcmp(strChoice, "1")=0 )Add();else if ( strcmp(strChoice, "2")=0 )Sub();else if ( strcmp(strChoice, "3")=0 )Test();else if ( strcmp(strChoice, "4")=0 )Mul();else if ( strcmp(strChoice, "5")=0 )Add1();else if ( strcmp(strChoice, "6")=0 )Sub1();else if ( strcmp(strChoice, "7")=0 )Compare();else if ( strcmp(strChoice, "0")=0 )cout << "nt 歡迎下次繼續(xù)使用復數(shù)計算器!nn"break;elsecout << "nt 輸入錯誤,請按任意鍵后重新輸入!n"cin.get();cin.get();while( (strcmp(strChoice, "0") );SaveFile(); / 退出程序前,保存或更新當前用戶的使用情況system("pause");return 0;*/4 運行結(jié)果與分析5 總結(jié)1. 明確實驗操作對象和目的。2. 針對目的和對象進行總體設計。3. 細化流程:書寫程序,編譯、運行并調(diào)試。4. 一開始錯誤的將復數(shù)的兩個部分一起聲明,在后來的編程過程中遇到了計算上的錯誤,于是將復數(shù)的實部和虛部分開聲明,問題得到了解決5. 計算器還可擴充用戶輸入錯誤算式時提示用戶的功能6. 計算器還可以擴充帶有括號的功能(課程設計過程中出現(xiàn)的問題及其解決方案,可擴充的功能及設計等。)6 參考文獻1李愛華,程磊著. 面向?qū)ο蟪绦蛟O計(C+語言) .北京:清華大學出版社,20102劉振安,劉燕君著. C+程序設計課程設計. 北京: 機械工業(yè)出版社,20043譚浩強著. C+程序設計實踐指導. 北京:清華大學出版社,2005

注意事項

本文(復數(shù)計算器課程設計)為本站會員(jun****875)主動上傳,裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對上載內(nèi)容本身不做任何修改或編輯。 若此文所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng)(點擊聯(lián)系客服),我們立即給予刪除!

溫馨提示:如果因為網(wǎng)速或其他原因下載失敗請重新下載,重復下載不扣分。




關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號:ICP2024067431-1 川公網(wǎng)安備51140202000466號


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng),我們立即給予刪除!