Input output
-
Upload
nickywalters -
Category
Documents
-
view
322 -
download
3
description
Transcript of Input output
![Page 1: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/1.jpg)
1
Input - Process - Output
in VB.NET
![Page 2: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/2.jpg)
22
Objectives
Distinguish between logic and syntax
Understand and use the input statement
Understand and use the assignment statement
Understand and use the output statement
Understand and use arithmetic operators with precedence
Successfully write program solutions that require input, processing, and output
![Page 3: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/3.jpg)
33
Logic and Syntax
A computer program is a solution to a problem.
An algorithm is the logical design used to accomplish a specific objective.
Syntax refers to the specific rules of a programming language.
![Page 4: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/4.jpg)
44
Input Statements
![Page 5: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/5.jpg)
55
Input Statements
An input statement accepts data from the user and stores that data into a variable.A variable is a storage location that can be accessed and changed by developer code.A variable has a name and an associated data value.A variable has a data type that determines the kind of data values the variable can store.
![Page 6: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/6.jpg)
66
Declaring Variables
Variables are declared with the Dim statement (short for Dimension statement).
One or more variables can be declared with a single Dim statement.
The Dim statement can be used to specify the variable’s initial value by placing an equal sign after the data type.
![Page 7: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/7.jpg)
77
Naming Rules for VariablesA 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 words
Dim identifier [, identifier] [As datatype [= initialvalue]]
![Page 8: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/8.jpg)
88
Working with Constants
A constant is a storage location whose value cannot change during the execution of the program.
Constants are declared with the Const declaration.
Const identifier As datatype = value
![Page 9: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/9.jpg)
99
Data TypeData Type Description
String Text
Byte (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)
Date Also stores time
Boolean True or false
Char Single character or positive number (up to 65535)
![Page 10: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/10.jpg)
1010
Weekly Paycheck Program
The weekly paycheck program has two input variables:
Hours and Rate
![Page 11: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/11.jpg)
1111
Operators and Expressions
An operator is a symbol that indicates an action to be performed.
Value-returning code elements such as variables, constants, and expressions can be combined with one or more operators to form an expression.
![Page 12: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/12.jpg)
1212
Assignment Statements
The assignment statement can be used to perform a calculation and store the result.An expression is a value-returning code element, such as a variable or mathematical formula.
![Page 13: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/13.jpg)
1313
The Assignment Statement
An assignment statement is used to store a value into a variable or an object property. variable = expression object.property = expression
The equal sign (=) is the assignment operator.
![Page 14: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/14.jpg)
1414
Numbers and String Operators
Arithmetic operators require numeric operands and produce numeric results.
The string operator concatenation (&) requires String operands and produces a String result such as: S = “sun” & “set” S becomes “sunset”
![Page 15: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/15.jpg)
1515
Numerical Operators
Operation Operator Expression 1 Result 1 Expression 2 Result 2
Plus & Minus + – 4 – 5 + 2 1 4 – (5 + 2) -3
Multiply & Divide * / 1 + 3 * 7 22 17 / 3 5.667
Integer Division \ 12 \ 4 3 17 \ 3 5
Integer Remainder Mod 12 Mod 4 0 17 Mod 3 2
Exponent (Power of) ^ 5 ^ 2 + 1 26 5 ^ (2 + 1) 125
![Page 16: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/16.jpg)
1616
How to Write Formulas
![Page 17: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/17.jpg)
1717
Output Statements (flow chart)
![Page 18: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/18.jpg)
1818
Intrinsic Functions
VB .NET provides a large number of intrinsic functions to improve developer productivity.
Intrinsic functions support a broad range of activities, including math calculations, business calculations, time and date functions, string formatting functions, and many more.
![Page 19: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/19.jpg)
1919
Common FunctionsIntrinsic functions are predefined commands that provide developers with common functions.
Function Example 1 Result 1 Example 2 Result 2
Val() (“23.5”) 23.5 (“£32”) 0
IsNumeric() (“23.5”) True (“£32”) True
FormatCurrency() (1234.567) £1,234.57 (4.5) £4.50
Format(expr,str)(1/2,
“0.##”) “0.5”(6.666,
“0.###”) “6.67”
Int() (3.8) 3 Int(Rnd()) 0
Rnd() ()Double value
between 0 and 1 Int(Rnd()*6)+1Integer
from 1 to 6
Abs() Import System.Math
(-3.3) 3.3 (5.67) 5.67
![Page 20: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/20.jpg)
2020
Rnd Statement
The Rnd statement generates a single precision random value between 0.0 up to (but not including) 1.0.
The Randomize statement is used to change the seed value (random sequence).
![Page 21: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/21.jpg)
2121
Financial Functions
Pmt is a function for determining monthly payments. Pmt(Rate, NPer, PV)
FV is a function for determining the future value of an annuity based on periodic, fixed payments and a fixed interest rate. FV(Rate, NPer, Pmt)
![Page 22: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/22.jpg)
2222
SummaryVariables are storage locations used for holding input and processing information. Each variable has two components: its name and its value. It is good practice to make variable names descriptive with
mixed case. The Dim statement is used to declare a variable by
specifying its name and data type.
Input statements are used to get data into variables.
Assignment statements are used to perform calculations and store the result.
![Page 23: Input output](https://reader033.fdocuments.in/reader033/viewer/2022042607/5554aa93b4c90502618b51cf/html5/thumbnails/23.jpg)
2323
Summary
Expressions are combinations of operators and value-returning code elements such as variables, constants, and literals. One of the common uses of an expression is to perform
a calculation for an assignment statement. Intrinsic functions provide pre-defined methods for
common processing requirements.
Output statements are used to display information.Input, assignment, and output statements are sufficient to write small programs.