• No results found

Cse208 SOFTWARE ENGINEERING LAB 10 Software Design Problems and Solutions

N/A
N/A
Protected

Academic year: 2020

Share "Cse208 SOFTWARE ENGINEERING LAB 10 Software Design Problems and Solutions"

Copied!
18
0
0

Loading.... (view fulltext now)

Full text

(1)

Cse208 SOFTWARE ENGINEERING LAB

10 Software Design Problems and Solutions

(2)
(3)
(4)

Solutions

Note that this provide a desk check of the algorithm for the first five problems only. Desk checking for the remaining five problems will be very similar to the previous five.

Programming problem #1

defining diagram:

Input Processing Output

Years Prompt for years, months months_of_age Months Get years, months ***

Calculate months_of_age Display months_of_age Display asterisks

control structures required:

A DOWHILE loop to control the repetition An IF statement to print asterisks

solution algorithm:

Calculate_months_of_age

Prompt for years, months Get years, months

DOWHILE (years, months) NOT = 9999 months_of_age = (years * 12) + months Display "Age in months = ", months_of_age IF months_of_age > 500 THEN

Display " *** " ENDIF

Prompt for years, months Get years, months ENDDO

END

input data:

First record Second record Third record

Years 25 50 99

Months 7 8 99

expected results:

Age in months = 307 Age in months = 608 ***

desk check table:

Statement years months months_of_age DOWHILE

Get 25 7

DOWHILE true

months_of_age 307

Display yes

(5)

Get 50 8 DOWHILE true months_of_age 608 Display yes IF *** Get 99 99 DOWHILE false Programming problem #2 defining diagram:

Input Processing Output

Diameter Prompt for diameter area

Get diameter circumference Calculate area

Calculate circumference Display area, circumference

control structure required:

A DOWHILE loop to control the repetition

Formula for the area of a circle: area = πr² where π = 3.14 Formula for the circumference of a circle: 2πr where π = 3.14

solution algorithm:

Process circle_measurements Prompt for diameter Get diameter

DOWHILE diameter NOT = 9999 radius = diameter / 2

area = 3.14 * radius * radius circumference = 3.14 * diameter

Display "The area of a circle, of diameter ", diameter, "cm = ", area, " sq cm"

Display "The circumference of a circle, of diameter ", diameter, "cm = ", circumference, " cm" Prompt for diameter

Get diameter ENDDO END

input data:

First record Second record Third record

diameter (cm) 6 26 999

expected results:

The area of a circle, of diameter 6 cm = 28.27 sq cm The circumference of a circle, of diameter 6 cm = 18.85 cm The area of a circle, of diameter 26 cm = 530.93 sq cm The circumference of a circle, of diameter 26 cm = 81.68 cm

desk check table:

Statement diameter radius area circumference DOWHILE

(6)

DOWHILE true

Radius 3

Area 28.27

Circumference 18.35

Display yes yes

Get 26

DOWHILE true

Radius 13

Area 530.93

Circumference 3168

Display yes yes

Get 999

DOWHILE false

Programming problem #3

defining diagram:

Input Processing Output

student_records print report headings Report headings Name Read student record married_men Gender Compute totals married_women Age Select single men,>30 single_women marital_status Print totals eligible bachelors

control structures required:

A DOWHILE loop to control the repetition IF statements to accumulate the totals

An IF statement to select the eligible bachelors

Accumulators for married_men, single_men, married_women, single_women

solution algorithm:

Print_student_reports

Print Student Summary Report heading Print Eligible Bachelors Report heading

Set married_men, single_men, married_women, single_women to 0 Read student record (name, gender, age, marital status)

DOWHILE more records IF gender ="F" THEN IF marital_status = "M" THEN add 1 to married_women ELSE add 1 to single_women ENDIF ELSE IF marital_status = "M" THEN add 1 to married_men ELSE add 1 to single_men IF age > 30 THEN

Print ‘Name: ‘, name, ‘Age: ‘, age (on eligible bachelor’s report) ENDIF

(7)

ENDIF

ENDIF

Read student record ENDDO

Print "Number of married men = ", married_men, "Number of single men = ", single_men

Print "Number of married women = ", married_women, "Number of single women = ", single_women END

input data:

First record Second record Third record Name Jenny Smith John Brown EOF

Gender F M

Age 25 32

marital_status M S

expected results:

Student Summary Report

Number of married men = 0 Number of single men = 1 Number of married women = 1 Number of single women = 0 Eligible Bachelors Report

(8)

desk check table:

Statement Name gender age marital_ status married_men single_men married_women single_women DOWHILE Print

Set 0 0 0 0

Read Jenny Smith F 25 M

DOWHILE true

IF 1

Read John Brown M 32 S

DOWHILE true

IF Print 1

Read EOF

DOWHILE false

Print

(9)

Programming problem #4 defining diagram:

