Question
Assignment: Intro to Ada Assignment: In this assignment, you will write a program to acclimate yourself to the Ada programming language. Write a program that
Assignment: Intro to Ada Assignment: In this assignment, you will write a program to acclimate yourself to the Ada programming language. Write a program that reads up to N integers into an array. It then sorts the data and presents the user a menu, as in the figure. The user makes their choice and the program responds accordingly, looping until the user uses the Q option to exit the program. Select: P)rint Array L)ook for Element C)hange an Element I)nsert New Element F)ind Average Q)uit Your program will implement each option using one or more subprograms. Your main routine (no longer named main!) may contain nothing more than function calls, a loop, and a multiple alternative (Ada equivalent to the C++ switch). You must have a function for each of the following tasks: Print the array, well-formatted, with each value below its index (starting from index 1) Sort the array Search the array o Input an element from the user, search the array for the element, and return whether the search succeeded. Alter an element of the array Determine whether the array is full Insert a new element, if there is room. Determine whether an element is in proper order, relative to its immediate neighbors Determine the exact average of all values in the array
I have some of the code but I need to adjust it can someone help me with Ada
with Text_IO; use Text_IO;
procedure demo1 is
package NUMBER is new INTEGER_IO (Integer); -- pack. for reading int use Number;
type INTList is array (1..10) of Integer;
List : INTList; Index, Value : Integer;
function GetElem(aList: in INTList; Index : in Integer) return Integer is begin return(aList(Index)); end GetElem;
procedure SetElem(aList: in out INTList; Index , Value: in Integer) is begin AList(Index):=Value; end SetElem;
procedure PrintList(alist: in INTList) is begin Text_IO.Put(Item=>"Items in the Array"); Text_IO.New_Line;
-- Example of tick mark for ligh and high for I in List'First .. List'Last loop Put(List(i),0); -- min field width Text_IO.Put(" "); end loop; Text_IO.New_Line; end PrintList;
begin -- code of a main procedure -- Example of a tick mark ' which is this for i in List'Range loop List(i):=i; end loop;
PrintList(List);
Text_IO.Put("You may change values..."); Text_IO.Put("Enter the Index to Alter (0 Quits) >"); Get(Index); -- Loop while not sentinel and Index in legal range while Index /= 0 and Index in List'Range loop Text_IO.Put("Present Value: "); Put(GetElem(List,Index)); Text_IO.New_Line; Text_IO.Put("Enter the Value >"); Get(Value); SetElem(List,Index,Value); PrintList(List); Text_IO.Put("Enter the Index to Alter (0 Quits) >"); Get(Index); end loop; Text_IO.New_Line;
end Demo1;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started