HOMEWORK PROBLEM 1 extra credit PURPOSE: Get programming experience by writing Ada code for a simple program. END RESULT: A program that does not do much, but uses a lot of basic Ada language features. PROBLEM: Implement a Ada program that will compile with no errors or warnings in a gnat Ada compiler. (OK to use other compilers if they are available.) A starter program is attached. First: compile, link, and execute this program to be sure you have the basic capability to write a program. Then add: 1) Define A, B, and C to have values 1.0, 2.5, and 7.3 respectively. Type float or long_float is acceptable. Write the following pseudo code in Ada. if A > 0.5 then if A < B and B < C then B <- ( A + C ) / 2.0 print B else B <- B + 1 print ( A + B ) fi else A <- A + 1 print A fi 2) Declare pwrs, to be an array of 10 integers use a loop statement to put the numbers 1, 2, 4, 8, 16, .. in the array using subscripting. e.g. pwrs <- 1, pwrs <- 2 * pwrs 1 i i-1 use another loop statement to print the array one value per line. 3) Given the string dat : string = "cabdc"; and val : integer = 0; Now put a case statement in a loop statement through dat with the following behavior: on letter 'a' add one to val on letter 'b' add three to val on letter 'd' add five to val on all other letters, add two to val after the loop, print val as a decimal number 4) Given Q, compute the following expression using 16 bit word logical operations Q <- not ( ( 5 and 9 ) or ( 48 xor 96) ) print Q as a hexadecimal number TURN IN: A listing of your source code and the output. This may be on paper or may be mailed to ECLUS::SQUIRE or squire@eclus OBSERVE: It is actually fastest to add one feature at a time, edit, compile, link, run, and see that everything works up to this point. Putting in a lot of code and getting a lot of error messages is very frustrating. METHOD: You may have all code in one file. This tends to make it easier during development. Later in the course you will be building larger programs where one file may not be appropriate. READING: The compact summary of Ada has most of what you need, but may be too terse for your experience level. Looking through the book may help -- HW1ex.adb with Text_IO; use Text_IO; procedure HW1ex is -- NOTE! all declarations are placed before the 'begin' that -- indicates executable statements follow. Later you can use 'declare' -- 1) add more here, finish after begin A : float := 1.0; -- 2) goes here, if declarations needed -- 3) goes here, finish dat : string := "cbadc"; val : integer := 0; -- 4) goes here type bits_16 is mod 65536; Q : bits_16 := 0; begin Put_Line("HW1ex is running"); -- 1) finish here Put_Line("A= " & float'image(A)); -- 2) finish here, remember dat(i) is i th character -- 3) finish here Put_Line("val= " & integer'image(val)); -- 4) goes here, finish Put_Line("Q= " & bits_16'image(Q)); -- not hex Put_Line("finished HW1ex"); end HW1ex;