0% found this document useful (0 votes)
77 views2 pages

T4 Homework 4

The document provides code for a program that checks if a package meets size requirements for shipping. It asks the user to enter the length, width, and height of a package. It then calculates the volume and checks if the volume is less than 2.5 cubic meters and each dimension is less than 1 meter. If the package passes these checks, it outputs that the package is accepted, otherwise it outputs that the package is too large. The document asks to: 1) Replace the variable names with more meaningful names. 2) Add two comments to explain complicated lines of code. 3) Rewrite the code to use a function to check if a package is an acceptable size.

Uploaded by

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

T4 Homework 4

The document provides code for a program that checks if a package meets size requirements for shipping. It asks the user to enter the length, width, and height of a package. It then calculates the volume and checks if the volume is less than 2.5 cubic meters and each dimension is less than 1 meter. If the package passes these checks, it outputs that the package is accepted, otherwise it outputs that the package is too large. The document asks to: 1) Replace the variable names with more meaningful names. 2) Add two comments to explain complicated lines of code. 3) Rewrite the code to use a function to check if a package is an acceptable size.

Uploaded by

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

Homework 4 Maintainable programs

Unit 10 Advanced programming and databases

Name:............................................................................ Class:................... Mark:................

The following program asks the user to enter dimensions of a package they wish to send. If the
volume of the package is greater than 2.5 m3 or any side of the package is greater than 1 metre,
the package won’t be accepted.

INPUT a
INPUT b
INPUT c

d  a * b * c

IF d > 2.5 OR a > 1 OR b > 1 OR c > 1


THEN
OUTPUT "Package too large"
ELSE
OUTPUT "Package accepted"
ENDIF

(a) The identifiers that have been used are not meaningful. Replace each identifier
in the table below with a more meaningful one. [4]

Current identifier name Meaningful identifier name


a
b
c
d

(b) Add two comments to the code above that would make the program more
maintainable by explaining what more complicated lines of code do. [2]

1
Homework 4 Maintainable programs
Unit 10 Advanced programming and databases

(c) The code would be more maintainbable if it made use of a function to calculate if a package
was accepted or not. This function would return TRUE if the package was an acceptable
size and FALSE if not.
Rewrite the code to make use of a function. The new program should use meaningful
identifiers, however, you do not need to add comments to it. [6]

[Total 12 marks]

You might also like