Copyright  © – Sudharsan Iyengar

 

CS – 234                                 Lab 9                          

 

A:        Arrays and Loops                                           3/25/25

 

Write an application that uses a random number generator to generate and store 50 random numbers in the range 1 – 500 in an array of integers.

 

Process the array to find

a)     The smallest in the array

b)     The largest in the array

c)     The average (mean) of the values in the array

d)     The standard deviation (SD) of the values in the array.

 

The SD of a set of numbers is the square root of the sum of the squares of the (value-mean) divided by the size of the population.

 

 

B:        Objects, Files, Arrays, and Loops

 

Write an application that uses a scanner and reads from a file fractions.dat

 

a)               The first line of the file has an integer – representing the number of lines of data to follow.

b)               Each line after that contains – information to be stored in a fraction object viz. Fraction name (String), numerator (int) and denominator (int).

c)               Create an array of objects – using the fraction class.

 

Your application should allow users to do the following any number of times:

 

1.               Output a menu for the user to select from operations – display, addition, subtraction, multiplication, division, and exit

2.               Receive the selection of operations from the user.

3.               Output a menu for the user to select from the list of fractions.

4.               Receive the selection(s) of fractions from the user

5.               Perform the chosen operation and output the result of the operation.

6.               Perform this until the user selects the exit option.