You are on page 1of 10

Lab 4.

1
Create a flowchart using Visual Logic to represent the logic of a program that displays the
number of vacation weeks due to an employee. The program should allow the user to enter the
number of years with the company from the keyboard. The number of vacation weeks is based
on the number of years the employee has been with the company, as shown in the following
table. Be sure and test your logic thoroughly.
Years with the company

Weeks of vacation

1-5

6 and over

*If the user enters a negative number; expected output should be:

*If the user enter 10 for the number of years with company:

Algorithm:
a. Let the program allow the user to enter the number of years with the company.
b. The number of vacation is based on the number of years the employee has been with the
company.
c. If the user enters a negative number of years, the program should display an Invalid
years message.
d. If the user enters 10 for the number of years with the company. The program should
display a You have 2 weeks of vacation.
e. Display the output.

Pseudo Code:

a. Let variable ny be the number of years with the company.


b. If condition: ny=0
If true, display output= You have 0 weeks of vacation.
If false, make another condition.
c. If condition: (ny<=5) AND (ny>=1)
If true, display output= You have 1 week of vacation.
If false, make another condition.
d. If condition: ny>=6
If true, display output=You have 2 weeks of vacation.
If false, make another condition.
e. If condition: ny<0
If true, display output= Invalid Years
f. End

Flowchart:

Variable Used and Explanation:


1. ny
The variable ny is used to represent the number of years of the employee with the company. This
variable is used by the user to enter the amount of years from the keyboard.

Condition Used and Explanation:


1.
2.
3.
4.

ny=0
(ny<=5) AND (ny>=1)
ny>=6
ny<0

The first condition ny=0, it is used to test if the user enter the amount 0 then the condition is
true, or else it falls to the second condition which is (ny<=5) AND (ny>=1). This condition
test if the user enter the numbers of years between 1-5 then the condition is true which falls
to the output: You have 1 week of vacation. If not it falls again to the next condition and
that is ny>=6. If the user enters 6 and above the program will display the output: You have 2
weeks of vacation. Lastly the condition ny<0 this test is when the user enter a negative
number of years that will display the output: Invalid Years.

Lab 4.2
Create a flowchart using Visual Logic to represent the logic of a program that calculates and
displays the commission and total salary of an employee. The total salary is computed as base
salary plus commission. The program should allow the user to enter the base salary and sales
from the keyboard. The percentage rate for calculating the commission is based on the sales as
shown in the following table:

Sales

Percentage Rate

$0-$14,999

1%

$15,000-$19,999

3%

$20,000 and over

5%

*If the user enters a base salary of $20,000 and sales $25,000, the following output would be
displayed:

*If the user enters a base salary of $15,000 and sales of $5,000, the following output will be
displayed:

Algorithm:
a. Let the program allow the user to enter the base salary and sales.
b. Calculate the commission and total salary of the employee.
c. Display the output.
Pseudo Code:
a. Input salary
b. Input sales
c. If condition: sales<15000
If true, let c1 be the variable for the expression 0.01*sales (c1=0.01*sales)
Let ts1 be the variable for the expression salary+c1 (ts1=salary+c1)
And display output:
The Commission is: & FormatCurrency(c1)
The Total Salary is: & FormatCurrency(ts1)
If false, input another condition.
d. If condition: (sales>=15000) AND (sales<=19999)
If true, let c2 be the variable for the expression 0.03*sales (c2=0.03*sales)

Let ts2 be the variable for the expression salary+c2 (ts2=salary+c2)


And display output:
The Commission is: & FormatCurrency(c2)
The Total Salary is: & FormatCurrency(ts2)
If false, input another condition.
e. If condition: sales>=20000
If true, let c3 be the variable for the expression 0.05*sales (c3=0.05*sales)
Let ts3 be the variable for the expression salary+c3 (ts3=salary+c3)
And display output:
The Commission is: & FormatCurrency(c3)
The Total Salary is: & FormatCurrency(ts3)
f. End
Flowchart:

Variables Used and Explanation:


1.
2.
3.
4.
5.
6.
7.
8.

salary
sales
c1
ts1
c2
ts2
c3
ts3

Expressions Used and Explanation:

1.
2.
3.
4.
5.
6.

0.01*sales
0.03*sales
0.05*sales
Salary+c1
Salary+c2
Salary+c3

Conditions Used and Explanations:

Lab 4.3
Create a flowchart using Visual Logic that represents the logic of a program that displays the
shipping charge as well as calculates and displays the total price to ship an item which is
calculated as item price plus shipping charge. The program should allow the user to enter the
price of the item and a state code. The shipping charge is based on the state code entered by the
user, as shown in the following table.
State Code
AL

Shipping Charge
$35.00

CA

$40.00

ND

$45.00

OK

$45.00

PA

$40.00

TX

$40.00

*If the user enters any other state code, the program should display an error message stating
Incorrect State Code:

*If the user enters an item price of $100.00 and a state code of TX the following output would be
displayed:

Algorithm:
a. Let the program allow the user the price of the item and a state code.
b. Calculate the total price to ship an item.
c. Display the shipping charge and total price of the item.

Pseudo Code:
a. Let variable price be the price of the item.
b. Let variable scode be the state code.

c. If condition: scode=AL
If true, sc=35.00
tp= sc+price
Display output: The Shipping Charge: & FormatCurrency(sc)
The Total Price: & FormatCurrency(tp)
If false, make another condition.
d. If condition: scode=CA
If true, sc1= 40.00
tp1=sc1+price
Display output: The Shipping Charge: & FormatCurrency(sc1)
The Total Price: & FormatCurrency(tp1)
If false, make another condition.
e. If condition: scode=ND
If true, sc2= 45.00
tp2=sc2+price
Display output: The Shipping Charge: & FormatCurrency(sc2)
The Total Price: & FormatCurrency(tp2)
If false, make another condition.
f. If condition: scode=OK
If true, sc2= 45.00
tp2=sc2+price
Display output: The Shipping Charge: & FormatCurrency(sc2)
The Total Price: & FormatCurrency(tp2)
If false, make another condition.
g. If condition: scode=PA
If true, sc1= 40.00
tp1=sc1+price
Display output: The Shipping Charge: & FormatCurrency(sc1)
The Total Price: & FormatCurrency(tp1)
If false, make another condition.
h. If condition: scode=TX
If true, sc1= 40.00
tp1=sc1+price
Display output: The Shipping Charge: & FormatCurrency(sc1)
The Total Price: & FormatCurrency(tp1)
If false, display output: Incorrect State Code
i. End

Flowchart:

Variable Used and

You might also like