Escolar Documentos
Profissional Documentos
Cultura Documentos
Objective
After completion of this lab students will be able to design different flow charts for solving
problems that include decisions.
Description
Arithmetic Operators
The following table summarizes the Visual Logic arithmetic operators, and their usage in
arithmetic expressions. You will use most of these in future assignments.
Operator
+
*
/
\
^
Mod
Operation
addition
subtraction
multiplication
realdivision
integerdivision
exponentiation
modulus
Example
Sum=5+3
Diff=5-3
Product=5*3
Quotient=5/3
Answer=5\3
Power=5^3
Remainder=5Mod3
Explanation
Sum=8
Diff=2
Product=15
Quotient=1.6666666
Answer=1 (nodecimals)
Power=125 (5*5*5)
Remainder=2
NOTE: modulus is another term for the remainder after division. Some more examples:
22 Mod 5 evaluates to 2 ( 5 divides into 22 four times with 2 remainder )
36 Mod 7 evaluates to 1 ( 7 divides into 36 five times with 1 remainder )
Virtually all computer programs of any significance can make decisions and execute different
branches of code based on the decision outcome. Often this means that one block of code will
execute if a specified condition is true, but another block of code will execute if that condition
was false.
In most programming languages, branching is achieved with IF. Visual Logic is no exception.
To illustrate branching, we will create a Visual Logic program that determines if a user is old
enough to vote in the USA.
Run the program a few times. Try ages older and younger than 18. Try 18, too.
The program should respond properly with respect to the Age variable. This simple program used
only one symbol in both branches of the IF, but multiple operations in each branch are common.
Operators Used for IF conditions
ConditionalOperator Explanation
<
>
<=
>=
=
<>
Less than
Greater than
Less than or equal to
Greater than or equalto
Equal to
Not equal to
Nested IFs
The branches of an IF diamond can themselves contain IFs that have their own branches. This is
called nesting. For example, a program that qualifies a voter in the USA should ensure that the
user is a US citizen, in addition to the age test. Lets try this.
Compound Conditions
By using logical operators, programmers can create compound conditions for IF symbols.
Logical Operators
Operator
AND
OR
NOT
Explanation
Lessthan
Greaterthan
Lessthanorequalto
As an example of a compound condition, we will modify the previous program to make it detect
a teenager.
This compound condition will be True for a teenager, since teenagers are aged between 13 and
19, inclusive. Note that there are two distinct conditions separated by the logical operator AND,
and note that both conditions must be True for a teenager.
NOTE: Each condition in a compound condition must be enclosed within parentheses.
Run the program at least three times. Try ages for teenagers and
ages that are too young or too old for a teenager.
Note that the False branch executes for input that is too young or too old.
Deliverables
Compile a single Word document by submitting flowcharts screen shots and output windows
screen shots for each question.
This lab is graded. Min marks: 0. Max marks: 10.
Lab Task
Question 1) Draw flow chart using Visual Logic to find out whether Number is an odd number
or even number after taking user input.
Question 2 ) Draw flow chart using Visual Logic to calculate Electricity Bill by taking units
from user and calculate the total bill according to the following criteria.
uptil 100 Rs.4/units
more than 100 till 300 Rs.4.50/units
above 300 Rs.4.75/units
Add fuel surcharge 20% and Govt. Tax 10% on bill to calculate the total bill.
Question 3) Draw a flow chart using visual logic to design a vending machine for cafeteria.
Display the menu as follows
Item
Price
Soft dirnk
Rs.20
Pizza
Rs 100
Burger
Rs 150
Ask the user for desired item and ask for payment. Output the change or insufficient amount on
screen after calculation.
NOTE: You can only take 100, 500 and 50 rupees as input for money. Else reject the request.