TH RD

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Name : Artha Bastanta

Class : LJ01

NIM : 2301944784

EXERCISE – SESSSION 7TH (MEETING 3RD TUTOR CLASS)

Individual Assignment

Type: Open Book, Open Note, Internet is allowed.

In the following questions, you will need to:

Create a solution algorithm using pseudocode


Desk check the solution algorithm using two valid test cases.

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.

Input Processing Output


Read 2 number 1.Compute the sum of two 1.Print two numbers
Read interger code code 2.Print interger code
2.If code is 2 compute the 3.if code not equal to 1,2,3,4
difference print error code
3. If code is 3 compute the 4. Display result to screen
product of two numbers
4.If code is 4 , second
number is not zero, compute
quotient

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

Statement number_1 number_2 code result message IF


First Get 10 4 2
pass Set 0 blank
CASE 6
IF true
Display yes yes yes yes
Second Get 20 5 6
pass Set 0 blank
CASE invalid
integer
code
IF false
Display yes yes yes yes
2. Design an algorithm that will prompt a terminal operator for the price of an article and a
pricing code. Your program is then calculate a discount rate according to the pricing code
and print to the screen the original price of the article, the discount amount and the new
discounted price. Calculate the pricing code and accompanying discount amount as follows:

PRICING CODE DISCOUNT RATE


H 50%
F 40%
T 33%
Q 25%
Z 0%

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.

Input Processing Output


Price Declare originalPrice as  "Enter price of an article"
Pricing_code double input price”
Declare pricingCode as Discount_amount
string New_price
Declare discountAmount as “no discount”
double “invalid pricing code”
Declare discountPrice as
double

Start
if pricingCode = "H"

Then discountAmount = (50/100) * originalPrice


discountPrice =originalPrice – discountAmount
else if pricingCode = "F" Then

discountAmount = (40/100) * originalPrice

discountPrice =originalPrice – discountAmount

else if pricingCode = "T" Then

discountAmount = (33/100) * originalPrice

discountPrice =originalPrice - discountAmount


else if pricingCode = "Q" Then

discountAmount = (25/100) * originalPrice

discountPrice =originalPrice – discountAmount

output "Original price of article =" +& originalPrice & ", Discount Amount= " &

discountAmount & ", New discounted price= " & discountPrice

else if pricingCode = "Z" Then

output "No discount"


else

output "Invalid pricing code entered"


End If

DESK CHECKING

First data Second data

price 10$ 30$


Pricing_code F S

First data Second data

Price 10$ 10$

New_price 6$ 0

Messege Blank ‘Invalid pricing code’


Statement Price Pricing_Code Discount_amoun New_price Messege
Number t
First Pass
1,2 10$ F
3,4 0 0 Blank
5 4$
6 6$
display display Display
Second Pass
1,2 10$ S
3,4 0 0 Blank
5 Invalid
Pricing Code
6 Display Display Display

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.

Input Processing Output


Payroll_amount SET Total_payroll_amount to  Total_payroll_amount
ZERO
Compute
Total_payroll_amountPrint
Total_payroll_amount

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

First data Second data Third data


PAYROLL_ AMOUNT 25$ 30$ 999

Statement payroll_amount total_payroll_amount DOWHILE


number
1   0  
2, 3 $25.00    
4     true
5   $25.00  
6, 7 $30.00    
4     true
5   $55.00  
6, 7 999    
4     false
8   display  

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.

Input Processing Output


Name Print Report Headings Report Headings
Gender Read Student Record Married_man
Age Compute Totals Single_men
Marital_Status Select Single Men>30 Married_woman
Print Totals Single_woman
Eligible_bachelors

Set marriedMen to 0
Set singleMen to 0
Set marriedWomen to 0
Set singleWomen to 0
Set hasPrintedHeader to False

READ name, sex, age, status


DOWHILE(NOT EOF)
IF (status = married) THEN //check if status is married, if yes then check next
IF (sex = 'F') THEN //check if sex is F, if yes then +1
marriedWomen = marriedWomen + 1
ELSE
IF (sex = 'M') THEN //under married, and sex is M then +1
marriedMen = marriedMen + 1
ENDIF
ENDIF
ENDIF

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

Print 'Student Summary Report'


Print 'Married Men: ', marriedMen
Print 'Single Men: ', singleMen
Print 'Married Women: ', marriedWomen
Print 'Single Women: ', singleWomen

You might also like