Comp-Based Modeling & Methods

1) Write a program with two functions. The main function will just define and initialize
the variables and call the user functions. All the work will be done by the user functions.
The size of the array is 100.

Function #1: this function will be passed a float array and its size and return
nothing. The function will fill the array with random floats between 0 and 1 (exclusive).
Use the formula below:

x = (float) rand() / (float) (RAND_MAX + 1);
Function #2: Print the array to the screen. Print the numbers using %8.4f format no blank
spaces between.
2) Write an additional function to add to the above program (Program #1). This function
will do a Histogram operation on the data in the array and print the results. The function
will be passed the float array and its size and return nothing. Prompt the user to enter in
the number of cells for the Histogram, this should be < the size of the array, do the error
check. Then count the number of array data values in that histogram range and print the
results to the screen, repeat until entire histogram range is covered. Range of data values
is 0.0 to 1.0 exclusive.
Example: user types in 5, histogram cell width is 1.0/5 = 0.2. First cell goes from 0.0 to
<0.2, next cell goes 0.2 to <0.4, .., last cell goes 0.8 to <1.0, function counts all the data
values in the range of each cell.
3) Write a program with two functions. The main function will just define and initialize
the variables and call the user functions. All the work will be done by the user functions.
In the main function, define an integer array of 55 elements and initialize the array to
zero.

READ ALSO :   INVENTORY ERRORS

Function #1: this function will be passed the integer array and its size and return nothing.
This function will fill the array with random numbers between 1 and 10. Print the array
to the screen with 5 blank spaces between numbers.

Function #2: this function will be passed the integer array and its size and return nothing.
This function will prompt the user to enter in a number to search for between 1 and 10,
error check to make sure the number is in range. Search the array and print the element
number for each match to the screen.

4) Write a program with three functions. The main function will just define and initialize
the variables and call the user functions. All the work will be done by the user functions.
In the main function, define an integer array of 20 elements and initialize the array to
zero.

Function #1: this function will be passed the integer array and its size and return nothing.
This function will fill the array with random numbers between 1 and 10.

Function #2: this function will be passed the integer array and its size and return nothing.
This function will print the array elements to the screen with one tab space between (\t).
Function #3: this function will be passed the integer array and its size and return nothing.
This function will do a bubble sort, with the largest data value in element zero.

print the sorted array – use function 2 again.

5) Write a program with two functions. The main function will just define and initialize
the variables and call the user functions. All the work will be done by the user functions.
In the main function, define a char array of 256 elements and initialize the array to blanks.
Function#1: This function will be passed the char array and its size and return nothing. Fill
each element with its element number – i.e. mycharArray[i] = i. You are storing an integer
number in a char, this works for char variables.

READ ALSO :   compound annual growth rate of the dividends

Function#2: This function will be passed the char array and its size and return nothing.
Print out each element from the array with 2 blank spaces between characters. Shows
what symbol you get from the ASCII character set.

6) Write a binary search program with 4 functions. Create an integer array of 101
elements (0 to 100). The main function will use a sentinel loop; enter in a data value
between 0 and 100 to search for or a negative number to quit, error check the entered
number.

Function #1: Fill the array. Set each array element value to its element number. So array
will be sorted as filled. Pass the function the array and its size and return nothing.
Function #2: Print out the array values with 2 blank spaces between numbers. Pass the
function the array and its size and return nothing.

Function #3: Do a binary search. Pass the function the array, its size and the value to
search for – return the element number (integer) where the match was found. For each
iteration of the binary search, print out the low, middle and high element numbers.
Function #4: Pass the value you searched for and the returned element number where
the match was found, return nothing. This function prints out the value you searched for
and the element it was found in.