Chapter 5: behaviour
Questions

 
1.     How is a creation policy specified? What does a creation policy control? Can a class have two creation policies?

2.     How is an export policy specified? What does an export policy control? Can a feature have two export policies?

3.     What is Eiffel’s default export policy when nothing is written? What is the default export policy you should use when designing a system?

4.     Why must an equality function be exported to its own class?

5.     What is an assertion? Can an assertion be implemented as a routine? Does an assertion have to have a label?

6.     What is a precondition? What keyword precedes the precondition in a feature? Where are the preconditions written in a routine?

7.     What is a postcondition? What keyword precedes the postcondition in a feature? Where are the postconditions written in a routine?

8.     What happens when a routine with assertions is called?

9.     How does Eiffel use preconditions to generate error messages?

10.   What is the complete interface definition for a feature?

11.   What is the ouput from running short on a class? Run short on the following classes:
•       REAL
•       INTEGER

12.   Run short on each class of the current case study to show the class interfaces. Run the system, using data that will crash the system with an assertion violation.

13.   Consider the following specification:

Bill the builder

Bill the builder has come to you for help. He has a job to convert a tool shed into a shrine to Elvis Presley, and needs to know how much he should charge for the building job. Write a system that prompts him for input, and shows him the amount of material he needs, and the amount of money he should charge for the job.

The tool shed consists of one large, rectangular room. It is 3 meters high, 2.8 meters wide, and 5.6 meters long. The owner, Mr. Prince, wants to cover the walls in an expensive wallpaper made of crushed red velvet, with silver outlines of Elvis on it. The windows he wants are specially glazed with frosted outlines of angels. The doors are covered with mats of Kentucky blue grass.

Show Bill how much wallpaper, glass, and matting he should buy, and how much to charge Mr. Prince. Wallpaper comes in rolls of 50 square meters, and costs $299.99 per roll; you cannot buy partial rolls. Glass is cut to size, so Bill can buy exactly as much as he needs; glass costs $89.99 per square metre. Matting is bought in units of a square metre, and costs $312.00 per square metre; you cannot buy it in smaller pieces. Bill charges $45 an hour for his labor.

Mr. Prince keeps changing his mind about how many windows and doors he wants, and how large they are. Thus, you have to read in all the relevant data as input, since the plans can change without notice. When he took the job, Bill insisted that all the doors in a wall were the same size, and all the windows in a wall were the same size. Read in the number of windows in each wall, and their dimensions, read in the number of doors in each wall and their dimensions, and calculate the amount of material that Bill has to buy. After all the room details have been input, ask Bill how many hours he thinks he will need to do the job. Show the amount and price of each material needed, the amount and price of labor needed, and the total price for the job.

Program details

The program reads in, for each wall, the number and size of the windows, and the number and size of the doors. It also reads the estimated number of hours needed for labour. The program calculates the amount of each material needed, and the cost of buying the materials. Bill can cut the wallpaper and matting to size, so you need not worry about whether a window cuts Elvis in half, or not. The program also finds the cost of labour, and the total cost of the job. Assume that all measurements are accurate to two decimal places. A sample output from the program looks like this:

a)     Define the data used in the system and work out the data flow.
b)     Define the classes in the system by placing each of the variables in a class.
c)     For each class, define the signature for each feature.

14.   Write down three antibugging strategies.

15.   Write down six debugging strategies. In what order should they be applied?

16.   Hand execute the case study. Draw a table with one column for each variable in each class. Show the value of each variable at each point in time by writing the value in the table; time is captured by moving down a column.