CPSC 120 LAB 9 Back to Lab index page

Lab must be completed and reviewed by Peer Instructor Seth Peery no later than Fri, Oct 26 during lab class.

You are to write a nicely documented Ada program that prompts the user to input three integers. Your program will first display the three integers in order. If all three integers are odd, your program will tell the user so. If all three integers are even, your program will state that. Your program will output the sum of the integers. Your program will figure out if the sum is a prime number, and if so, will tell the user. Your program will output the average of the three numbers -- displaying one decimal point.

You should write a Boolean function IsPrime to figure out if a number is a prime number or not. (Remember that a number is prime if it is divisible only by itself and 1). You should have a procedure Order which will put your three integers in order. You should also write a procedure getinput which gets the 3 integers and handles exceptions.

Sample

Program outputs: Enter 3 integers, S to stop>
  Intger 1>
User inputs: 7
Program outputs: Intger 2>
User inputs: 5
Program outputs: Integer 3>
User inputs: 5
Program outputs:

You entered: 5 5 7
All three integers are odd.
The sum of the integers is: 17.

17 is a prime number.
The average of the three numbers is 6.5.

----------------------------------------

Program outputs: Enter 3 integers, S to stop>

A pseudocode outline of the program appears below.

With ada.text_io;
Procedure lab9 is

Procedure G etinput (i1, i2, i3: out integer; stop in out Boolean) is

begin
     This procedure gets 3 integers and returns them in order. Stop becomes true when S is entered.
end order;

Procedure Order (i1, i2, i3: in out integer) is

begin
     This procedure gets 3 integers and returns them in order.
end order;

Function IsPrime(num :Integer) return Boolean is

Begin -- IsPrime
     This function determines whether it's parameter is prime, if so, returns True. If not, False.
end IsPrime;

Begin -- main program lab 9
stop := false;

while not stop loop
     getinput(num1,num2,num3, stop);
     order(num1,num2,num3);
     (you figure out the rest)
end loop;

end lab9;