Summer 2023 Midterm
Page 1
Midterm Exam Summer 2023
ESE/EEO 124
Instructor: Jenny Chen
1.
(20pts) Write a C program that takes two 1D arrays of decimal values as input and creates a third
1D array. The third array should contain the greater of the corresponding values from the first and
second arrays. If the arrays have different lengths, only consider values up to the length of the
shortest array. The resulting array should have the same length as the shortest input array.
For example, given the following input arrays:
1st array: 2.0 5.0 3.0 4.0
2nd array: 3.0 5.0 7.0 8.0 10.0
The program should generate the following output array:
3rd array: 3.0 5.0 7.0 8.0
Note that the last value in the second array (10.0) is ignored since it exceeds the length of the first
array.
2.
(40pts) Design a C program that performs the following tasks:
Read words from an input file named "input_sentence.txt".
Read names from an input file named "names.txt".
Create a new file named "output_sentence.txt".
Write the sentence from “input_sentence.txt” into “output_sentence.txt”, but with the first letter
of each word appearing in “names.txt” capitalized.
For example, given the following input files:
input_sentence.txt:
Hi, james and frank are taking an exam.
names.txt:
james, frank, chris, anne
The program should generate the following output file:
output_sentence.txt:
Hi, James and Frank are taking an exam.
3.
(40pts) Write a C program to read decimal values from an input file – “Input_file.txt” contains at
most 15 values. The output file must sort the value in 1D array. Then it should display sorted
results and display the average of all values in the array.
Input file example:
1D array: 7.0 5.0 2.0 3.0 4.0
Output file:
1D sorted result: 2.0 3.0 4.0 5.0 7.0
The average = 21/5 = 4.5