Pseudocode Pseudocode is an abbreviated version of the actual statement t t (or code ) in the program. It is a type of algorithm in that all steps needed to solve the problem must be listed. 1 While algorithms are written to solve all type of problems, Pseudocode d is used specifically for programming problems
Example 1 A pseudocode to compute the area of a ti triangle, given its Length and dbreath 1. INPUT length as L 2. INPUT Breath as B 3. Area = L * B 4. PRINT Area 5. Stop 2
Example 2
Introduction to QBASIC Lecture 5
Constants Constants are values that do not change during the execution of a program. There are generally two types: 1. Numeric constants 2. Character string constants
Categories of constants
Numeric constants A number included in a statement is called a numeric constant. t It can be decimal or an integer Exponential notation is used when very large or small numbers are involved A numeric constant t is any real or integer that t can be assign to a numeric variable.
Example Type Examples Integer 236 45312-236 +145-61231 Decimal/Real 236. -156.76 +7015-8878 0.215 Exponential 2.61E 4 0.156E-4 2E10 +2.456E-08
Remarks A numeric constant should not contain any character except the digit it 0 9 and a decimal Commas (,) are not allowed in numbers e.g., 1,234.25 X 1234.2525 If a number has no sign, the computer assumes it is positive. E.g., 237 =+237
Remarks cont If a number is negative, the negative sign must precede the digit, it as in -210 Fractions must be written in decimal form. E.g., 3.75 is the correct representation ti for No blank spaces are allowed e.g., 1 364 3 3 4
Character String Constant A character string constant is a collection of symbols called alphanumeric data. It can include any combination of letters, numbers and special characters including dashes, commas, blanks, etc It t b l d i d bl t ti It must be enclosed in double quotation marks
Character String Constant cont Single quotation marks can be used within a string contained within double quotation ti marks E.g., She said, what did you do? It is invalid to have for e.g., The letter E is a vowel Note that the computer can store a blank E.g., University, University
Variables A variable is a storage location containing a value that t can change during program execution A variable can contain only one value at a time Use descriptive variable names to identify values E.g., QuantityOnHand is better than QUAN
Remarks The first character of the variable name must be a letter. The remaining i characters may be letters, numbers and period QBASIC does not differentiate t between uppercase and lowercase letters in variable names. FirstName FIRSTNAME Firstname are all identical
Types of Variables There are two types: 1. Numeric variables 2. String variables
Numeric variables Numeric variables are used to store numbers that t are either supplied to the computer by the programmer /user or internally calculated during program execution. It must begin with a letter, followed by letters, digits and periods E.g., BigNumber, TOTAL.PRICE, CLASS2A Some invalid variable names are : 1. Maximum/Average 2. 1stChoice 3. Square meters
String Variables A string variable is used to store a character string ti such as a name, an address or a social security number. A string variable name must begin with a letter followed by letter or digit and must be terminated with a dollar sign ($). E.g., Headings$ Employee$ DaysOfWeek$
Remark Certain words have specific meanings to QBASIC. They are called reserved words/ keywords and thus cannot be used as variable names. Examples: READ, LET, END, LIST etc.
BASIC characters Refer to Laboratory manual
Arithmetic Operations and Expressions In QBASIC, arithmetic expressions are composed of numeric constants numeric variables arithmetic operators
Arithmetic operators The most commonly used arithmetic operators are as follows: Operator Operation BASIC Expression + Addition A + B - Subtraction A - B / Division A/B * Multiplication A * B ^ Exponentiation A^B
Expressions Expressions can be: Arithmetic Logical An Arithmetic ti expressions is an arithmetic ti formula consisting of a sequence of variables, constants and arithmetic operators that is to be evaluated. E.g., X + 9 A + B + C 7 0.5 * A* H
Expressions cont A logical expression is a sequence of variables, constants, t relational l operators and connectives that always has a value of either true or false. E.g., A > B X + Y <= 0 A < B AND B < C
Statements A statement is the fundamental unit in a computer program.