Question: In either C, CPP, or Java In this assignment youll write a program that calculates the checksum for the text in a file. Your program
In either C, CPP, or Java
In this assignment youll write a program that calculates the checksum for the text in a file. Your program will take two command line parameters. The first parameter will be the name of the input file for calculating the checksum. The second parameter will be for the size of the checksum (8, 16, or 32 bits). The program must generate output to the console (terminal) screen as specified below.
1.1 Command line parameters
Your program must compile and run from the command line.
Input the required file name and the checksum size as command line parameters. Yourprogram may NOT prompt the user to enter the file names. The first parameter must be the name of the file used for calculating the checksum, as described below. The second parameter must be the size, in bits, of the checksum. The sample run command near the end of this document contains an example of how the parameters will be entered.
Your program should open the input text files, echo the processed input to the screen,make the necessary calculations, and then output the checksum to the console (terminal) screen in the format described below.
Note
All of the test data files contain a termination character LF represented as a hexadecimal 0A. This character is included in all the checksum calculations.
1.2 Checksum size
The checksum size is a single integer, passed as the second command line argument. The valid values are the size of the checksum, which can be either 8, 16, or 32 bits. Therefore, if the second parameter is not one of the valid values, the program should advise the user that the value is incorrect with a message formatted as shown below:
fprintf(stderr, "Valid checksum sizes are 8, 16, or 32 ");
The message should be sent to STDERR[1].
Format of the input file
The input file specified as the first command line argument, will consist of the valid 8 bit ASCII characters normally associated with the average text file. This includes punctuation, numbers, special characters, and whitespace.
Output Format
The program must output the following to the console (terminal) screen, also known as STDOUT: 1. Echo the text from the input file.
The echoed input text should be in rows of exactly 80 characters per row, except for the last row, which may possibly have fewer. These characters should correspond to the input text.
Print the checksum.
Remember to pad with X if the input data does not align with checksum size for the checksum calculation. For example, if calculating a 16 bit checksum, it could be necessary to add an additional X to arrive at an input file size of an even 16 bit size input. Likewise for 32 bits. However, note that it may be necessary to pad with 1, 2, or 3 X characters for an even 32 bit size input.
The checksum line should be formatted as follows[2] :
printf("%2d bit checksum is %8lx for all %4d chars ", checkSumSize, checksum, characterCnt);
Submission instructions
You must submit this assignment in Webcourses as a source file upload. Note that all submissions will be via Webcourses. The submitted programs will be tested and graded on
Eustis.
Make sure to include a comment at the top of your main source file that contains the following Academic Integrity statement (substitute your name and NID) - I [name] ([NID]) affirm that this program is entirely my own work and that I have neither developed my code with any another person, nor copied any code from any other person, nor permitted my code to be copied or otherwise used by any other person, nor have I copied, modified, or otherwise used programs created by others. I acknowledge that any violation of the above terms will be treated as academic dishonesty.
Program Notes and Hints
One possible breakdown to solve this problem is as follows:
Collect the command line input arguments and print them to the console. Remember to remove or comment out this test code when running the testing scripts.
Read the file and print it out to the console.
Adjust the output to print 80 characters per line.
Calculate the 8 bit checksum. Remember that the checksum is a running total with no overflow.
Resolve the calculations and padding for both 16 and 32 bit checksums.
[1] Printing to STDERR can be accomplished using the followinge code:fprintf(stderr,normal printf format specifications); Java uses System.err.println(...);
[2] Where the variable checkSumSize is the checksum size of 8, 16, or 32, the variable checksum is the calculated checksum. Note that the checksums are masked to print the appropriate sizes such as two hex characters for 8 bits, 4hexcharactersforthe16bitchecksum, and8hexcharactersfor32bitchecksum. ThevariablecharacterCnt is the character count of the input file and includes the terminating charact LF or the hexadecimal value 0A.
Every input file has a single line of text terminated by the hexadecimal character 0A orthe NEWLINE character.
Some input files are less than 80 characters long, others arent.
More testing files are supplied than are used in the hw2Test.sh script.
After uploading the testing shell script (and corresponding files) remember to execute thecommand chmod +x *.sh to grant execution privileges for the script.
The script is executed at the command line by the command bash hw2Test.sh checksum.c where the checksum program filename has the correct extension for your submission. Valid extensions are .c for C, .cpp for C++, and .java for Java.
Contents of files: hw2Test.sh
#!/bin/bash
case $1 in
checksum.c)
rm a.out
gcc checksum.c
EXE="./a.out"
;;
checksum.cpp)
rm a.out
g++ checksum.cpp
EXE="./a.out"
;;
checksum.java)
rm checksum.class
javac checksum.java
EXE="java checksum"
;;
*)
echo "Invalid source file name"
echo "-> should be checksum.c, checksum.cpp, or checksum.java"
exit 1
esac
echo "Case #1 - in10A.txt - 8 bit checksum"
eval $EXE in10A.txt 8 >s10A-Output8.txt
diff s10A-Output8.txt s10A-Base8.txt
echo "Case #1 - in10A.txt - 16 bit checksum"
eval $EXE in10A.txt 16 >s10A-Output16.txt
diff s10A-Output16.txt s10A-Base16.txt
echo "Case #1 - in10A.txt - 32 bit checksum"
eval $EXE in10A.txt 32 >s10A-Output32.txt
diff s10A-Output32.txt s10A-Base32.txt
echo "Case #2 - in17A.txt - 8 bit checksum"
eval $EXE in17A.txt 8 >s17A-Output8.txt
diff s17A-Output8.txt s17A-Base8.txt
echo "Case #2 - in17A.txt - 16 bit checksum"
eval $EXE in17A.txt 16 >s17A-Output16.txt
diff s17A-Output16.txt s17A-Base16.txt
echo "Case #2 - in17A.txt - 32 bit checksum"
eval $EXE in17A.txt 32 >s17A-Output32.txt
diff s17A-Output32.txt s17A-Base32.txt
echo "Case #3 - in18A.txt - 8 bit checksum"
eval $EXE in18A.txt 8 >s18A-Output8.txt
diff s18A-Output8.txt s18A-Base8.txt
echo "Case #3 - in18A.txt - 16 bit checksum"
eval $EXE in18A.txt 16 >s18A-Output16.txt
diff s18A-Output16.txt s18A-Base16.txt
echo "Case #3 - in18A.txt - 32 bit checksum"
eval $EXE in18A.txt 32 >s18A-Output32.txt
diff s18A-Output32.txt s18A-Base32.txt
echo "Case #4 - inRF2.txt - 8 bit checksum"
eval $EXE inRF2.txt 8 >sRF2-Output8.txt
diff sRF2-Output8.txt sRF2-Base8.txt
echo "Case #4 - inRF2.txt - 16 bit checksum"
eval $EXE inRF2.txt 16 >sRF2-Output16.txt
diff sRF2-Output16.txt sRF2-Base16.txt
echo "Case #4 - inRF2.txt - 32 bit checksum"
eval $EXE inRF2.txt 32 >sRF2-Output32.txt
diff sRF2-Output32.txt sRF2-Base32.txt
echo "Case #5 - inWC2.txt - 8 bit checksum"
eval $EXE inWC2.txt 8 >sWC2-Output8.txt
diff sWC2-Output8.txt sWC2-Base8.txt
echo "Case #5 - inWC2.txt - 16 bit checksum"
eval $EXE inWC2.txt 16 >sWC2-Output16.txt
diff sWC2-Output16.txt sWC2-Base16.txt
echo "Case #5 - inWC2.txt - 32 bit checksum"
eval $EXE inWC2.txt 32 >sWC2-Output32.txt
diff sWC2-Output32.txt sWC2-Base32.txt
Contents of : inWC2.txt
A love for tradition has never weakened a nation, indeed it has strengthened nations in their hour of peril. Sir Winston Churchill
Contents of: sWC2-Base8.txt
A love for tradition has never weakened a nation, indeed it has strengthened nations in their hour of peril. Sir Winston Churchill
8 bit checksum is e3 for all 134 chars
Contents of: sWC2-Base16.txt
A love for tradition has never weakened a nation, indeed it has strengthened nations in their hour of peril. Sir Winston Churchill
16 bit checksum is 5d9d for all 134 chars
Contents of: sWC2-Base32.txt
A love for tradition has never weakened a nation, indeed it has strengthened nations in their hour of peril. Sir Winston Churchill XX 32 bit checksum is ef00c701 for all 136 chars
Contents of: sWC2-Output8.txt
A love for tradition has never weakened a nation, indeed it has strengthened nations in their hour of peril. Sir Winston Churchill 8 bit checksum is e3 for all 134 chars
Contents of: sWC2-Output16.txt
A love for tradition has never weakened a nation, indeed it has strengthened nations in their hour of peril. Sir Winston Churchill 16 bit checksum is 5d9d for all 134 chars
Contents of: sWC2-Output32.txt
A love for tradition has never weakened a nation, indeed it has strengthened nations in their hour of peril. Sir Winston Churchill XX 32 bit checksum is ef00c701 for all 136 chars
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
