Click here to load reader

Input output

  • View
    314

  • Download
    3

Embed Size (px)

DESCRIPTION

Intro to programming concepts

Text of Input output

  • 1.Input - Process - Output in VB.NET 1

2. ObjectivesDistinguish between logic and syntaxUnderstand and use the input statementUnderstand and use the assignmentstatementUnderstand and use the output statementUnderstand and use arithmetic operatorswith precedenceSuccessfully write program solutions thatrequire input, processing, and output2 3. Logic and SyntaxA computer program is a solution to aproblem.An algorithm is the logical design used toaccomplish a specific objective.Syntax refers to the specific rules of aprogramming language. 3 4. Input Statements 4 5. Input StatementsAn input statement accepts data from theuser and stores that data into a variable.A variable is a storage location that can beaccessed and changed by developer code.A variable has a name and an associateddata value.A variable has a data type that determinesthe kind of data values the variable canstore. 5 6. Declaring VariablesVariables are declared with the Dimstatement (short for Dimension statement).One or more variables can be declared witha single Dim statement.The Dim statement can be used to specifythe variables initial value by placing anequal sign after the data type. 6 7. Naming Rules for Variables A variable must have a unique name, called an identifier. Identifiers must follow three rules: Begin with a letter or underscore Contain only letters, digits, and underscores Cannot be reserved wordsDim identifier [, identifier] [As datatype [= initialvalue]] 7 8. Working with ConstantsA constant is a storage location whosevalue cannot change during the executionof the program.Constants are declared with the Constdeclaration.Const identifier As datatype = value 8 9. Data TypeData Type DescriptionStringTextByte (1 byte) Positive Whole Number (0 to 255)Short (2 bytes) Whole Number (-32,768 to 32,767)Integer (4 bytes) Whole Number (+ or up to 2 million)Long (8 bytes)Whole Number (huge!)Single (4 bytes)Floating point (+ or up to 3.4 x 1038)Double (8 bytes)Floating point (+ or up to 1.8 x 10308)Decimal Stored exactly as BCD (currency & percentages)DateAlso stores timeBoolean True or falseCharSingle character or positive number (up to 65535)9 10. Weekly Paycheck ProgramThe weeklypaycheck programhas two inputvariables:Hours and Rate10 11. Operators and ExpressionsAn operator is a symbol that indicates anaction to be performed.Value-returning code elements such asvariables, constants, and expressions can becombined with one or more operators toform an expression. 11 12. Assignment StatementsThe assignmentstatement can be usedto perform acalculation and storethe result.An expression is avalue-returning codeelement, such as avariable ormathematical formula.12 13. The Assignment StatementAn assignment statement is used to store avalue into a variable or an object property. variable = expression object.property = expressionThe equal sign (=) is the assignmentoperator. 13 14. Numbers and String OperatorsArithmetic operators require numericoperands and produce numeric results.The string operator concatenation (&)requires String operands and produces aString result such as: S = sun & set S becomes sunset14 15. Numerical OperatorsOperationOperatorExpression 1 Result 1 Expression 2 Result 2Plus & + 45+2 14 (5 + 2)-3MinusMultiply & * / 1+3*7 22 17 / 35.667DivideInteger 124 31735DivisionInteger Mod 12 Mod 40 17 Mod 3 2RemainderExponent ^ 5^2+1 26 5 ^ (2 + 1)125(Power of) 15 16. How to Write Formulas16 17. Output Statements (flow chart)17 18. Intrinsic FunctionsVB .NET provides a large number ofintrinsic functions to improve developerproductivity.Intrinsic functions support a broad range ofactivities, including math calculations,business calculations, time and datefunctions, string formatting functions, andmany more. 18 19. Common FunctionsIntrinsic functions are predefined commands thatprovide developers with common functions.Function Example 1Result 1 Example 2 Result 2Val()(23.5) 23.5 (32)0IsNumeric()(23.5) True (32) TrueFormatCurrency() (1234.567)1,234.57(4.5) 4.50Format(expr,str) (1/2, 0.##)0.5(6.666, 0.###) 6.67Int()(3.8) 3 Int(Rnd()) 0Double valueIntegerRnd() () Int(Rnd()*6)+1 between 0 and 1from 1 to 6Abs()(-3.3) 3.3(5.67) 5.67Import System.Math19 20. Rnd StatementThe Rnd statement generates a singleprecision random value between 0.0 upto (but not including) 1.0.The Randomize statement is used tochange the seed value (randomsequence).20 21. Financial FunctionsPmt is a function for determining monthlypayments. Pmt(Rate, NPer, PV)FV is a function for determining the futurevalue of an annuity based on periodic, fixedpayments and a fixed interest rate. FV(Rate, NPer, Pmt) 21 22. SummaryVariables are storage locations used for holding inputand processing information. Each variable has two components: its name and its value. It is good practice to make variable names descriptive withmixed case. The Dim statement is used to declare a variable byspecifying its name and data type.Input statements are used to get data into variables.Assignment statements are used to performcalculations and store the result.22 23. SummaryExpressions are combinations of operators andvalue-returning code elements such as variables,constants, and literals. One of the common uses of an expression is to performa calculation for an assignment statement. Intrinsic functions provide pre-defined methods forcommon processing requirements.Output statements are used to displayinformation.Input, assignment, and output statements aresufficient to write small programs.23