0% found this document useful (0 votes)
4 views13 pages

CIT 104 exercise 2_3_Real2

The document provides solutions to practical exercises in programming, specifically focusing on creating a temperature converter and calculating monthly take-home pay based on allowances and deductions. It outlines problem statements, specifications, algorithms, and coding implementations in Visual Basic 6.0 and Visual Studio 2015. The exercises include converting Fahrenheit to Celsius and calculating net pay from a basic salary with various allowances and deductions.

Uploaded by

rtjtcrtxzt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views13 pages

CIT 104 exercise 2_3_Real2

The document provides solutions to practical exercises in programming, specifically focusing on creating a temperature converter and calculating monthly take-home pay based on allowances and deductions. It outlines problem statements, specifications, algorithms, and coding implementations in Visual Basic 6.0 and Visual Studio 2015. The exercises include converting Fahrenheit to Celsius and calculating net pay from a basic salary with various allowances and deductions.

Uploaded by

rtjtcrtxzt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

CIT 104 – Practical Exercises

Solution to Practical Exercises


Exercises Two: Practical Two
Solution:
1. Problem Statement:
You are required to provide solution to the problem
specified as:
Write a program to convert Fahrenheit temperatures to Celsius
and display the results.

(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.

(b) Identify the inputs:


Temperature value in Fahrenheit

• 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

3. Develop an Algorithm or Flowchart of the solution


Algorithm is define as the step by step procedure to be followed in
order to solve a problem.
So, the steps would look something like this:

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

Visual Studio ver 2015 form interface

3
(a) Visual Basic 6 ver coding

The interface in Visual Basic ver 6.0

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)

Visual Studio ver 2015 form

The interface in Visual Basic ver 6.0

5
The code for the modified version of the form is as given below;

(c) Visual Studio ver 2015 code

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim C As Double
If TextBox1.Text <> " " Then
C = TextBox1.Text
TextBox2.Text = ((C * 9) / 5) + 32
Else
MessageBox.Show("Please enter the Value of Temperature in degree Celsius")
End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


Dim F As Double
If TextBox2.Text <> " " Then
F = TextBox2.Text
TextBox1.Text = (5 * (F - 32) / 9)
Else
MessageBox.Show("Please enter the Value of Temperature in Fahrenheit")
End If
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


End
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click


TextBox1.Text = ""
TextBox2.Text = ""
End Sub
End Class

(d) Visual Basic 6.0 code


Private Sub Command1_Click()

Dim C As Double

If Text1.Text <> " " Then

C = Text1.Text

Text2.Text = ((C * 9) / 5) + 32

Else

MessageBox.Show ("Please enter the Value of Temperature in degree Celsius")

End If

End Sub

6
Private Sub Command2_Click()

Dim F As Double

If Text2.Text <> " " Then

F = Text2.Text

Text1.Text = (5 * (F - 32) / 9)

Else

MessageBox.Show ("Please enter the Value of Temperature in degree Fahrenheit")

End If

End Sub

Private Sub Command3_Click()

End

End Sub

Private Sub Command4_Click()

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

(b) Identify the inputs:


 Basic Salary Value to be inputed by the user.

To be calculated from Basic salary are:
 Allowances (Transport, Rent & Hazard)
 Deductions (Pension, NHIS, Tax)

Identify outputs:
 Gross Pay = (Basic + Total Allowances)
 Net-Pay = (Gross pay – ( Total Deductions))

(C) The relationship is given as:


Employee Net Pay = Gross pay – (Total deductions)
(3) Develop an Algorithm + Flowcahrt of the solution
1. Start
2. Get the value of the basic salary from the employee
3. Add all the allowances to the basic salary to obtain Gross-pay (Basic + total
allowances)
4. Subtract total deductions from the Grosspay to obtain the Net-pay
5. Write out the value of Net-pay
6. Stop

9
Flowchart of the solution

Start

Input the value of the


basic salary

Calculate Total Allowance:


(Transport +Rent+Hazard)
Calculate Gross pay:
(Gross-pay=Basic Salary+Total Allowance)

Calculate Total Deductions:


(Pension+NHIS+Tax)
Calculate Net-pay:
(Net-pay = Gross-pay - Total Deductions)

Write out the value


of Net-pay

Stop

4. Implementation (Coding)
Visual Basic 6.0 code

Dim Basic_Salary As Double


Dim Transport As Double
Dim Rent As Double
Dim Hazard As Double
10
Dim Total_allowance As Double
Dim Pension As Double
Dim NHIS As Double
Dim Tax As Double
Dim Total_Deduct As Double
Dim Gross_Pay As Double
Dim Net_Pay As Double
Private Sub Command3_Click()
If Text1.Text <> " " Then
Basic_Salary = Text1.Text
Else
MessageBox.Show ("Please enter Employee Salary amount")
End If
Transport = (Basic_Salary * 10) / 100
Text4.Text = Transport
Rent = (Basic_Salary * 15) / 100
Text5.Text = Rent
Hazard = (Basic_Salary * 6.5) / 100
Text6.Text = Hazard
Total_allowance = (Transport + Rent + Hazard)
Text7.Text = Total_allowance

Pension = (Basic_Salary * 7.5) / 100


Text8.Text = Pension
NHIS = (Basic_Salary * 5) / 100
Text9.Text = NHIS
11
Tax = (Basic_Salary * 2) / 100
Text10.Text = Tax
Total_Deduct = (Pension + NHIS + Tax)
Text11.Text = Total_Deduct
End Sub
Private Sub Command4_Click()
Gross_Pay = Basic_Salary + Total_allowance
Text2.Text = Gross_Pay
End Sub
Private Sub Command5_Click()
Net_Pay = Gross_Pay - Total_Deduct
Text3.Text = Net_Pay
End Sub
Private Sub Command6_Click()
Text1.Text = ""
End Sub

*** Improve on the code above by giving object the right name for easy
identification and debugging.

The ouput from is shown in the form below

12
The output in Visual Basic ver 6.0

13

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy