C Homework 1
Compiling Submission/Grading Files
This is our first C assignment and as such we are going to be focusing on wring a single funcon. The funcon will use repeon and selecon to reorder digits within a given number.
We are calling this digit_plow because we are going to use a given digit as a ¡°plow¡± to push digits that are less than the plow to one side of the plow and digits that are greater than the plow to the other.
For example, suppose you are given the number 1148764558 and the plow digit is 3 and you are told to put the larger numbers to the right of the plow, then this would be the resulng number
1148764558 . In this case the plow is not present in the number, so nothing changes. The numbers less than 3 are on the le side, and the numbers greater than 3 are on the right.
Here is another example. Given this number 1404524817 , the plow 4 , and we are told to put the
larger digits on the right of the plow, then the result would be 1021444587 . Since 0, 1, 2, and 3, are
less than 4, those appear in the resulng number to the le side of the plow (in the order they
appeared in the original number). In this case the input number didn¡¯t have 3, so it doesn¡¯t appear in
the result. Because 5, 6, 7, 8, and 9 are greater than 4, they appear in the result number on the
right. Not of all of the larger digits appear in the input number which is why they don¡¯t appear in the
https://canvas.vt.edu/courses/165468/assignments/1714610
Code Help, Add WeChat: cstutorcs
2023/2/9 19:23 Homework 1
result. Noce that the same relave order of the digits is retained in the result from the input number. If the plow shows up more than once, there is a group of plow digits in the middle.
In general, you are given an input number, a plow digit, and where to store the digits that are larger than the plow, if there are any. The result will be a new number with the digits in the same relave order, but moved to one side or the other of the plow.
You can do all of this using basic math operators, e.g. division, mulplicaon, addion, modulus, etc.
You program will be given an input file similar to the one below:
Then the provided main funcon will produce a table like this one
We will be using the main.c as it is provided for you so you should not modify this file. If you have to modify the main in any way it will not work in tesng. Your implementaon must do all of the work in the funcon you are wring.
Implementation
You will be wring a file named that will implement the funcon that is declared in the
digit_plow.c
digit_plow.h file. The first thing your
implement the code to produce the correct result.
file should do is #include “digit_plow.h” and then Your funcon must adhere to the given funcon declaraon. Do not change the funcon interface
or we will not be able to grade it.
It must return the result via a return statement.
Suggestions
digit_plow.c
166680978 5 ONLEFT
1148764558 3 ONRIGHT
1404524817 4 ONRIGHT
762260593 5 ONRIGHT
1667879331 6 ONRIGHT
461853093 6 ONLEFT
372184581 9 ONRIGHT
135623999 7 ONRIGHT
566140699 6 ONRIGHT
1340064517 8 ONLEFT
Number Result Plow
166680978 666897810 5
1148764558 1148764558 3
1404524817 1021444587 4
762260593 220357669 5
1667879331 1331667879 6
461853093 896415303 6
372184581 372184581 9
135623999 135623999 7
566140699 514066699 6
1340064517 1340064517 8
Larger On Which Side
https://canvas.vt.edu/courses/165468/assignments/1714610
程序代写 CS代考 加微信: cstutorcs
2023/2/9 19:23 Homework 1
These are some suggesons on how to approach solving this problem. You are free to make up your own mind about how you want to approach this, but it may make it harder.
Start on the right side of the number, that is in the one¡¯s place. Do not try to figure out how many digits are in the number. Starng on the le is possible but makes this much harder.
Figure out how to get a single digit from the right side of the number and how to compute a new number that is the old number with the right most digit removed. For example, if the input number is 123, how can you get 3? And how can you get a new number 12?
Think about how you can group the sets of digits, the numbers less than the plow, numbers equal to the plow, and greater than the plow. Once you have those groups, how can you recombine them into the answer?
Our soluon including many braces on their own lines and some blank lines is 50 lines long. So if you are wring 100s of lines of code, you are probably approaching the program in the wrong way.
I did not write any other funcons. If you think you need to write other funcons, you may be approaching the problem in the wrong way.
Restrictions
1. You may not work with anyone. This is an individual assignment.
2. Like all our assignments, AI may not be used to generate a soluon.
3. You may not convert the number or digits to strings or characters.
4. You may not use arrays, pointers, or structs.
5. No dynamic allocaon. It is unnecessary.
6. You may not use the library, nor are we going to be linking to that library. 7. You must use the and digit_plow.h as provided. Do not modify them.
8. You must comment your funcon as to its purpose. Also any ¡°tricky¡± code.
Use the provided input and output files to test your code. Use the tool diff or the file difference checker in VS Code to make sure your results match the expected output.
Assuming you are using the name digit_plow.c for your file, this is the command you should use to compile your code. This is also essenally the command we will be using for grading
Then you can run your program, digit_plow , like this
./digit_plow input-2.txt myoutput-2.txt
You can diff the results like this
gcc -Wall -Wextra -std=c11 -g -o digit_plow digit_plow.c main.c
https://canvas.vt.edu/courses/165468/assignments/1714610
2023/2/9 19:23 Homework 1
If this doesn¡¯t show any differences then you are good with that input file.
If it does show differences try this command to help see where the problems are
The -y opon will put the output side-by-side with a | to denote where the issues are. Submission/Grading
When you have tested, you will turn in your digit_plow.c to Canvas. It will be graded and a file with feedback will be returned to you in Canvas. If you have quesons about the feedback, please ask.
main.c (hps:/canvas.vt.edu/courses/165468/files/26870620?wrap=1) (hps:/canvas.vt.edu/courses/165468/files/26870620/download?download_frd=1) digit_plow.h (hps:/canvas.vt.edu/courses/165468/files/26874202?wrap=1) (hps:/canvas.vt.edu/courses/165468/files/26874202/download?download_frd=1)
input.txt (hps:/canvas.vt.edu/courses/165468/files/26870613?wrap=1) (hps:/canvas.vt.edu/courses/165468/files/26870613/download?download_frd=1) – output.txt (hps:/canvas.vt.edu/courses/165468/files/26874204?wrap=1) (hps:/canvas.vt.edu/courses/165468/files/26874204/download?download_frd=1)
input-2.txt (hps:/canvas.vt.edu/courses/165468/files/26870614?wrap=1) (hps:/canvas.vt.edu/courses/165468/files/26870614/download?download_frd=1) – output-2.txt (hps:/canvas.vt.edu/courses/165468/files/26870625?wrap=1) (hps:/canvas.vt.edu/courses/165468/files/26870625/download?download_frd=1)
input-3.txt (hps:/canvas.vt.edu/courses/165468/files/26870617?wrap=1) (hps:/canvas.vt.edu/courses/165468/files/26870617/download?download_frd=1) – output-3.txt (hps:/canvas.vt.edu/courses/165468/files/26870626?wrap=1) (hps:/canvas.vt.edu/courses/165468/files/26870626/download?download_frd=1)
Ñ¡ÔñÌá½»ÀàÐÍ
diff -w output-2.txt myoutput-2.txt
diff -wy output-2.txt myoutput-2.txt
CanvasÎļþ
https://canvas.vt.edu/courses/165468/assignments/1714610
Computer Science Tutoring
2023/2/9 19:23 »ò Homework 1
Ñ¡ÔñÒªÉÏ´«µÄÎļþ
ÔÊÐíµÄÎļþ:C
https://canvas.vt.edu/courses/165468/assignments/1714610