include_template( 'topper.html' ); ?> CS 3304 semester(); ?> Homework Assignment 13 include_template( 'page-start.html' ); ?>
Note: The following instructions are repeated from the Homework Dates/Guidelines page:
Your solutions for each homework assignment must be prepared with a word processor (e.g., LaTeX or Word), and are due at the beginning of class on the due date specified unless otherwise noted on the assignment itself.
Note that all homework problems taken from the text are in the Problem Sets. Do not turn in solutions to Review Questions by mistake!
Also, remember that the 5th Edition text includes a new chapter--Chapter 4. All chapter numbers in homework assignments are from the 5th Edition, so students with earlier versions of the text must remember that in their books, the chapter numbers are off by one. If you have an earlier version of the text, you are still responsible for solving the correct problems.
section_title( 'Problems' ) ?>Complete each of the following problems:
Chapter 14, Problem 11 (Chapter 13 in 4th ed.)
To complete this problem, consider the following about Ada:
The exception End_Error
is raised if you
read past the end of a file.
The exception Data_Error
is raised if input
data doesn't satisfy the format required by Get()
.
The exception Numeric_Error
is raised if
a numeric operation cannot produce the correct result (e.g.,
overflow and underflow for integers or fixed point types,
among other things).
You can model your solution on the code sample in 14.3.5.
Note that the first line, "with Text_IO; use Text_IO;
"
imports the standard library operations for file I/O. The
code in 14.3.5 uses the following generic package instantiation
to create a custom I/O module for dealing with integers:
package Integer_Text_IO is new Integer_IO( Integer ); use Integer_Text_IO;
This generic package instance provides a Get()
operation that can be used to read integer
values from stdin.
Instead, I would recommend defining your own type
that corresponds to the correct subrange on integers,
and instantiating Integer_IO
with your
type. This will provide a custom Get()
operation
for your type that will automatically raise Data_Error
for integers outside the allowable range for your type (just
as it will if there are characters instead of digits, or any
other invalid input values).
The Ada 95 Reference Manual can be used to answer questions.
Chapter 13, Problem 6 (Chapter 12 in 4th ed.)
Chapter 13, Problem 9 (Chapter 12 in 4th ed.)