ada代写 COMP 3220-002 Fall 2018 Project-4 Ada

COMP 3220-002 Fall 2018 Project-4 Ada Due: 11/25/2018 @ 11:59 PM

For this programming assignment, you will be writing an ada program that will do the following:

Section 1. Initialization (14 points). Create a binary array of 1’s and 0’s that is of length 16.

  1. Your binary array should be a user-defined type called BINARY_ARRAY that can

ONLY store numbers that are of type BINARY_NUMBER. (2 points) b. BINARY_NUMBER is another user-defined type that is a numeric value of either 0 or 1.

(2 points) c. To populate your array, you must generate 16 random 0’s or 1’s using a for loop. (10

points)

Section 2. Functions. (58 points)

  1. Bin_To_Int accepts one BINARY_ARRAY as a parameter and returns the integer

equivalent of that binary value. You must calculate this using a loop. DO NOT use a function built-in to ada to do this. (7 points) b. Int_To_Bin accepts an integer value (you may want to limit the size as we only have 16 “bits” to store it in) and returns a BINARY_ARRAY set to the binary equivalent of that integer value. The binary array should be in the correct order (least significant bit at the far right). (15 points)

  1. Overloaded “+” (18 points)
  2. One version of this should add two BINARY_ARRAYs and return a

BINARY_ARRAY as a result. Don’t worry about overflows. ii. The other version of this should accept a BINARY_ARRAY and an integer and

return a BINARY_ARRAY as a result. d. Overloaded “-” (same as above except subtract the second from the first parameter) (18

points)

Section 3. Procedures. (14 points, each 7 points)

  1. Reverse_Bin_Arr accepts a BINARY_ARRAY and simply reverses it.
  2. Print_Bin_Arr accepts a BINARY_ARRAY and prints it to the console.

Section 4. Main. (14 points, each 2 points) Your “main” should do the following:

  1. Call the Initialization implemented in Section 1. b. Call your Bin_To_Int function from Section2a and display the result on the console c. Call your Int_To_Bin function Section2b and save the return value into a second

BINARY_ARRAY. d. Call your Print_Bin_Arr procedure from Section 3b to display the newly created

binary array. e. Use your overloaded “+” function on arrays 1 and 2, and save the return value into a

third BINARY_ARRAY. Print this as well using your print procedure.

COMP 3220-002 Fall 2018 Project-4 Ada Due: 11/25/2018 @ 11:59 PM

  1. Use your overloaded “-” function on arrays 1 and 2, and save the return value into a

fourth BINARY_ARRAY. Print this as well. g. Finally, reverse the fourth BINARY_ARRAY using your Reverse_Bin_Arr

procedure from Section 3a, and print the result.

Helpful Links:

Download here. You want GNAT ada 2018: http://libre.adacore.com/download/

Old but very useful (careful with the chapter on packages. Newer versions of ada require you to write them in two separate files. The specification belongs in .ads, and the implementation belongs in .adb):

http://perso.telecom-paristech.fr/~pautet/Ada95/intro.htm

Other Useful Links:

http://www.cs.fsu.edu/~baker/ada/examples/

http://www.cristhianny.com/others/ada_tutorial_introduction_code.html

http://www.adapower.com/adapower1/articles/class.html

Deliverables for Project 4:

  • All files should be zipped into a single file for submission on Canvas(FirstName_LastName_P4.zip)
  • Technically, there should be three files: main.adb, radom.adb and radom.ads But if some of you prefer to implement Ramdon inside a main.adb, it is Okay.
  • Students’ code will be tested by the compiler from the download linkage above in Window 10.

No late submission!

Rebuttal period

You will be given a period of 3 days to read and respond to the comments and grades of your homework or project assignment. The TA may use this opportunity to address any concern and question you have. The TA also may ask for additional information from you regarding your project4.

(Important) There should be no collaboration among students. Each student should NOT share any project code with any other students. Collaborations among students in any form will be treated as a serious violation of the University’s academic integrity code.

COMP 3220-002 Fall 2018 Project-4 Ada Due: 11/25/2018 @ 11:59 PM

An output sample

C:\Users\xzl0031\Desktop\obj\main.exe

Printing Random Array My_Array

1000 0110 0010 0111

Printing Integer value of My_Array

34343

Printing Array created from Int_To_Bin function: Int_To_Bin(55);

0000 0000 0011 0111

Printing value of My_Array + Another_Array, first + overload

Int value of My_Array: 34343

Int value of Another_Array: 55

Int value of Array3: 34398

Binary value of Array3: 1000 0110 0101 1110

Printing value of Int_To_Bin(10) + Array3, second + overload

Int value of Array3 after addition: 34408

Current binary value of Array3: 1000 0110 0110 1000

Printing value of My_Array – Another_Array, first – overload

Int value of My_Array: 34343

Int value of Another_Array: 55

COMP 3220-002 Fall 2018 Project-4 Ada Due: 11/25/2018 @ 11:59 PM

Int value of Array 4 (Note, this value will be incorrect if first number is smaller than second): 34288

Binary value of Array 4

1000 0101 1111 0000

Printing value of Int_To_Bin(16384) – My_Array, second – overload

Int value of My_Array: 34343

Int value of Array4 after modification: 47577

Binary value of Array4

1011 1001 1101 1001

Reversing and printing Array4

1001 1011 1001 1101

[2018-11-04 17:10:43] process terminated successfully, elapsed time: 00.47s