Input Processing Output

employee records Print report headings Report heading emp_num Read employee record employee details hours_worked Calculate gross_pay emp_num rate_of_pay Accumulate

total_gross_earnings

hours_worked Print employee details rate_of_pay Print total_gross_earnings gross_pay

control structures required:

A DOWHILE loop to control the repetition An accumulator for total_gross_earnings

solution algorithm:

Produce_gross_earnings_report

Print ‘Gross Earnings Report’ heading Print ‘ ‘

Print ‘Employee Hours Rate of Gross’ Print ‘Number Worked Pay Pay’ Print ‘ ‘

Set total_gross_earnings to 0

Read employee record (emp_num, hours_worked, rate_of_pay) DOWHILE NOT EOF

gross_pay = hours_worked * rate_of_pay add gross_pay to total_gross_earnings

Print ‘Employee Number: ‘, emp_num, ‘Hours Worked: ‘, hours_worked, ‘Rate of Pay: ‘, rate_of_pay, ‘Total Gross Pay: ‘, gross_pay

Read employee record ENDDO

Print "Total Gross Earnings ", total_gross_earnings END

input data:

First record Second record Third record

emp_new 1111 2220 EOF

hours_worked 40 35 rate_of_pay $15.00 $10.00

expected results:

Gross Earnings Report

Employee Hours Rate of Gross

Number Worked Pay Pay

1111 40 $ 15.00 $ 600.00

2222 35 $ 10.00 $ 350.00

(10)
(11)

desk check table:

Statement emp_num hours_worked rate_of_pay gross_pay total_gross_earnings DOWHILE

Set 0

Read 1111 40 $15

DOWHILE true

gross_pay $600

Add $600

Print yes yes yes yes

Read 2222 35 $10

DOWHILE true

gross_pay $350

Add $950

Print yes yes yes yes

Read EOF

DOWHILE false

(12)

Programming problem #5

defining diagram:

Input Processing Output

employee records Print report heading Report heading emp_num Read employee record employee details hours_worked Calculate gross_pay emp_num rate_of_pay Calculate tax_payable gross_pay

Calculate medical_levy tax_payable Calculate net_pay medical_levy Accumulate totals net_pay

Print employee details total_gross_earnings total_tax

total_medical_levy total_net_earnings

control structures required:

A DOWHILE loop to control the repetition

Accumulators for total_gross_earnings, total_tax, total_medical_levy, total_net_earnings

solution algorithm:

Produce_net_earnings_report

Print ‘Net Earnings Report’ heading Print ‘ ‘

Print ‘Employee Gross Tax Medical Net’ Print ‘Number Pay Payable Levy Pay’ Print ‘ ‘

Set total_gross_earnings, total_tax, total_medical_levy, total_net_earnings to 0 Read employee record (emp_num, hours_worked, rate_of_pay)

DOWHILE NOT EOF

gross_pay = hours_worked * rate_of_pay tax_payable = 15% * gross_pay

medical_levy = 1% * gross_pay

net_pay = gross_pay - (tax_payable + medical_levy)

Print emp_num, gross_pay, tax_payable, medical_levy, net_pay add gross_pay to total_gross_earnings

add tax_payable to total_tax

add medical_levy to total_medical_levy add net_pay to total_net_earnings Read employee record

ENDDO

Print ‘Total Gross Earnings: ‘, total_gross_earnings, ‘Total Tax: ‘, ‘Total Tax: ‘, total_tax, ‘Total Medical Levy: ‘, total_medical_levy, ‘Total Net Earnings: ‘, total_net_earnings

END

input data:

First record Second record Third record

emp_num 1111 2222 EOF

hours_worked 40 35 rate_of_pay $15.00 $10.00 expected results:

(13)

Employee Gross Tax Medical Net

Number Pay Payable Levy Pay 1111 $ 600.00 $ 90.00 $ 6.00 $ 504.00 2222 $ 350.00 $ 52.50 $ 3.50 $ 294.00

Totals $ 950.00 $142.50 $ 9.50 $ 798.00

desk check table:

Statement emp_num gross_pay tax_payable medical_levy net_pay totals DOWHILE

Set 0 Read 1111 DOWHILE true gross_pay $600 tax_payable $90 medical_levy $6 net_pay $504 Add yes

Print yes yes yes yes yes

Read 2222 DOWHILE true gross_pay $350 tax_payable $52.50 medical_levy $3.50 net_pay $294 Add yes

Print yes yes yes yes yes

Read EOF

DOWHILE false

(14)

Programming problem #6

defining diagram:

Input Processing Output

inventory_record Read inventory record valid inventory records record_code Validate inventory record record_code part_no Print valid records part_no

part_desc part_desc

inventory_balance inventory_balance

control structures required:

A DOWHILE loop to control the repetition IF statements to validate the inventory fields

An IF statement to select records with zero inventory balance

