Chapter 2: data flow
Questions
 

1.     How is an attribute declared? How is a constant declared? What is the difference betwen a literal and a constant? Can an attribute have the same name as a class?

2.     When should I use a literal and when a constant?

3.     What is the default or initial value of an attribute?

4.     What are the names of the three numeric types in Eiffel? Is there a class for each type? Is there a text file for each type? How can you get a list of the operators defined for each type?

5.     Write down a command to read in
•       an integer
•       a real number
•       a double precision real number
•       a character

6.     An input command gets a value from the user, and stores it in a buffer. How do you get the value from the buffer? How many instructions are there to get a value from an input buffer?

7.     Describe the general method for getting a value from the user. Write the declarations and code needed to read and store
•       two integers
•       two real numbers
•       an integer and a real number

8.     Write down the command to output
•       an integer
•       a real number
•       a double precision real number
•       a character

9.     When do you need a prompt? a label?

10.   Explain, step by step, how an assignment statement works.

11.   What is meant by operator precedence? What is the numeric operator precedence order?

12.   Evaluate the following expressions, showing each step:
•      1 + 2 * 3 / 4.0
•      1 // 2
•      34 // 4.5
•      1 // 2 \\ 3
•      1 \\ 2 * 3 // 4 / 5.0
•      -43 // 4 ^ 2
•      -((12 / 3.0) * (0 // 7) + 2)

13.  Write a class X that consists of a single make routine, plus attributes. Write a make routine to read in the weight of an object in pounds, convert the weight to kilograms, and show the answer. The program should print out both the weight in pounds and in kilograms. One pound is equal to 0.453592 kilograms.

14.  Write a class X that consists of a single make routine, plus attributes. Write a make routine that converts degrees in fahrenheit to degrees in centigrade. Fahrenheit degrees range from 32 degrees F (freezing point of water) to 212 degrees F (boiling point of water), Centigrade degrees range from 0 (freezing) to 100 (boiling).

15.  Write a class X that consists of a single make routine, plus attributes. Write a make routine that reads in an employee's hourly rate, the number of hours worked, and the tax rate. It then finds and shows the gross salary (before tax) and net salary (after tax) for the employee.

16. Write a class X that consists of a single make routine, plus attributes. Write a make routine that finds the time and cost of a car trip. The input data is the distance covered on the trip, the average speed, the number of litres of petrol used per hundred kilometres, and the cost of a litre of petrol.

17. Write a class X that consists of a single make routine, plus attributes. The specification is:

"You have decided to become a rock concert entrepreneur and want to use your knowledge of computing to help with the accounting. Write a system that calculates your individual profit and the total attendance for a rock concert.

There are three ticket prices, the cheap seats at $10, the standard seats at $20, and the special seats for $100 each. The special ticket holders get to sit in the front row, plus a pair of autographed sunglasses, plus a chance at a backstage pass. You must pay for the rent on the stadium, cost of the band, security and insurance. The security is calculated at 32 cents per person attending. The insurance is 3.6% of the income.

You have two partners in this venture, and must split the profits evenly between all three partners. You must pay 12.5% tax on any profits made from the concert. Show the net (after tax) profit per person, and the total attendance at the concert."