While Project
COP-3223H
Table of Contents
1. Overview
In this project, you will implement the full magic of nine program where, where you iteratively peform the digit summation until the final result is nine, using only the constructs shown in class so far.
2. Repository setup
Log into eustis:
ssh NID@eustis.eecs.ucf.edu
Go to your local repository: Be sure you have already completed the git exercise before attempting this project.
cd ~/cop3223spring26/assignments
Create and enter a directory for the while project:
mkdir while cd while
You only need to mkdir once to create the directory.
Make sure you are in the right directory
pwd
You should see
/home/net/NID/cop3223spring26/assignments/while
3. Create the magic of nines program
Make sure you are in the right directory
pwd
You should see
/home/net/NID/cop3223spring26/assignments/while
Input: a positive, non-zero integer. You can assume this is given or use an assert to guarantee it. Output: the sum of the digits of the input number (multiplied by nine), then as long as that sum is not nine, the sum of all subsequent sums of digits until the result is nine.
Multiply the input number by nine, then sum the digits. Print the sum. If the sum is not nine, then sum the digits again and print again. Keep going until the result is nine.
Use only while/do-while and the C constructs covered in class so far, i.e., inputting and outputting numbers; outputting a string literal; arithmetic operations; declaring, assigning, and using variables; and if statements, if-then-else statements, comparison operators, and Boolean operator; while and do-while loops.
For example, if we give the following input to our program:
Another example:
12
the output will be (excluding the input)
9
Yet another example:
997
the output will be (excluding the input)
27 9
Make sure the program terminates (no infinite while loops) and be aware of operator precedence (use parentheses if in doubt). Additionally, it is possible to overflow the integer due to the multplication. If you would like to avoid this, use assert((num != 0) && (x / num == 9));, but this will not be tested.
The program must be called while.c and must be in the while directory, i.e., the full path should be
~/cop3223spring26/assignments/while/while.c
Compile and run the program whenever you make changes using
cd ~/cop3223spring26/assignments/while/ gcc -o while while.c ./while
Then enter an integer, hit enter, and observe the output.
Be sure there is no other output besides the required output as the grading will be automatic. If you would like to have debugging output, use fprintf(stderr, "...", ...); instead of printf.
4. Submitting your program via git
This assumes you have already setup your repository and that you are still in your hello directory in your repository.
4.1. Add and commit the file
Enter
git add while.c git commit while.c
Write an appropriate commit message. Remember that you will need to save (Ctrl-x Ctrl-s) then quit (Ctrl-x Ctrl-c) the emacs editor that pops up. If you are having trouble, be sure that you have completed the git project first.
Do not commit the backup file while.c~ nor the while program. Use a .gitignore file to exclude those from the repository, so they won't show up when you type git status.
Then to synchronize the changes to the remote git repository on the grading server:
git push
5. Self-check
5.1. Remove the previous self-check
If you have already run the self-check, you can remove it like this
rm -rf ~/tmp/assignments_selfcheck
Double-check the path carefully to avoid deleting the wrong directory.
5.2. Make a fresh clone of your project
git clone gitolite3@eustis3.eecs.ucf.edu:cop3223/$USER/assignments ~/tmp/assignments_selfcheck
You should see something like
Cloning into '/home/net/NID/tmp/assignments_selfcheck'... Welcome to eustis.eecs.ucf.edu. Please use your NID and NID password to log in. See http://t.cs.ucf.edu/help/eustis for additional instructions. remote: Enumerating objects: 16, done. remote: Counting objects: 100% (16/16), done. remote: Compressing objects: 100% (12/12), done. remote: Total 16 (delta 1), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (16/16), done. Resolving deltas: 100% (1/1), done.
If you see
fatal: destination path '/home/net/NID/tmp/assignments_selfcheck already exists and is not an empty directory.
5.3. Enter the fresh clone's directory
cd ~/tmp/assignments_selfcheck/while
5.4. Make sure while runs correctly
cd while gcc -o while while.c ./while
Then run the program as described above.
6. Grading schema
| Criterion | Points |
|---|---|
| while.c exists and compiles | 1 |
| The program runs correctly, prorated by successful test cases | 3 |
| TOTAL | 4 |