Professional Documents
Culture Documents
TH RD
TH RD
TH RD
Class : LJ01
NIM : 2301944784
Individual Assignment
QUESTION
1. Design an algorithm that will read two numbers and an integer code from the screen. The
value of the integer code should be 1,2,3 or 4. If the value of the code is 1, compute the sum
of the two numbers. If the code is 2, compute the difference (first minus second). If the code
is 3, compute the product of the two numbers. If the code is 4, and the second number is
not zero, compute the quotient (first divided by second). If the code is not equal to 1,2,3 or 4
display an error message. The program is then to display the two numbers, the integer code
and the computed result to the screen.
Read num_1,num_2
Read int_code
IF int_code = ‘1’ THEN
Compute Sum= num_1 + num_2
ELSE
IF int_code = ‘2’ THEN
Compute Diff = num_1 + num_2
ELSE
IF int_code = ‘3’ THEN
Compute Prod = num_1*num_2
ELSE
IF int_code =’4’ ANDnum_2 <> 0
Compute Quotient = num_1/num_2
ENDIF
ENDIF
ENDIF
Print num_1, num_2, int_code
Print Sum, Diff, Prod, Quotient
IF int_code <> ‘1’,’2’,’3’, OR ‘4’
Print error_msg = ‘Error’
ENDIF
DESK CHECKING
First data set Second data set
number_1 10 20
number_2 4 5
code 2 6
if the pricing code is Z, the words ‘No discount’ are to be printed on the screen, if the pricing
code is not H, F, T, Q or Z, the words ‘Invalid pricing code’ are to be printed.
Start
if pricingCode = "H"
output "Original price of article =" +& originalPrice & ", Discount Amount= " &
DESK CHECKING
New_price 6$ 0
3. Design an algorithm that will prompt for, receive and total a collection of payroll amounts
entered at the terminal until a sentinel amount of 999 is entered. After the sentinel has been
entered, display the total payroll amount to the screen.
Calculate_total_payroll_amount
Set total_payroll_amount to 0
Prompt for payroll_amount
Get payroll_amount
DOWHILE payroll_amount NOT = 999
Add payroll_amount to total_payroll_amount
Prompt for payroll_amount
Get payroll_amount
ENDDO
Display ‘Total payroll amount = ', ‘$', total_payroll_amount
END
DESK CHECKING
4. A file of student records contains name, sex, (M of F), age (in years) and marital status
(single or married) for each student. Design an algorithm that will read through the file and
calculate the numbers of married men, single men, married women, and single women,
print these numbers on a student summary report. If any single men are over 30 years of
age, print their names and ages on a separate eligible bachelors report.
Set marriedMen to 0
Set singleMen to 0
Set marriedWomen to 0
Set singleWomen to 0
Set hasPrintedHeader to False
IF (status = single) THEN //check if status is single, if yes then check next
IF (sex = 'F') THEN //check if sex is F, if yes then +1 to singleWomen
singleWomen = singleWomen + 1
ELSE
IF (sex = 'M') THEN //under single, and sex is M then +1
singleMen = singleMen + 1
IF (age > 30) THEN //under single, sex = M and age is over 30 then print the name, age
IF (hasPrintedHeader = False) THEN
Print 'Eligible bachelors Report'
hasPrintedHeader = True
END IF
Print 'Name: ', name
Print 'Age: ', age
ENDIF
ENDIF
ENDIF
ENDIF
READ next record
ENDDO