In C programming
Make sure you run your code in submit mode inzyBooks--you do not need to submit code to Blackboard!
Write a program that reads two input files and uses them togenerate an output file. While you can write the entire program ina single file, if you do write your own functions for this program,put their prototypes and definitions in thefiles final_prog4functions.h and final_prog4functions.c,respectively. Note that, similarly to your programming assignments,some percentage of your grade will depend on proper programmingstyle.
The program should begin by prompting for and reading the namesof three files:
A binary input file (for example, testfile_50vals.bin) thatcontains a set of integer values
A text input file (for example, commands1.txt)
A text output file (for example, commands1_out.txt)
If any of the files cannot be opened, your program should printan error message and repeat the prompt for that file until the userenters the name of a file the program can actually open.
The program should then use the contents of the text input fileto determine how to handle the integers in the binary input fileand fill the output file. Each line in the text input file containsone of the following commands, where N is an integervalue that is no greater than 20:
copy N: Read N values from the binary input file andprint them to the text output file on a single line. The lineshould start with the text Copied N values: with theactual value of N printed.
reverse N: Read N values from the binary input fileand print them to the text output file on a single line, in theopposite order they were read. The line should start with thetext Reversed N values: with the actual valueof N printed.
sort N: Read N values from the binary input file andprint them to the text output file on a single line, sorted fromlowest value to highest value. The line should start with thetext Sorted N values: with the actual valueof N printed. It's up to you to find and implement analgorithm to sort these values--we didn't cover that topic inclass.
median N: Read N values from the binary input file,calculate their median, and print it to the text output file. Theline should start with the text Median of N values: withthe actual value of N printed. If it's possible for themedian to have a fractional part, print the median with a precisionof 1. If you don't know how to calculate a median, a quick websearch will help you out.
exit: End the program (after closing the three open files).
The text below shows a sample of what your output to the screenshould look like, both with and without errors. User input isunderlined. The only error you need to worry about is a file thatdoesn't open--assume there are no invalid commands in the textfile:
Enter binary input file name: badfilename.exeInvalid file name badfilename.exeEnter binary input file name: testfile.binInvalid file name testfile.binEnter binary input file name: testfile_50vals.binEnter text input file name: commands.txtInvalid file name commands.txtEnter text input file name: commands1.txtEnter output file name: commands1_out.txt
In addition, I've linked several test filesbelow. testfile_50vals.bin and testfile_200vals.bin are,unsurprisingly, binary input files that contain a total of 50 and200 integer values,respectively. commands1.txt, commands2.txt, commands3.txt,and commands4.txt are text input files as describedabove. commands1.txt and commands3.txt workwith the 50-value binary input file; the other two work with the200-value binary input file. The corresponding output files havesimilar names to the text input files with _out after theoriginal name (for example, commands1_out.txt).
Make as 3 separate codes as follows. Let me know if there areany questions.
final_prog4_main.c
final_prog4_functions.c
final_prog4_functions.h
In C programming Make sure you run your code in submit mode in zyBooks--you do not need to submit code to Blackboard! Wr
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am