Solutions to End-of-Chapter Exercises
Many of these are example solutions, and alternate solutions may look somewhat different.
Only the code of interest appears here, unless the problem specifically asks for code for an
(entire) Ada program.
1. rate : FLOAT;
2. orderOne, orderTwo : INTEGER;
3. evaporationRate : constant := 6.15;
4. stockTime : constant := 4;
inventory : INTEGER;
sales : FLOAT;
5. quiz1, quiz2, quiz3 : INTEGER;
average : FLOAT;
6. list(8)
7. table(3, 2)
8. TEXT_IO.PUT("Enter the time in hours and minutes "
& " (two integer values)");
INT_IO.GET(hours);
INT_IO.GET(minutes);
9. INT_IO.PUT(numberOrdered, 3);
, TEXT_IO.PUT(" ordered for inventory item ");
INT_IO.PUT(inventoryNumber);
10. bbb13bb4b62118
11.
TEXT_IO.PUT("The current density is:");
FLO_IO.PUT(density, 3, 1, 0);
TEXT_IO.NEW_LINE;
TEXT_IO.PUT("to within one decimal place.");
12. 66
13.
TEXT_IO.PUT("Enter the length of the rectangle: ");
INT_IO.GET(length);
TEXT_IO.PUT("Enter the width of the rectangle: ");
INT_IO.GET(width);
area := length * width;
TEXT_IO.PUT("The area of the rectangle is: ");
INT_IO.PUT(area);
14.
a. while more = 'Y' or more = 'y'
b. if taskToDo = 'C' or taskToDo = 'c'
15.
C : CHARACTER;
, TEXT_IO.PUT("Enter a single character: ");
TEXT_IO.GET(C);
if C = 'a' or C = 'e' or C = 'i' or
C = 'o' or C = 'u'
then
TEXT_IO.PUT("Congratulations, you picked a vowel!");
else
TEXT_IO.PUT("You lose, better luck next time.");
end if;
TEXT_IO.NEW_LINE;
16. score := score + 1;
17.
1 20
2 19
3 18
4 17
5 16
6 15
7 14
8 13
9 12
10 11
18.
counter : INTEGER;
, counter := 1;
while counter <= 15
loop
INT_IO.PUT(counter * 2);
TEXT_IO.NEW_LINE;
counter := counter + 1;
end loop;
19.
sum, number : INTEGER;
sum := 0; -- initialize sum
TEXT_IO.PUT("Please enter numbers to add, ");
TEXT_IO.NEW_LINE;
TEXT_IO.PUT("terminate with a negative number. ");
TEXT_IO.NEW_LINE;
TEXT_IO.PUT("Enter a number: ");
INT_IO.GET(number);
loop
sum := sum + number;
TEXT_IO.PUT("Enter a number: ");
INT_IO.GET(number);
exit when number < 0;
end loop;
TEXT_IO.PUT("The total is ");
INT_IO.PUT(sum);
20.
--computes total elapsed time from hours and minutes