Professional Documents
Culture Documents
Engr. J. Cansino
Information Technology Department
Numeric Constant - may be an integer (whole number) or a real number (with a decimal place). It may be preceded by a positive or negative sign. Examples: 10
-28
+3.4
-0.413
201
Note: No other characters must or can appear together with the constants. The following are examples of incorrect numeric constants: 10,000 $14.3 10mi/hr 1/2
String Constant A character or group of characters enclosed in double quotation marks ( ). The numbers 0-9, letters a-z or A-Z and all special characters like a space, % $ - _ & etc. may be included. Examples: J Jojo . 1225 J & J
Note: The entire string constant must always be enclosed in double quotation marks, one before the first character and one after the last character (no more no less). The following are examples of incorrect string constants:
Earl Jerald Cansino SMART Avenger Assemble
2.) Variables Is a portion of the computers main memory used to store a numeric or string constant. The value stored in the variable must be given a unique variable name but it can only hold one value at a given time.
Variable names must conform to the following requirements: a.) Must contain only letters, numbers and/or an underscore. b.) Must begin with a letter. c.) Must end either with a letter or a number. d.) Must be unique that is, not a name of another variable. e.) Must not be a keyword like ACCEPT, WHILE and the like.
A variable may be one of the following types: Numeric, String, Array Note: Variable names are not case sensitive in flowcharting and pseudo-coding, that is, upper and lower case letters are not differentiated. For example the variable TOTAL is the same as total. The following are example of incorrect variable name: Year code 10ctr #5 Total=
3.) Expressions is a group of program elements consisting of operands and operators. Operands can be a constant, variable, and or an array element. Operators can be arithmetic, logical, relational and/or string. Expressions always yield a value of a certain type depending on the type of expressions used. Arithmetic Expressions Hierarchy or Priority of Operators 1.) Expressions in parenthesis 2.) * / % 3.) + -
Examples:
1.) 10 + 4 * 8
3.)
20 / 4 * 9
5 45
32 42
2.) 50 % 6 5
2 -3
String Expressions
Examples: 1.) 2.)
3 + 4 = 34 Ja + red = Jared
Relational Expressions
Greater than Less than Greater than or equal to Less than or equal to Not equal Is equal to Examples: Ctr1 > 10 3 <= 5 Temp1 != Temp2 > < >= <= != ==
Logical Expressions
Hierarchy or Priority of Operators 1.) 2.) 3.) 4.) Expressions in parenthesis Not (!) And (&&) Or (||)
TRUTH TABLE FOR AND(&&) X FALSE FALSE TRUE TRUE Y FALSE TRUE FALSE TRUE X && Y FALSE FALSE FALSE TRUE
TRUTH TABLE FOR OR(||) X FALSE FALSE TRUE TRUE Y FALSE TRUE FALSE TRUE X || Y FALSE TRUE TRUE TRUE
4.) Statements are keywords, which perform which perform a predefined procedure. The following statements are available:
1.) 2.) 3.) 4.) 5.) DISPLAY Statement ACCEPT Statement IF Statement WHILE Statement FOR Statement
Assignment #1.2
Check if Valid (V) or Invalid (I) 1. Numeric Constant: 2. String Constant: 3. Arithmetic Expression: 4. Variable Name: 5. Relational Expression: 6. Logical Expression: 7. Variable Name: 8. String Constant: 9. Numeric Constant: 10. Logical Expression: 0.12345 HELLO_TRISHA (45.9)%(5*2%3) _J_A_R_E_D (5<=2*2) =10+1 (!(!(!(F&&T)))) J5R3D *&****hello## 1,000,000.98 (!T&&!F)||(!F)
Evaluate the Following expressions: 1. 12 % 6 + (2 + 12 * 3) ( 12 % 13) 2. (10 / 3 + (16 + 3) ) ((5 * 2 % 10) + 2) 3. (T || F) && (!(!F && (6 > 8) || (5< 10) || F) || !T) 4. (T || !F) || (!(!(!F || (3 < 15) || F) || !F) && T) 5. !(!T && !F) || (!T || (12 <= 12) || (T && F)|| F)
FLOWCHARTS
- A graphic form of an algorithm.
- A diagram of a sequence of steps that a program must perform to produce the desired output.
- Traditional tool of programmers which allow in terms of detail to be included. flexibility
TYPES OF FLOWCHARTS
1.) System Flowchart present the total picture without worrying about taking care of every detail. 2.) Program Flowcharts depicts a main segment of a complete computer program.
FLOWCHARTING GUIDELINES
1.) Always use the ANSI standard symbols.
2.) Construct your flowcharts to read from top to bottom and left to right.
3.) Do not crisscross flowlines (used labeled connectors and use arrowheads to indicate direction of the flow. 4.) Make the messages and labels in the flowchart symbol direct and descriptive. 5.) Strive for neatness, clarity and simplicity.
Preparation Symbol
Processing Symbol
Decision Symbol
Input/Output Symbol
I/O symbol
Preparation symbol
Direction lines
Sequential structure
#1] Input a temperature in Celsius and output the corresponding temperature in Fahrenheit. The formula is a follows: Fahrenheit = 9 (Celsius) + 32 5
Pseudocode
Flowchart
Start
F=0
Input C
F = (9.0/5.0) * C + 32
Accept C
F = (9.0 / 5.0) * C + 32 Display Equivalent temperature in Fahrenheit:, F End
Output F End
Sequential structure #2] Pepperoni++ Pizza House charges 10% service charge and 5% sales tax on the gross bill of the customer. Create a flowchart and a pseudocode that would input the gross bill of the customer and the amount given by the customer to the waiter. It must output the customers total bill and change (if theres any).
Flowchart
Start Variables Used:
Pseudocode
TBill = 0 change = 0
Input GBill, Amt
change = Amt - TBill Display Total Bill = , Tbill Display Change = , change
End
Assignment #1.2: Sequential structure #5] Using Visual Logic, Draw and execute a FCD for Workers at a particular company were given a 15.5% salary increase. Moreover, the increase was retroactive for 2 months, that is, effective two months ago. Create a flowchart and a pseudocode that takes the employees old salary as input and then output the amount of retroactive pay (balance) due the employee and his new salary as well.
For Flowchart, symbols used are the following: Terminal symbol I/O symbol Preparation symbol
Decision symbol
2.) Display
Syntax: Display <string> Display <variable> Display <variable1>, , <variableN>
3.)
if-then-else
begin statements . . . end
else
begin statements . . . end
Syntax #2: if <condition1> then begin statements end else if <condition2> then begin statements end else if <conditionN> then begin statements end else begin statements end
Selection/Conditional Structure #1] Using Visual Logic, create a flowchart and a pseudo-code that will prompt the user to input two number and output the highest number entered.
Flowchart
Start
Input N1, N2
Y If N1 > N2 N Output N2 A End Output N1 A
Pseudocode
Variables Used: N1, N2 are numeric
Begin
Display Input two numbers: Accept N1, N2 if (N1 > N2) then Display N1 else Display N2 End
#3] Bongga Ka Day Inc. gives additional performance bonuses to its employees every year. The amount is dependent on the number of years of service of the employee as follows:
Years of Service
Amount of Bonus
Decision symbol
For Pseudo code, keywords used are the following: 1.) Accept 2.) Display 3.) if-then, if-then-else 4.) while-do Syntax:
while <condition> do
begin statements;
. . .
end
Start
Flowchart
X = 10 Y=5
Output X, Y X=X1 Y=Y+5 Y N End
If X >= 6
Pseudo code
Variables Used: X, Y are numeric
Begin
X = 10 Y=5 while (X >= 6) do begin Display X, Y X=X1 Y=Y+5 end End
Start
X=0 Y=1 Sum = 1
Flowchart
If Sum <= 55
End
Pseudo code
Variables Used: X, Y, Sum are numeric Begin X=0 Y=1 Sum = 1 while (Sum <= 55) do begin Display Sum Sum = X + Y X=Y Y = Sum end End
Assignment #1.4 Iterative Program Structure Using Visual Logic: #1] Create a flowchart/pseudo code that will input five numbers and output how many of the numbers entered are odd or even. #2] Create a flowchart/pseudo code that will input five numbers and output how many of the numbers entered are positive or negative.
#4] #5]