solution algorithm:

Process_inventory_records Read inventory record DOWHILE more records Set valid_record to true

IF record_code NOT = 11 THEN valid_record = false

ENDIF

assign 1st 2 characters of part_no to alpha_part_no assign last 4 characters of part_no to numeric_part_no IF alpha_part_no NOT alphabetic THEN

valid_record = false ENDIF

IF numeric_part_no NOT numeric THEN valid_record = false

ENDIF

IF valid_record THEN

IF inventory_balance = 0 THEN Print inventory record

ENDIF ENDIF

Read inventory record ENDDO

(15)

Programming problem #7

defining diagram:

Input Processing Output

inventory_record Read inventory record selected inventory records record_code Validate inventory record record_code

part_no Select inventory records part_no part_desc Print selected records part_desc

inventory_balance Compute total_selected_records inventory_balance Print total_selected_records total_selected_records

control structures required:

A DOWHILE loop to control the repetition IF statements to validate the inventory fields An IF statement to select required records An accumulator for total_selected_records

solution algorithm:

Process_inventory_records

Set total_selected_records to zero Read inventory record

DOWHILE more records Set valid_record to true

IF record_code NOT = 11 THEN valid_record = false

ENDIF

assign 1st 2 characters of part_no to alpha_part_no assign last 4 characters of part_no to numeric_part_no IF alpha_part_no NOT alphabetic THEN

valid_record = false ENDIF

IF numeric_part_no NOT numeric THEN valid_record = false

ENDIF

IF valid_record THEN

IF (part_no >= AA3000 AND part_no <= AA3999) THEN Print inventory record

add 1 to total_selected_records ENDIF

ENDIF

Read inventory record ENDDO

Print total_selected_records END

(16)

Programming problem #8 defining diagram:

Input Processing Output

inventory_record Read inventory record selected inventory records record_code Validate inventory record record_code

part_no Select inventory records part_no part_desc Print selected records part_desc

inventory_balance Compute total_AA_records inventory_balance Compute total_selected_records total_AA_records Print totals total_selected_records

control structures required:

A DOWHILE loop to control the repetition IF statements to validate the inventory fields An IF statement to select required records

Accumulators for total_selected_records, total_AA_records

solution algorithm:

Process_inventory_records

Set total_selected_records, total_AA_records to zero Read inventory record

DOWHILE more records Set valid_record to true

IF record_code NOT = 11 THEN valid_record = false

ENDIF

assign 1st 2 characters of part_no to alpha_part_no assign last 4 characters of part_no to numeric_part_no IF alpha_part_no NOT alphabetic THEN

valid_record = false ENDIF

IF numeric_part_no NOT numeric THEN valid_record = false

ENDIF

IF valid_record THEN

IF (part_no >= AA3000 AND part_no <= AA3999) THEN Print inventory record

add 1 to total_selected_records ENDIF

ENDIF

IF (valid_record AND alpha_part_no = AA) THEN add 1 to total_AA_records

ENDIF

Read inventory record ENDDO

Print total_selected_records, total_AA_records END

(17)

Programming problem #9

defining diagram:

Input Processing Output

Usage_file Print heading Heading

Read header_total_usage

header_record Read usage record Detail line header_total_usage Calculate amount_owing customer_no detail record Print usage details name

customer_no Compute total_usage usage

name compare total_usage figure amount_owing usage

control structures required:

A DOWHILE loop to control the repetition An IF statement to calculate the amount_owing An IF statement to compare the total usage figures An accumulator for total_usage

solution algorithm:

Process_electricity_usage_records

Print Electricity Usage Report heading Set total_usage to zero

Read header_total_usage Read usage record DOWHILE more records add usage to total_usage IF usage > 200 THEN

amount_owing = (200 * 0.11) + ((usage - 200) * 0.08) ELSE

amount_owing = (usage * 0.11) ENDIF

Print customer_no, name, usage, amount_owing Read usage record

ENDDO

Print total_usage, header_total_usage

IF total_usage NOT = header_total_usage THEN

Print "Total calculated usage does not match header record" ENDIF

(18)

Programming problem #10

defining diagram:

Input Processing Output

customer record Read customer record customer details customer_no Calculate min_amt_due customer_no

name Print min_amt_due name

address address

postcode postcode

total_amt_owing total_amt_owing

min_amt_due

control structures required:

A DOWHILE loop to control the repetition

An IF statement to calculate the min_amount_due

solution algorithm:

Calculate_minimum_amount_due Read customer record DOWHILE more records

IF total_amt_owing < $5.00 THEN min_amount_due = total_amt_owing ELSE min_amount_due = total_amt_owing / 4 IF min_amount_due < $5.00 THEN min_amount_due = $5.00 ENDIF ENDIF

Print customer_no, name, address, total_amt_owing, min_amount_due Read customer record

ENDDO END

References

Related documents