DOC PREVIEW
Mizzou CMP_SC 1040 - Computer Science- After Exam 1

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Computer ScienceSeptember 28, 2011Code for Simplified “Cascade”Select Case structure mimics the cascadeSelect Case only works for testing ONE variable in a multitude of conditionsWorks for either string or numerical variableAll tests must be the same data type Using select case for pricesSelect Case ageCase Is < 12Price = 3.5Case Is < 18 Price = 5Case Is < 65 Price = 7.5Case Else : price = 5End Select More Case ExamplesUsing StringsSelect Case strVar.Substring(0,1) Case “S”,”Z” : ‘Statement Case “0” to “9” : ‘Statement Case Is < “W” : ‘Statement Case Else : ‘StatementEnd Select Combo BoxMethod to force choices for usersControls type of inputExample of code getting InputDim NumberVar As Double Dim strName As StringNumberVar = CDbl(cboInput.Text)strName = cboEnter.TextOctober 3, 2011Functions A mathematical function is basis of computer programming functions. You supply x, the function supplies f(x). In computer science, a function is a little sub-program that receives data, works on data, and returns a valueEach function in a program has unique nameI.E.: Int, MultiplyltFunction is known to program because 1. Built-in to VB  128 functions 2. Defined by programmer, such as MultiplyltWriting FunctionsNew VocabularyArguments: item(s) sent to the function to be worked on by the function from some place within the programParameters: placeholders in the function itself that accept the argumentsFunction returns only ONE value Functions have Name, 0 or more parameters, and data type Example:Function MultlT (ByVal X As Integer) As Integer‘statements hereReturn X * XEnd Function Documenting a FunctionThree important comment lines:Function goal:What will it do during its duration?Input:What values will be given to the function form the calling program?Return:What value will be returned to the calling program?Calling [Invoking] A FunctionFunctions are called or invoked where you would expect to find a literal or expressionFor example:dblResult = functionCall(arguments…)dblResult = FindlT(23.5, 98.76)dblResult = FindlT(14, FindlT(3, 5))**Functions are always on the RIGHT side of an assignment statementOctober 5, 2011What is scope in respect to Visual Basic programming?a. mouthwash b. something to do with class-level variablesc. tell when class-level variables are active d. tells what variables inside an event procedure are available for loading valuesinto theme. none of these Local variables – known only to procedure in which they are declaredClass variables – known to all procedures in the form in which they reside Scope – the portion of the program that can refer to the declared entityQuiz 15. true12. true 13. c, both Sub Procedures Used to “modularize” programStandard CodeSub NameOfProcedure(…parameters…)‘statements to solve procedure purposeEnd SubDefault parameter type is ByValParametersParameter is local to the procedureData TypeParameter data type declared in header Match number of arguments sent from calling procedureNameUses same naming conventions as variablesDoes not need to match argument name(s)Calling the Sub ProcedureCall AddNums(2, 35)Call AddNums(3*5, Int(-1.876))Call AddNums(var, var+3)October 12, 2011Which is true about arguments and parameters?Arguments appear in calling statements; parameters appear in Sub statementsThe argument in a calling statement must match the parameters in the appropriate Sub or Function header in all but one of the following ways. Which one?a. number of argumentsb. names of arguments c. data type of arguments d. order of arguments Suppose a variable is passed by value to a parameter of a Sub procedure, and the parameter has its value changed in side the Sub procedure. What will the value of the variable be after the Sub procedure has executed?It will retain the value it had before the call to the Sub procedureSuppose a variable is passed by reference to a parameter of a Sub procedure, and the parameter has its value changed inside the Sub procedure. What will the value of the variable be after the Sub procedure has executed?It will have the newly modified value from inside the Sub procedure Loop IdeasA loop is one of the most important structures in programmingUsed to repeat a sequence of statements a number of timesThe Do loop repeats a sequence of statements either as long as or until a certain condition is trueLooping means repeating action until (or while) a condition is metCode for Do LoopDo While (some condition is true)‘statements to be done repeatedly LoopDo‘statements to be done repeatedly Loop Until (some condition is true)October 24, 2011Code for Post-Test LoopsDo ‘statements done at least one timeLoop Until (condition)  leave when condition is trueDo ‘statements done at least one time Loop While (condition)  leave when condition is false November 2, 2011Answer to 15: 2November 7,


View Full Document

Mizzou CMP_SC 1040 - Computer Science- After Exam 1

Download Computer Science- After Exam 1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Computer Science- After Exam 1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Computer Science- After Exam 1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?