Question: Please do this program in Ada programming language. This exercise is designed to help you get acquainted with the Ada compiler and the basic layout

Please do this program in Ada programming language.

This exercise is designed to help you get acquainted with the Ada compiler and the basic layout of Ada programs. You may wish to use the Fibonacci, Quadratic, and Geometry programs as a guide as you construct your programs.

1. Write a program to read an integer N and print out the score for N. Compute the score this way:

Begin with a score of 0.

  • If N is even, add 5 points; otherwise, add 1 point.
  • If N is negative, add 2 points.
  • If N is bigger than 100, add 10 points.

For example, the score for 501 is 11 (1 + 10), and the score for -12 is 7 (5 + 2).

Note: Ada has two remainder-after-division operators, mod and rem. They have slightly different behavior on negative numbers, but either can be used for this problem: N mod 2 and N rem 2 will both be 0 if N is even.

Name your program file number_score.adb.

2. Write a program to read a positive integer N and print out the sum of the first N terms of the alternating harmonic series.

The alternating harmonic series is

1 - 1/2 + 1/3 - 1/4 + 1/5 - ...

For example, if N = 3, then the sum is 1 - 1/2 + 1/3 = 0.83333

Print the result with a precision of 5 places after the decimal, and do not display the result in scientific notation. (You will need to use some formatting arguments in your Put statement.)

If the user enters a non-positive value for N, print an error message instead of attempting to compute the sum of the series.

Name your program file harmonic.adb.

A note on loops:

You may use any type of loop in the program to generate the values of the series. If you wish to use a for loop, the syntax is

 for Counter in Start_Value..Stop_Value loop body end loop; 

For example,

 for I in 1..10 loop Put(I); New_Line; end loop; 

The loop counter variable is not declared elsewhere in the program; its use in the for loop header serves as its declaration.

A note on integer formatting:

If you find that Ada is putting too many spaces in front of the score when you print it, you can supply a Width parameter to Put. For example, Put(5); will print

 5 

(i.e., 5 preceded by ten spaces), but Put(5, Width => 1); will print

5 

A note on numeric data types and type conversion:

You will probably see a type conflict between the data type of the loop counter and the data types in the division operation. A for loop can only use discrete types for indexing; this includes integers, characters, enumerated types, and a few other types, but not floats. On the other hand, the division operation will have to have float operands, not integer operands, in order to require real division (rather than integer division).

If you need to convert an integer to a float, use the Float function. For example, if I is an integer, then Float(I) returns the float that corresponds to I. Similarly, if you need to convert a float to an integer, use the Integer function. If X is a float, then Integer(X) returns the integer that results from rounding X to the nearest integer.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!