




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、22VC+計算器課程設(shè)計報告1.作品名稱:計算器2.本次課程設(shè)計的目的 在程序設(shè)計中,通過設(shè)計、編制、調(diào)試一個模擬計算器的程序,加深對語法及語義分析原理的理解,并 實現(xiàn)對命令語句的靈活應(yīng)用。3.主要功能實現(xiàn)計算器的功能。用戶根據(jù)程序提示,輸入數(shù)字或字符,選擇要進行的運算,可以進行正弦、余弦、正切、開方、對數(shù)、加、減、乘、除、華氏溫度與攝氏度之間的換算以及平方根的運算。4.代碼#include <process.h>#include<time.h>#define MAX 100#include <iostream.h>#include <conio.h&
2、gt;#include <stdlib.h>#include <math.h>double number1,number2,answer,number3,num10000; int n,k=1;char input,val; class oopcalc private:double x,y; double fartocel(double number1); double celtofar(double number1); double sqroot(double number1);void calcsqr();void calccos();void calctan();
3、void calcsin();void calclog();public:double getX()return x;double getY()return y;double set()x=number1;y=number2;double calcadd(double number1,double number2); double calcsub(double number1,double number2); double calcdiv(double number1,double number2); double calcmult(double number1,double number2)
4、; void calcfartocel();void calcceltofar();void calcsroot();void exitprog();void menu();void caculate(); void test();void badinput(); ;void oopcalc:calcsin()cout<<"The Sin Functionn"cout<<"Enter a number:"cin>>number1;answer=sin(number1);cout<<"The sin
5、 of "<<number1<<" is "<<answer<<endl;cout<<"Press any key to continuen"getch();menu();void oopcalc:calccos()cout<<"The Cos Functionn"cout<<"Enter a number:"cin>>number1;answer=cos(number1);cout<<"
6、The cos of "<<number1<<" is "<<answer<<endl;cout<<"Press any key to continuen"getch();menu();void oopcalc:calctan()cout<<"The Tan Functionn"cout<<"Enter a number:"cin>>number1;answer=tan(number1);cout<<
7、;"The tan of "<<number1<<" is "<<answer<<endl;cout<<"Press any key to continuen"getch();menu();void oopcalc:calcsqr()cout<<"The sqr Functionn"cout<<"Enter a number:"cin>>number1;answer=(number1*number1)
8、;cout<<"The sqr of "<<number1<<" is "<<answer<<endl;cout<<"Press any key to continuen"getch();menu();void oopcalc:calclog()cout<<"The Log Functionn"cout<<"Enter a number:"cin>>number1;if(number1&l
9、t;=0) cout<<"Bad input!n"cout<<"Press any key to continuen"getch();menu();elseanswer=log(number1);cout<<"The log of "<<number1<<" is "<<answer<<endl;cout<<"Press any key to continuen"getch();menu();doub
10、le oopcalc:calcadd(double number1,double number2) answer=number1+number2;return(answer);double oopcalc:calcsub(double number1,double number2) answer = number1-number2;return(answer);double oopcalc:calcdiv(double number1,double number2) if(number2=0)getch();menu();elseanswer = number1/number2;return(
11、answer);double oopcalc:calcmult(double number1,double number2) answer = number1*number2;return(answer);void oopcalc:calcfartocel()cout << "The Farenheit to Celsius Functionn"cout << "Enter a tempature in Farenheit: "cin >> number1;answer =(number1 - 32) * 5) / 9
12、;cout << "The tempature in Celsius is " << answer << endl;cout << "Press any key to continuen"getch();menu();void oopcalc:calcceltofar()cout << "The Celsius to Farenheit Functionn"cout << "Enter a tempature in Celsius: "cin
13、>> number1;answer =number1 * 9 / 5 + 32;cout << "The tempature in Farenheit is " << answer << endl;cout << "Press any key to continuen"getch();menu();void oopcalc:calcsroot()cout << "The Square Root Functionn"cout << "First
14、 number: "cin >> number1;if(number1<0) cout<<"your enter is incorrect,please enter a new numbern"getch();menu();elseanswer = sqrt(number1);cout << "The square root of " << number1 << " is " << answer << endl;cout <<
15、; "Press any key to continuen"getch();menu();void oopcalc:exitprog()exit(-1);void oopcalc:menu()oopcalc a;system("cls"); cout << "=MENU=n"cout <<"s:選擇s進行正弦運算n"cout <<"c:選擇c進行余弦運算n"cout <<"t:選擇t進行正切運算n"cout <<&q
16、uot;g:選擇g進行對數(shù)運算n"cout <<"n:選擇n進行求平方運算n"cout << "1: 選擇1進行混合運算n"cout << "2: 選擇2進行華氏溫度轉(zhuǎn)化為攝氏溫度的運算n"cout << "3: 選擇3進行攝氏溫度轉(zhuǎn)化為華氏溫度的運算n"cout << "4: 選擇4進行求平方根運算n"cout << "5: 選擇5進行測試n"cout << "6:選擇6
17、退出運算n" cout << "請選擇: "cin >> input;cout << "=n"switch (input)case 's':case 'S':a.calcsin();break;case 'c': case 'C': a.calccos();break;case 't':case 'T': a.calctan();break;case 'g':case 'G':a.c
18、alclog();break;case 'n':case 'N':a.calcsqr();break;case '1':a.caculate();break;case '2':a.calcfartocel();break;case '3':a.calcceltofar();break;case '4':a.calcsroot();break;case '5': a.test();break;case '6':a.exitprog();break;default :a.
19、badinput();void oopcalc:caculate() oopcalc a;cout<<"The Multifunction(混合四則運算)n"for(int n=1;n+)cout<<"Number"<<n<<"(Enter 0 to end entering):"cin>>numnif(numn=0)cout<<"Press any key to continuen"getch();menu();switch(k)case 1
20、:if(n=1)answer=num1;break;else answer=a.calcadd(answer,numn); cout<<"The answer is "<<answer<<endl;break;case 2:if(n=1)answer=num1;break;else answer=a.calcsub(answer,numn);cout<<"The answer is "<<answer<<endl;break;case 3:if(n=1)answer=num1;bre
21、ak;else answer=a.calcmult(answer,numn);cout<<"The answer is "<<answer<<endl;break;case 4:if(n=1)answer=num1;break;else answer=a.calcdiv(answer,numn);cout<<"The answer is "<<answer<<endl;break;label1:cout<<"Please choose the function
22、you want(+ or - or * or /):n"cin>>val;switch(val)case'+':k=1;break;case'-':k=2;break;case'*':k=3;break;case'/':k=4;break;default:cout<<"Bad input!n"goto label1;void oopcalc:test()cout<<"The Test Functionn"int s;float p;s=rand
23、()%4+1;srand ( time (NULL) );number1=rand()%MAX+1;number2=rand()%MAX+1;switch(s)case 1:cout<<number1<<'+'<<number2<<'='answer=calcadd(number1,number2);break;case 2:cout<<number1<<'-'<<number2<<'='answer=calcsub(number1,number2);break;case 3:cout<<number1<<'/'<<number2<<'='answer=calcdiv(number1,number2);break;case 4:cout&
溫馨提示
- 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 配電線路技能鑒定實操培訓(xùn)課件
- 高效節(jié)能電機項目投資估算方案(范文模板)
- 城市污水管網(wǎng)建設(shè)工程安全管理方案(模板)
- 2025年高純氮化鋁粉體項目建議書
- 2025年銀行監(jiān)管及中央銀行服務(wù)項目合作計劃書
- 智慧物流概論 課件 04智慧運輸
- 2025年醫(yī)藥級纖維素醚合作協(xié)議書
- 常用胰島素種類及特點表
- 常用烏頭類中藥的毒性研究概述
- 航空航天零部件制造2025年高精度加工技術(shù)不銹鋼成形技術(shù)研究報告
- 2024詳解國家基層糖尿病防治管理指南
- 零星維修改造工程施工方案施工組織設(shè)計投標(biāo)方案(技術(shù)標(biāo))
- 盾構(gòu)隧道用管片招標(biāo)采購
- 《環(huán)境與資源保護法(第5版)》全套教學(xué)課件
- 2024年03月北京西城區(qū)教委事業(yè)單位招考聘用764人筆試近年2018-2023典型考題及考點剖析附答案帶詳解
- 人教版2024七年級英語上冊Starter Unit(1-3)單詞精講課件
- 廣東省深圳市寶安區(qū)2023-2024學(xué)年五年級下學(xué)期期末英語試題
- 成品煙道安裝施工方案
- 《路遙人生》讀書分享課件
- 律師保密協(xié)議書
- 小學(xué)2024年暑假致家長的一封信9篇
評論
0/150
提交評論