SEM510b Theory of Programming.

 

Examination January 1997.

 

2 hours

Answer BOTH questions.

 

1. Assume that you have been employed to replace a programmer who has been sacked for incompetence. You have been asked to go through his previous work and improve the designs of the modules on which he was working. The first one you come to is the following module:

 

Procedure seekrec

Purpose: To find a record within a file.

Input: none

Output: nextrec (the required record).

 

Data Table: not needed.

 

Pseudo-code

            1. Ask the user to input a file name.

            2. Read the filename

            3. Open the file.

            4. Loop until ans=“yes”

                        5.1 Read Record

                        5.2 Display record.

                        5.3 Ask user if this is the required record.

                        5.4 Read ans

                        5.5 Close file

            6. End loop

            7. End of procedure.

 

(a) Produce a flow chart corresponding to this module (including the errors in logic). 10%

 

(b) Identify the errors in logic (which will prevent the module producing a result) and also comment on other non-fatal errors which make it hard to understand. Produce pseudo-code and a data table for a single revised module which would work. 10%

 

(c) Comment on the cohesion of this module and discuss whether it would be better expressed as more than one module. If it were split, comment on the coupling between these modules. 10%

 

(d) Describe what is meant by the term “glass-box” testing and discuss how it may be applied to this module or modules. 10%

 

(e) Describe what is meant by “black-box” testing.  Discuss how it may be applied to this module or modules and suggest suitable test data. Can you identify equivalence classes for this example? If not, give an example which does illustrate this concept.  10%

 

 


2. A project has been set up to study detailed variations in the weather over an area of countryside. This involves the recording of data from twenty local weather stations, which take automatic measurements every hour and send the resulting data record to a central system. The central system builds up an archive of data and carries out further analysis. You are asked to consider the system for processing the data at one of these local stations.

 

            Every hour, each weather station collects information from its instruments and calculates values from them. It forms a single record of the data, adds the time and an identification of the station and transmits the resulting record to the central station. The instruments provinding these readings are an anemometer from which windspeed is calculated, wet and dry bulb thermometers from which temperature and humidity are calculated, and instruments to measure the number of seconds of sunlight during the past hour and the number of mm of rainfall during the past hour.

 

            In addition to these hourly readings, totals must be accumulated to provide a summary for the weather station which is calculated and transmitted at midnight each day, together with the date and the station identifier. This summary contains the total amount of sunshine (in hours and fractions of an hour) and the percentage of  hours of daylight for which the sun was shining, the total amount of rainfall and the maximum, minimum and average values of windspeed, temperature and humidity for that day.

 

(a) Draw a data-flow diagram to describe the processing carried out at one of these weather stations.  10%

 

(b) Describe what is meant by “afferent”, and “efferent” modules and identify them in your  data flow diagram. Also identify the central transforms.  10%

 

(c) Perform first-level factoring of this diagram. 10%.

 

(d) Complete the structure chart by applying further factoring where this is appropriate. 10%

 

(e)  Produce a schema in Z for the module “sunshine” which converts the total sunshine in seconds to hours and fractions of an hour and calculates the percentage of sunshine (the total hours of sunshine as a percentage of the hours of daylight for that date). 10%