Function programs,

Function programs, set #2
Here are some programs that will give you practice writing programs with
functions that have array parameters. Each of these should have:
1. AT LEAST an input function and an output function. Additional functions will
be noted if needed;
2. Function headings as shown in Example #12 in “Functions in C, part 1.pdf”;
3. #define statements as shown in “Functions in C, part 2.pdf”;
4. Function prototypes in the correct place in the program;
5. Unless otherwise noted, the only parameter to a function should be the array;
6. No more than 1 return per function; and
7. Descriptive function and variable names.
1. This program will be using an array of 300 ints.
2. The input function should open a file named “300ints.txt” (attached to the assignment) and
read the values from that file into the array. Because we are modifying the array directly,
this function does not return anything.
3. Another function should return the average (double) of the elements in the array.
4. Another function should return the smallest element in the array.
5. The output function should print the results in this form:
Average of the elements = 234.7867
Smallest value = -48
1. This program will deal with an array of 50 “strings” (which means it is a 2D array of chars).
2. The input function should open a file named “50Strings.txt” (attached to the assignment)
and read the values from that file into the array. Because we are modifying the array
directly, this function does not return anything.
Note: These “strings” are not words; they are random combinations of
alphabet letters and digits. Each “string” has 15 characters in it.
Part of the file is shown on the right.
3. A second input function should return the user’s char to search for
4. Another function will return how many times the user’s char is contained in the array.
5. The output function will print how many times the user’s value was in the array.
Functions6
Functions7
Function programs, set #2
1. This program will be using an array of 1000 ints.
2. The input function should open a file named “1000ints.txt” (attached to the assignment)
and read the values from that file into the array. This function does not return anything.
3. Another function will sort the elements in the array from lowest to highest using Bubble
Sort. This function will not return anything.
4. The output function should save the sorted array into a file named “sorted.txt”.
5. Make sure you open the sorted file in Notepad to make sure that it worked.
1. This program uses an array of 300 ints.
2. The input function should open a file named “300ints.txt” and read the values from that file
into the array. This function does not return anything.
3. Another function should find all of the values in the array which are negative and change
them to the value 10000.
4. The output function should save the modified array into a text file named “altered.txt”
5. Make sure you open the altered file in Notepad to make sure that it worked. Count how
many values are 10000. If your program works correctly, there should be 25 of those.
1. This program will be using an array of 60 “strings”.
2. The input function should open a file named “60words.txt” and read the values from that
file into the array. This function does not return anything.
Note: These “strings” are actual words. You can assume the “strings”
contain no more than 20 characters. Part of the file is shown.
3. Another function will sort the elements in the array in alphabetical order using
Bubble Sort. This function will not return anything.
4. The output function will print the sorted array on the screen, one “string” per
line.
To turn these in:
1. Copy and paste all 5 programs into an open MS Word document.
2. Once you have all of the programs in the Word document, submit it in this form:
Lastname, Firstname – HW11.docx
Functions8
Functions9
Functions10