Imperative language
For the exercises below (except for the first one), don't worry about the
details of the Main procedure. You should just focus on implementing the
application in the subprogram specified by the exercise.
Hello World
Goal: create a "Hello World!" application.
Steps:
Complete the
Mainprocedure.
Requirements:
The application must display the message "Hello World!".
Remarks:
The part that you have to modify is indicated by the
-- Implement the application here!comment in the source code.
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
begin
-- Implement the application here!
null;
end Main;
Greetings
Goal: create an application that greets a person.
Steps:
Complete the
Greetprocedure.
Requirements:
Given an input string
<name>, procedureGreetmust display the message "Hello <name>!".
For example, if the name is "John", it displays the message "Hello John!".
Remarks:
You can use the concatenation operator (
&).The part that you have to modify is indicated by the
-- Implement the application here!comment in the source code.
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
procedure Greet (Name : String) is
begin
-- Implement the application here!
null;
end Greet;
begin
if Argument_Count < 1 then
Put_Line ("ERROR: missing arguments! Exiting...");
return;
elsif Argument_Count > 1 then
Put_Line ("Ignoring additional arguments...");
end if;
Greet (Argument (1));
end Main;
Positive Or Negative
Goal: create an application that classifies integer numbers.
Steps:
Complete the
Classify_Numberprocedure.
Requirements:
Given an integer number
X, procedureClassify_Numbermust classifyXas positive, negative or zero and display the result:
If
X > 0, it displaysPositive.If
X < 0, it displaysNegative.If
X = 0, it displaysZero.
Remarks:
If you're using the tabbed editor view, you see the following source-code tabs:
classify_number.ads: this tab has the specification of theClassify_Numberprocedure;
classify_number.adb: this tab has the implementation (body) of theClassify_Numberprocedure;
main.adb: this tab has the implementation (body) of theMaintest procedure.You're supposed to edit the body of the
Classify_Numberprocedure.
In the tabbed editor view, you should select the
classify_number.adbtab by clicking on it.In the non-tabbed editor view, you should click on the body of the
Classify_Numberprocedure (which is the second entry).The part that you have to modify is indicated by the
-- Implement the application here!comment in the source code.
procedure Classify_Number (X : Integer);
with Ada.Text_IO; use Ada.Text_IO;
procedure Classify_Number (X : Integer) is
begin
-- Implement the application here!
null;
end Classify_Number;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
with Classify_Number;
procedure Main is
A : Integer;
begin
if Argument_Count < 1 then
Put_Line ("ERROR: missing arguments! Exiting...");
return;
elsif Argument_Count > 1 then
Put_Line ("Ignoring additional arguments...");
end if;
A := Integer'Value (Argument (1));
Classify_Number (A);
end Main;
Numbers
Goal: create an application that displays numbers in a specific order.
Steps:
Complete the
Display_Numbersprocedure.
Requirements:
Given two integer numbers,
Display_Numbersdisplays all numbers in the range starting with the smallest number.
Remarks:
You're supposed to edit the body of the
Display_Numbersprocedure.
In the tabbed editor view, select the
display_numbers.adbtab.In the non-tabbed editor view, click on the body of the
Display_Numbersprocedure.The part that you have to modify is indicated by the
-- Implement the application here!comment in the source code.
procedure Display_Numbers (A, B : Integer);
procedure Display_Numbers (A, B : Integer) is
begin
-- Implement the application here!
null;
end Display_Numbers;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
with Display_Numbers;
procedure Main is
A, B : Integer;
begin
if Argument_Count < 2 then
Put_Line ("ERROR: missing arguments! Exiting...");
return;
elsif Argument_Count > 2 then
Put_Line ("Ignoring additional arguments...");
end if;
A := Integer'Value (Argument (1));
B := Integer'Value (Argument (2));
Display_Numbers (A, B);
end Main;