vc课程设计打印.docx
《vc课程设计打印.docx》由会员分享,可在线阅读,更多相关《vc课程设计打印.docx(19页珍藏版)》请在冰豆网上搜索。
![vc课程设计打印.docx](https://file1.bdocx.com/fileroot1/2022-11/22/988158bb-ce33-4123-ab7b-48ea63320ff9/988158bb-ce33-4123-ab7b-48ea63320ff91.gif)
vc课程设计打印
TheLoveCaculator
Acalculatordisplay
(计算器上的显示屏)
1.Editbox(编辑框)
Calculatorisdisplayedonthedisplayscreenofthedigitalinputoperationandoperationaftertheimplementationoftheresults.
(计算器上的显示屏显示输入的运算数字及运算执行后的结果。
)
2.Addclasswizard(添加类向导)
3.Addvariables(添加变量)
AddvariablesusedbythetypeofCString,CStringisaveryusefuldatatype,whichlargelysimplifiesMFCmanyoperation,makestheMFCdoingstringoperationwhenalotofconvenience.ThecalculatordesignaredefinedinthestringtypetwovariablesA1andA2,mainlyusedfortwoinputdataiscachedforcalculation.Anintegervariablem,usedinfunctionOnequalwhencomputingoperatorselection.(添加变量所用到的类型是CString,CString是一种很有用的数据类型,它们很大程度上简化了MFC中的许多操作,使得MFC在做字符串操作的时候方便了很多。
该计算器设计中定义了字符串类型的两个变量a1与a2,主要用于对两次输入的数据进行缓存以便于进行计算。
一个整数变量m,用于在函数Onequal中进行运算时进行运算符的选择。
)
4.Addbutton(添加按钮)
Definebuttonproperties(定义按钮的属性)
5.界面设计图
Caculaterbuttonandcodecallfunction
(计算器上的按钮及其代码中调用的函数)
Calculatorbuttonsymbols,forexample:
PIisπmean,taketheπ=3.1415926;e=2.718281828459;lnisthenaturallogarithm,inmath,ln(x)istobaseelogx
Sin--AonedgeandbevelanglethancalledangleAsine,denotedassinA,sinA=angleAtotheedge/hypotenuse.
Cos--thecosinetheoremisrevealedinthetriangularrelationshipbetweenthecornersofanimportanttheorem,itcanbedirectlyusedtosolveaclassofknowntriangletwosidesandangleofthirdorthreeedgeangleisknownfortheproblems,ifthecosinetheoremtobedeformedandappropriatelymovedtootherknowledge,itismoreconvenienttouse,flexible.
Tan--thetangentfunctionisarighttriangle,theedgeandtheadjacentedgeoftheratio.
N!
--thisisthefactorialofmathematics.
计算器按钮上的符号,例如:
PI就是π的意思,取π=3.1415926;e=2.718281828459;ln就是自然对数,在数学中ln(x)是以e为底的x的对数
sin——角A的对边与斜边的比叫做角A的正弦,记作sinA,即sinA=角A的对边/斜边。
cos——余弦定理是揭示三角形边角关系的重要定理,直接运用它可解决一类已知三角形两边及夹角求第三边或者是已知三个边求角的问题,若对余弦定理加以变形并适当移于其它知识,则使用起来更为方便、灵活。
tan——正切函数是直角三角形中,对边与邻边的比值。
n!
——这个是数学中的阶乘。
计算器上的按钮表示计算器上的运算符号,代码中有实现该功能所用到的函数,这些函数中有从math.h中调用得到的,也有自己编写的。
Calculatorbuttonsonsaidcalculatoroperationalsymbol,codehastoachievethefunctionoftheuseoffunction,thesefunctionsarecalledfrommath.hobtained,alsohavetheirownwritten.
Button
Callfunction(调用的函数)
%
fmod(num1,num2)
sin
doublesin(doublex)
cos
doublecos(doublex)
tan
doubletan(doublex)
/
doublemodf(double,double*)
arcsin
doubleasin(doublex)
arccos
doubleacos(doublex)
arctan
doubleatan(doublex)
sqrt
doublesqrt(doublex)
Detailedcodecalculatordesign
计算器的详细代码设计
1.Buttonoperationpartofdigitaldesigncode(按钮上运算数字部分的代码设计)
Thefollowingcodeusedtodisplaythebuttononthecontent,equivalenttoabuttononthedisplaydefinition,whentheinputnumber,calculatorbycallingtheinternalfunctiontorefreshthedata,whenpressingthenumberkeys,constant,adecimalpointkey,thedatadisplayedintheeditbox,againwithinternalfunctiontorefreshdatatransfer.
以下代码用于显示按钮上的内容,相当于按钮的定义,当在显示器上输入数字后,计算器通过调用内部函数来刷新数据,当按下数字键、常数、小数点键时,就把该数据显示在编辑框内,再次调用内部函数来刷新数据。
//数字0
voidCCalculatebDlg:
:
On0()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
m_lecture+="0";
UpdateData(FALSE);
}
//数字1
voidCCalculatebDlg:
:
On1()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
m_lecture+="1";
UpdateData(FALSE);
}
//数字2
voidCCalculatebDlg:
:
On2()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
m_lecture+="2";
UpdateData(FALSE);
}
//数字3
voidCCalculatebDlg:
:
On3()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
m_lecture+="3";
UpdateData(FALSE);
}
//数字4
voidCCalculatebDlg:
:
On4()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
m_lecture+="4";
UpdateData(FALSE);
}
//数字5
voidCCalculatebDlg:
:
On5()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
m_lecture+="5";
UpdateData(FALSE);
}
//数字6
voidCCalculatebDlg:
:
On6()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
m_lecture+="6";
UpdateData(FALSE);
}
//数字7
voidCCalculatebDlg:
:
On7()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
m_lecture+="7";
UpdateData(FALSE);
}
//数字8
voidCCalculatebDlg:
:
On8()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
m_lecture+="8";
UpdateData(FALSE);
}
//数字9
voidCCalculatebDlg:
:
On9()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
m_lecture+="9";
UpdateData(FALSE);
}
//小数点
voidCCalculatebDlg:
:
Onf()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
m_lecture+=".";
UpdateData(FALSE);
}
//pi的值
voidCCalculatebDlg:
:
Onpi()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
m_lecture+="3.1415926";
UpdateData(FALSE);
}
2.计算器上一般运算符号的代码设计
Thisarithmeticforadd,subtract,multiplyanddivideanddemand,calculatorrefreshdataafterthefirstinputdataisassignedtothevariableA1,willbeusedtoselecttheoperationoftheswitchfunctioninthecasecorrespondstothenumberofvaluem,easytocalloperationfunctioncomputation.ThenthesecondinputdatatoA2,thenA1,A2fromthestringtypedoublecharacter,thisisaveryimportantstep,thecomputerfunctionsasthecontentonadisplayscreenfromthestringconversiontocomputerexecutabledoubleprecisioncharacter,throughthecodetoachievethecalculatorcalculationfunction.Finally,fortheadditionandsubtractionoperationsofx^yA1andA2directlybetweentheoperation,fordivisiontojudgewhetherthedivisoriszero,ifzerowerewarned,ifnotzero,thenadivisionoperation.Switchusedinprogramming,suchasClanguagesitisoftenusedwithCase.,isajudgeselectioncode.Itsfunctionistocontrolthebusinessprocessflow.Thisdesignisthegeneraloperationalsymbolselectioncalculator.此部分运算为加减乘除及求余,计算器刷新数据后把第一次输入的数据赋给变量a1,将用于选择运算的switch函数中的case对应的编号值赋予m,便于调用运算函数进行运算。
然后把第二次输入的数据传给a2,然后将a1、a2由字符串型转换成双精度字符型,这是很重要的一步,计算机功能的实现即为将显示屏上的内容从字符串转换为计算机可执行的双精度字符型,通过代码实现计算器的计算功能。
最后,对于加减乘x^y运算直接进行a1与a2之间的运算,对于除法先进行判断除数是否为零,若为零就进行警告,若不为零,则进行除法运算。
Switch用在编程中,如C语言中它经常跟Case一起使用,是一个判断选择代码。
其功能就是控制业务流程流转的。
此设计中是对计算器一般运算符号的选择。
voidCCalculatebDlg:
:
Ona()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
a1=m_lecture;
m_lecture+="+";
m=1;
UpdateData(FALSE);
}
voidCCalculatebDlg:
:
Onb()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
a1=m_lecture;
m_lecture+="-";
m=2;
UpdateData(FALSE);
}
voidCCalculatebDlg:
:
Onc()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
a1=m_lecture;
m_lecture+="*";
m=3;
UpdateData(FALSE);
}
voidCCalculatebDlg:
:
Ond()
{
UpdateData();
a1=m_lecture;
m_lecture+="/";
m=4;
UpdateData(FALSE);
}
voidCCalculatebDlg:
:
Onqy()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
a1=m_lecture;
m_lecture+="%";
m=5;
UpdateData(FALSE);
}
voidCCalculatebDlg:
:
Onequal()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
a2=m_lecture;
doublenum1=atof(a1);
doublenum2=atof(a2);
doublenum3;
switch(m)
{
case1:
num3=num1+num2;
m_lecture.Format(_T("%lf"),num3);
m_lecture=Delling(m_lecture);
break;
case2:
num3=num1-num2;
m_lecture.Format(_T("%lf"),num3);
m_lecture=Delling(m_lecture);
break;
case3:
num3=num1*num2;
m_lecture.Format(_T("%lf"),num3);
m_lecture=Delling(m_lecture);
break;
case4:
if(num2==0)
{
MessageBox("除数不能为0,请重新输入除数!
");
m_lecture="";
}
else
{
num3=num1/num2;
m_lecture.Format(_T("%lf"),num3);
m_lecture=Delling(m_lecture);
}
break;
case5:
if(num2==0)
{
MessageBox("除数不能为0,请重新输入除数!
","警告",MB_OK);
m_lecture="";
}
else
{
doublenum3=fmod(num1,num2);//在math.h中调用fmod进行计算器求余功能的实现
m_lecture.Format(_T("%lf"),num3);
}
break;
default:
break;
}
UpdateData(FALSE);
}
3.计算器上特殊运算符的代码设计
Sin,cos,Tan,arcsin,arccos,arctandirectlyfrommath.hcallingfunctioncouldachieveitsoperationalfunctionforcotoperation,thedirectuseofCOSdividedbysinfor.Thefactorialn!
Operationbyforcycletoachieve,thefactorialforcycletoachieve,forcycleisacircle.Itsgeneralform:
for(<>initialize;condition;incrementstatement<>);initializationisalwaysanassignmentstatement,itisusedtogivetheloopcontrolvariableinitialization;conditionalexpressionisanexpression,itisdecidingwhentoexitaloop;incrementaldefinitionforloopcontrolvariableforeachcycletimebywhatmeanschanges.Thethreepartby";"separate.
sin,cos,tan,arcsin,arccos,arctan直接从math.h中调用函数就可以实现其运算功能,对于cot运算直接用cos除以sin求的。
阶乘n!
的运算时通过for循环来实现的,此处的阶乘用for循环来实现,for循环是开界的。
它的一般形式为:
for(<初始化>;<条件表达式>;<增量>)语句;初始化总是一个赋值语句,它用来给循环控制变量赋初值;条件表达式是一个关系表达式,它决定什么时候退出循环;增量定义循环控制变量每循环一次后按什么方式变化。
这三个部分之间用";"分开。
voidCCalculatebDlg:
:
Onsin()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
a1=m_lecture;
doublenum1=atof(a1);
doublenum2=sin(PI/180*num1);
m_lecture.Format(_T("%lf"),num2);
UpdateData(FALSE);
}
voidCCalculatebDlg:
:
Oncos()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
a1=m_lecture;
doublenum1=atof(a1);
doublenum2=cos(PI/180*num1);
m_lecture.Format(_T("%lf"),num2);
UpdateData(FALSE);
}
voidCCalculatebDlg:
:
Ontan()
{
//TODO:
Addyourcontrolnotificationhandlercodehere
UpdateData();
a1=m_lecture;
doublenum