CIT 104 exercise 2_3_Real2
CIT 104 exercise 2_3_Real2
(Hint: )
2. Problem Specification:
(a) Determine
• Problem to solve: Convert Fahrenheit temperature
to Celcius and display the result
• Basically a converter
• The temperature value will be given in Fahrenheit.
This temperature converter program will be able to convert
temperature values from Fahrenheit to Degre and vice versa.
• Identify outputs:
The Equivalent temperature
value in degree celcius
1
(c) The relationship between the
output and input is given by the
relation : )
Where c is the variable to hold the value
of the calculated temperature in degree
celcius.
F is the given value or inputed value for
the temperature in Fahrenheit
1. Start
2. Get the temperature in Fahrenheit from the end-user
3. Subtract 32 from the temperature in Fahrenheit
4. Multiply the result by 5/9
5. Store the result as the temperature in Celsius
6. Stop
A flowchart is a diagrammatical representation of an alborithm
2
4. Implementation (Coding)
(a) Visual Studio ver 2015 code
3
(a) Visual Basic 6 ver coding
4
The code can be modified and improved upon as follows:
1. We can add a button to clear the textbox after each operation
2. We can add another button to close the form or program when we
are through with the conversion operation.
3. Finally, you can make it an executable file.
VB 6.0 (After completing project save it, Then click on file menu, In file menu there
is an sub menu ‘Make Project’, After clicking on Make Project sub menu it will open a
save dialog box to locate the path where .exe file will be created. Select the location
and click on Ok then your project will be converted into .exe file at specified location)
5
The code for the modified version of the form is as given below;
Dim C As Double
C = Text1.Text
Text2.Text = ((C * 9) / 5) + 32
Else
End If
End Sub
6
Private Sub Command2_Click()
Dim F As Double
F = Text2.Text
Text1.Text = (5 * (F - 32) / 9)
Else
End If
End Sub
End
End Sub
Text1.Text = ""
Text2.Text = ""
End Sub
7
Exercises Three: Practical Three
Write a program to calculate your monthly take-home pay
considering the following allowances and deductions on your
basic salary
Allowances
Transport = 10% of your basic salary
Rent = 15% of your basic salary
Hazard = 6.5% of your basic salary
Deductions
Pension = 7.5% of basic salary
NHIS = 5% of basic salary
Tax = 2% of basic salary
(Hint: To calculate percentage of a number use
Solution:
Problem Statement:
1. You are required to provide solution to the
problem as:
Given an employee basic salary, you are required to calculate
his or her monthly take-home pay (Net Pay) after the addition
of allownces and subtraction of deductions.
2. Problem Specification:
(a) Determine
• Problem to solve: To calculate an Employee Net pay
after calculating the Gross pay minus other
deductions.
8
• Given:
• The value of the Basic salary of the employee
• Allowances
Transport = 10% of your basic salary
Rent = 15% of your basic salary
Hazard = 6.5% of your basic salary
Deductions
Pension = 7.5% of basic salary
NHIS = 5% of basic salary
Tax = 2% of basic salary
Hint: To calculate percentage of a number use
Identify outputs:
Gross Pay = (Basic + Total Allowances)
Net-Pay = (Gross pay – ( Total Deductions))
9
Flowchart of the solution
Start
Stop
4. Implementation (Coding)
Visual Basic 6.0 code
*** Improve on the code above by giving object the right name for easy
identification and debugging.
12
The output in Visual Basic ver 6.0
13