欢迎来到天天文库
浏览记录
ID:33943750
大小:11.36 MB
页数:121页
时间:2019-03-02
《CSCI114 week4 Color.pdf》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、CSCI114/MCS9114Week4LecturesMoreonFunctionsandSelectionStructuresLecturer:JoAbrantesRoom3.212ph:42213872jo_abrantes@uow.edu.auSchoolofComputerScienceandSoftwareEngineeringCSCI114/MCS9114–Spring2011LecturesOverviewRevisionsMoreonFunctions:Parameterspassedby
2、valueControlStructures:TheifstatementTheif-elsestatementCascadedandNestedifTheConditionalExpressionRevisionLastWeek’sProgramTheProblem:Writeaprogramthattakesasinputagivenlengthexpressedinfeetandinches.Itthenconvertsandoutputsthelengthincentimetres.Revis
3、ionProgramDesign:Thealgorithm:1.Prompttheuserfortheinput2.Getthedata(infeetandinches)3.Findthelengthininches4.Outputthelengthininches5.Convertthelengthtocentimetres6.OutputthelengthincentimetresRevisionTheCompleteProgram//ProgramDescription:Convertsagivenleng
4、thfromfeetandinchestocm#includeusingnamespacestd;constdoubleCM_PER_INCH=2.54;constintINCHES_PER_FOOT=12;intmain(){intfeet,inches,totalInches;doublecm;cout<<"Pleaseenterlengthinfeetandinches:";cin>>feet>>inches;totalInches=inches+feet*INCHES_PER_FOOT
5、;cout<<"Thelengthininchesis:"<6、entsthelogicvalueofanexpression(orsinglevariable)!trueisfalse,!falseistrue!(age<23)isthesameasage>=23SummaryofComplements>isthecomplementof<==!expristhecomplementofexprandvice-versa…RevisionLogicalOperatorsTheothertwooperatorsarebinaryl7、ogicalandwiththesymbol&&logicalorwiththesymbol8、9、Suchoperationsarebestexplainedusingatruthtable!hashigherprecedenceUnaryoperatorshavethehighestprecedenceRevisionLogicalOperatorsAnd–thevalueofexpr1&&expr2RevisionLogicalOperatorsOr–thevalueofexpr110、11、expr2Lo12、gicalOperatorsNotethat:!(expr113、14、exptr2)isthesameas!expr1&&!expr2!(expr1&&exptr2)isthesameas!expr115、16、!expr2RevisionArithmetic,RelationalandLogicalOperatorsMnemonicUnaryArithmeticReallyLogic
6、entsthelogicvalueofanexpression(orsinglevariable)!trueisfalse,!falseistrue!(age<23)isthesameasage>=23SummaryofComplements>isthecomplementof<==!expristhecomplementofexprandvice-versa…RevisionLogicalOperatorsTheothertwooperatorsarebinaryl
7、ogicalandwiththesymbol&&logicalorwiththesymbol
8、
9、Suchoperationsarebestexplainedusingatruthtable!hashigherprecedenceUnaryoperatorshavethehighestprecedenceRevisionLogicalOperatorsAnd–thevalueofexpr1&&expr2RevisionLogicalOperatorsOr–thevalueofexpr1
10、
11、expr2Lo
12、gicalOperatorsNotethat:!(expr1
13、
14、exptr2)isthesameas!expr1&&!expr2!(expr1&&exptr2)isthesameas!expr1
15、
16、!expr2RevisionArithmetic,RelationalandLogicalOperatorsMnemonicUnaryArithmeticReallyLogic
此文档下载收益归作者所有