Defect Example: The Coin Problem

Specification for the program calculate_coin_value

This program calculates the total rupees value for a set of coins. The user inputs the amount of 25p, 50p and 1rs coins. There are size different denominations of coins. The program outputs the total rupees and paise value of the coins to the user

Input      : number_of_coins is an integer

Output    : number_of_rupees is an integer

number_of_paise is an integer

This is a sample informal specification for a simple program that calculates the total value of a set of coins. The program could be a component of an interactive cash register system. This simple example shows

  • Requirements/specification defects,
  • Functional description defects,
  • Interface description defects.

The functional description defects arise because the functional description is ambiguous and incomplete. It does not state that the input and the output should be zero or greater and cannot accept negative values. Because of these ambiguities and specification incompleteness, a checking routine may be omitted from the design. A more formally stated set of preconditions and post conditions is needed with the specification.

A precondition is a condition that must be true in order for a software component to operate properly.

A postcondition is a condition that must be true when a software component completes its operation properly.

The functional description is unclear about the maximum number of coins of each denomination allowed, and the maximum number of rupees and paise allowed as output values. It is not clear from the specification how the user interacts with the program to provide input, and how the output is to be reported.

1. Design Description for the Coin Problem

Design Description for Program calculate_coin_values
Program calculate_coin_values
number_of_coins is integer
total_coin_value is integer
number_of_rupees is integer
number_of_paise is integer
coin_values is array of six integers representing
each coin value in paise
initialized to: 25,25,100
begin
initialize total_coin_value to zero
initialize loop_counter to one
while loop_counter is less than six
begin
output “enter number of coins”
read (number_of_coins )
total_coin_value = total_coin_value +
number_of_coins * coin_value[loop_counter]
increment loop_counter
end
number_rupees = total_coin_value/100
number_of_paise = total_coin_value – 100 * number_of_rupees
output (number_of_rupees, number_of_paise)
end

2. Design Defects in the Coin Problem

Control, logic, and sequencing defects. The defect in this subclass arises from an incorrect “while” loop condition (should be less than or equal to six)

Algorithmic, and processing defects. These arise from the lack of error checks for incorrect and/or invalid inputs, lack of a path where users can correct erroneous inputs, lack of a path for recovery from input errors.

Data defects. This defect relates to an incorrect value for one of the elements of the integer array, coin_values, which should be 25, 50, 100.

External interface description defects. These are defects arising from the absence of input messages or prompts that introduce the program to the user and request inputs.

3. Coding Defects in the Coin Problem

Control, logic, and sequence defects. These include the loop variable increment step which is out of the scope of the loop. Note that incorrect loop condition (i<6) is carried over from design and should be counted as a design defect.

Algorithmic and processing defects. The division operator may cause problems if negative values are divided, although this problem could be eliminated with an input check.

Data Flow defects. The variable total_coin_value is not initialized. It is used before it is defined.

Data Defects. The error in initializing the array coin_values is carried over from design and should be counted as a design defect.

External Hardware, Software Interface Defects. The call to the external function “scanf” is incorrect. The address of the variable must be provided.

Code Documentation Defects. The documentation that accompanies this code is incomplete and ambiguous. It reflects the deficiencies in the external interface description and other defects that occurred during specification and design.

The poor quality of this small program is due to defects injected during several phases of the life cycle because of different reasons such as lack of education, a poor process, and oversight by the designers and developers.

Leave a comment