In the remainder of this text we introduce more features of the Ada language and provide rules for using these features. You must remember throughout that, unlike the rules of English, the rules of Ada--like those of any computer language--must be followed precisely. The compiler will be unable to translate Ada instructions that violate these rules. Remember to declare every identifier used as a variable or constant and to terminate program statements with semicolons.
Table 2.7
Summary of New Ada Constructs
Construct EffectContext Clause
WITH Ada.Text_IO; indicates that package Ada.Text_IO is used by the program
Program Heading
PROCEDURE Payroll IS identifies Payroll as the name of the program
Constant declaration
Tax : CONSTANT Float := 25.00; associates the constant, Tax, with the Float value 25.00
Star : CONSTANT Character := '*'; associates the constant, Star, with the Character value '*'
Variable declaration
X: Float; allocates a memory cell named X for storage of Float numbers Me : Integer; allocates a memory cell named Me for storage of Integer numbers
Assignment Statement
Distance := Speed * Time; assigns the product of Speed and Time as the value of Distance.
Input Statements
Ada.Text_IO.Get(Item=>Initial); enters data into the character variable Initial
Ada.Integer_Text_IO.Get(Item=>HowMany); enters data into the integer variable HowMany
Ada.Float_Text_IO.Get(Item=>PayRate); enters data into the float variable PayRate
Output Statements
Ada.Text_IO.Put(Item=>Initial); displays the value of the character variable Initial Ada.Integer_Text_IO.Put(Item=>HowMany, Width=>5); displays the value of the integer variable HowMany, using five columns on the display Ada.Float_Text_IO.Put(Item=>GrossPay, Fore=>4, Aft=>2,Exp=>0); displays the value of the float variable PayRate using four columns before the decimal point and two columns after the decimal point
X
by the following statement?
X := 25.0 * 3.0 / 2.5;
X
by the following statement?
X := X - 20.0;
X
is
3.456.
Ada.Text_IO.Put(Item => "Three values of X are"); Ada.Float_Text_IO.Put(Item => X, Fore => 2, Aft => 1, Exp => 0); Ada.Text_IO.Put(Item => '*'); Ada.Float_Text_IO.Put(Item => X, Fore => 1, Aft => 2, Exp => 0); Ada.Text_IO.Put(Item => '*'); Ada.Float_Text_IO.Put(Item => X, Fore => 2, Aft => 3, Exp => 0); Ada.Text_IO.New_Line;
N
is 345.
Ada.Text_IO.Put(Item => "Three values of N are"); Ada.Integer_Text_IO.Put(Item => N, Width => 4); Ada.Text_IO.Put(Item => '*'); Ada.Float_Text_IO.Put(Item => N, Width => 5); Ada.Text_IO.Put(Item => '*'); Ada.Float_Text_IO.Put(Item => N, Width => 1); Ada.Text_IO.New_Line;
Ada.Integer_Text_IO.Get
is called twice in
succession, for example
Ada.Integer_Text_IO.Get(Item => X); Ada.Integer_Text_IO.Get(Item => Y);What character(s) may be typed after the first number is entered? What may be typed after the second number is entered?
Ada.Integer_Text_IO.Get
is called twice in
succession, for example
Ada.Text_IO.Get(Item => X); Ada.Text_IO.Get(Item => Y);What happens if a blank is entered after the first character? What happens if
RETURN
is pressed after the first character?
30.0
10.0
Three values of X are 3.5*3.46* 3.456
Three values of N are 345* 345*345
Natural
, Character
,
Float
(or NonNegFloat
)
RETURN
s; same
Y
; the RETURN
will
be skipped and the next character (if it is not a RETURN
) will be
read into Y
.
X
,
Y
, and Z
and then finds and displays their product
and sum.
Minutes
) and seconds (Seconds
)
for this runner and then computes and displays the speed in feet per second
(FPS
) and in meters per second (MPS
). (Hint: There
are 5280 feet in 1 mile and 1 kilometer equals 3282 feet.) Test your program on
each of the times below.
Minutes Seconds 3 52.83 3 59.83 4 00.03 4 16.22
Copyright © 1996 by Addison-Wesley Publishing Company, Inc.