Package Specification Listing-Computer Programming-Assignment Solution, Exercises of Aeronautical Engineering

This is solution to assignment for Aeronautical Engineering and Computer Programming course. It was submitted to Prof. Chitraksh Gavde at Biju Patnaik University of Technology, Rourkela. It includes: Package, Specification, If, Then, Else, Listing, Package, Procedure, Function, Return

Typology: Exercises

2011/2012

Uploaded on 07/20/2012

savitri_122
savitri_122 🇮🇳

4.6

(14)

184 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
C-10 1.
For X = 3
Case 1.
IF x >= 0 THEN
x:= x+1;
ELSIF x >=1 THEN
x := x + 2;
END IF;
In the case above, only the x:= x+1 statement is executed and the result is 4;
Case 2.
IF x >= 0 THEN
x := x + 1;
END IF;
IF x >= 1 THEN
x := x + 2;
END IF;
In this case, both the x:=x+1 and x:= x+2 statements will be executed and the result is 6.
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Package Specification Listing-Computer Programming-Assignment Solution and more Exercises Aeronautical Engineering in PDF only on Docsity!

C-10 1.

For X = 3

Case 1.

IF x >= 0 THEN x:= x+1; ELSIF x >=1 THEN x := x + 2; END IF ;

In the case above, only the x:= x+1 statement is executed and the result is 4;

Case 2.

IF x >= 0 THEN x := x + 1; END IF ; IF x >= 1 THEN x := x + 2; END IF ;

In this case, both the x:=x+1 and x:= x+2 statements will be executed and the result is 6.

C-10 2.

Package Specification Listing

Checking: c:/docume~2/jk/desktop/16070/codeso~1/my_math_package.ads (source file time stamp: 2003- 09-24 03:27:46)


  1. -- Package specified to implement two arithmetic functions
  2. -- Specifier : Jayakanth Srinivasan
  3. -- Date Last Modified : 09/23/

  4. package My_Math_Package is
  5. subtype Menu_Choice is Integer range 1 .. 3;
  6. procedure Menu (
  7. My_Menu_Choice : out Menu_Choice );
  8. function Add (
  9. X : Float;
  10. Y : Float )
  11. return Float;
  12. function Multiply (
  13. X : Integer;
  14. Y : Integer )
  15. return Integer;
  16. end My_Math_Package;

23 lines: No errors

Package Code Listing

Compiling: c:/docume~2/jk/desktop/16070/codeso~1/my_math_package.adb (source file time stamp: 2003- 09-24 03:27:46)

. ----------------------------------------------------------- . -- Package implementation of My_Math package . -- Implementer : Jayakanth Srinivasan . -- Date Last Modified : 09/23/ . ----------------------------------------------------------- . with Ada.Integer_Text_Io; . with Ada.Text_Io; . with Ada.Float_Text_Io; |

C-10 3.

Algorithm

1. Display the menu to the user

2. Get the menu choice from the user

3. If Choice is 1 then

a. Prompt the user for two floating point numbers

b. Clear the screen

c. Compute the sum using the math package

d. Display the answer in the required format.

4. If Choice is 2 then

a. Prompt the user for two integer numbers

b. Clear the screen

c. Compute the product using the math package

d. Display the answer in the required format.

5. If Choice is 3 then

a. Exit the program

Code Listing

Compiling: c:/docume~2/jk/desktop/16070/codeso~1/test_math.adb (source file time stamp: 2003-09- 03:47:18)


  1. -- Program to implement a menu driven program using the
  2. -- the math package
  3. -- Programmer : Jayakanth Srinivasan
  4. -- Date Last Modified : 09/23/

  5. with My_Math_Package;
  6. with Ada.Text_Io;
  7. with Ada.Float_Text_Io;
  8. with Ada.Integer_Text_Io;
  9. with Screen;
  10. procedure Test_Math is
  11. Choice : My_Math_Package.Menu_Choice;
  12. X,
  13. Y : Integer;
  14. Number_X,
  15. Number_Y : Float;
  16. begin
  17. loop
  18. -- obtain the choice from the user
  19. My_Math_Package.Menu(Choice);
  20. -- exit if the user chooses 3
  1. exit when Choice = 3;
  2. case Choice is
  3. when 1 =>
  4. -- obtain two floating point numbers
  5. Ada.Text_Io.Put ("Please Enter the Value of X : ");
  6. Ada.Float_Text_Io.Get(Number_X);
  7. Ada.Text_Io.Skip_Line;
  8. Ada.Text_Io.Put("Please Enter the Value of Y : ");
  9. Ada.Float_Text_Io.Get(Number_Y);
  10. Ada.Text_Io.Skip_Line;
  11. -- clear the screen
  12. Screen.Clearscreen;
  13. -- display the results
  14. Ada.Text_Io.Put("Adding");
  15. Ada.Float_Text_Io.Put(Number_X);
  16. Ada.Text_Io.Put("and");
  17. Ada.Float_Text_Io.Put(Number_Y);
  18. Ada.Text_Io.Put(":");
  19. Ada.Text_Io.New_Line;
  20. Ada.Float_Text_Io.Put(Number_X);
  21. Ada.Text_Io.Put("+");
  22. Ada.Float_Text_Io.Put(Number_Y);
  23. Ada.Text_Io.Put("=");
  24. Ada.Float_Text_Io.Put(My_Math_Package.Add(Number_X, Number_Y));
  25. Ada.Text_Io.New_Line;
  26. when 2=>
  27. -- obtain two integers
  28. Ada.Text_Io.Put ("Please Enter the Value of X : ");
  29. Ada.Integer_Text_Io.Get(X);
  30. Ada.Text_Io.Skip_Line;
  31. Ada.Text_Io.Put("Please Enter the Value of Y : ");
  32. Ada.Integer_Text_Io.Get(Y);
  33. Ada.Text_Io.Skip_Line;
  34. -- clear the screen
  35. Screen.Clearscreen;
  36. -- display the product
  37. Ada.Text_Io.Put("Multiplying");
  38. Ada.Integer_Text_Io.Put(X);
  39. Ada.Text_Io.Put("and");
  40. Ada.Integer_Text_Io.Put(Y);
  41. Ada.Text_Io.Put(":");
  42. Ada.Text_Io.New_Line;
  43. Ada.Integer_Text_Io.Put(X);
  44. Ada.Text_Io.Put("*");
  45. Ada.Integer_Text_Io.Put(Y);
  46. Ada.Text_Io.Put("=");
  47. Ada.Integer_Text_Io.Put(My_Math_Package.Multiply(X, Y));