CS 2505 Computer Organization I C01: Arithmetic and Logic in C
Arithmetic and Decision-making in C Comparing Digits of an Integer
Given the integer values N = 73427347 and M = 8435346, we see some cases in which the corresponding digits are equal:
73277 8356
The sum of those matching digits is 11.
For this assignment, you will use very basic C techniques to implement a C function to compare the digits of the base-10 representation of two nonnegative integers, detect the ones that match, and compute the sum of those matching digits, as described above. Of course, its possible that no pair of digits matches; in that case, the function will return -1.
/** Determines which digits of left and right are equal, and occur * at the same positions, and computes the sum of those digits.
*
* Pre: left and right are initialized
3 3
4 4
*
*
*
*
*
*
*
*
*
*
*
*/
Returns: sum of matching digits; -1 if none occur
4 4
Examples:
left
314513612
363984358
4824421
8265263
rightresult
42451472310
4469 4
535358-1
47826626424
Restrictions:
does not use global variables
does not read input or write output
int8_t sumMatches(uint32_t left, uint32_t right);
Make useful comments in your implementation of sumMatches(). The same general guidelines for commenting that
you have been taught in your Java courses should provide sufficient guidance.
Getting Started
A tar file is available, containing the testing/grading code that will be used to evaluate your solution:
C01driver.c
sumMatches.h
sumMatches.c
Generate.h
Generate.o
checkAnswer.h
checkAnswer.o
test driver read the comments!
header file declaring the specified function do not modify!
C source file for implementing the specified function
header file declaring the test case generator do not modify! 64-bit object file containing the test case generator
header file declaring the result checking code do not modify! 64-bit object file containing the result checker
Download the tar file C01Files.tar from the course website and save it on your CentOS 7 installation (or on rlogin), in a directory created for this assignment. Unpack the tar file there. You can do this by executing the command:
CentOS> tar xf C01Files.tar
The file sumMatches.c contains a trivial, nonworking implementation of the specified function. You will edit this file
to complete the function.
Version 1.00 This is a purely individual assignment! 1
CS 2505 Computer Organization I C01: Arithmetic and Logic in C
Implementation and Testing
You can compile the given code by executing the command:
CentOS> gcc -o C01driver -std=c11 -Wall C01driver.c sumMatches.c Generator.o checkAnswer.o
You can run the test/grading code by executing the command:
CentOS> ./C01driver
Read the comments in C01driver.c for more information. C01driver will create test data, run your function on that test data, use supplied code to check your answers, and create a file showing the results using the file name from the command line, which might be something like this once youve completed your solution:
Test results
Test case 1 results are correct:
64
964 10
Test case 2 results are correct:
278
378 15
Test case 3 results are correct:
75
9234085 5
.. .
>> 1 Score: 100 / 100
If you try this with the original version of sumMatches.c, the code will compile, but the results will be (mostly) incorrect. Each execution of driver will produce a different set of test data, if you use the rand switch:
CentOS> ./C01driver
If you omit the switch, the test data file created by a previous run will be reused. That allows you to focus on a fixed set of test cases while you are debugging.
You should test your solution thoroughly; the given testing code generates random test data, and there is no guarantee that it will cover all cases unless you run it a sufficient number of times.
Submission and Grading
You should not submit your solution to the Curator until you can correctly pass tests with the given testing/grading code.
Submit your completed version of sumMatches.c, after making changes and testing. Your submission will be compiled, tested and graded by using the supplied code, but that will be done manually after the due date. A TA may also check to see if your solution violates any of the restrictions given in the header comment for the function; if so, your submission will be assigned a score of zero (0), regardless of how many tests it passes.
Version 1.00 This is a purely individual assignment! 2
CS 2505 Computer Organization I C01: Arithmetic and Logic in C
If you make multiple submissions of your solution to the Curator, we will grade your last submission. If your last submission is made after the posted due date, a penalty of 10% per day will be applied.
The Student Guide and other pertinent information, such as the link to the proper submit page, can be found at: http://www.cs.vt.edu/curator/
Pledge
Each of your program submissions must be pledged to conform to the Honor Code requirements for this course. Specifically, you must include the following pledge statement in the submitted file:
//On my honor:
//
// //
//
//
// //
//
//
// //
//
//
//
// //
//
//
//
I have not discussed the C language code in my program with anyone other than my instructor or the teaching assistants assigned to this course.
I have not used C language code obtained from another student, the Internet, or any other unauthorized source, either modified or unmodified.
If any C language code or documentation used in my program
was obtained from an authorized source, such as a text book or course notes, that has been clearly noted with a proper citation in the comments of my program.
I have not designed this program in such a way as to defeat or interfere with the normal operation of the grading code.
We reserve the option of assigning a score of zero to any submission that is undocumented or does not contain this statement.
Change Log
Any changes or corrections to the specification will be documented here.
Version Posted
1.00 Jan 21
1.01 Jan 26
Pg Change
Base document.
1 Corrected return value for sumMatches() when there are no matches.
Version 1.00
This is a purely individual assignment! 3
Reviews
There are no reviews yet.