UP | HOME

State Project
COP-3223H

Table of Contents

1. Overview

In this project, you will implement a coin counting state machine without using C's built-in arithmetic.

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 ~/cop3223fall26/assignments

Create and enter a directory for the state project:

mkdir state
cd state

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/cop3223fall26/assignments/state

3. Create the state machine

Make sure you are in the right directory

pwd

You should see

/home/net/NID/cop3223fall26/assignments/state

3.1. State machine specification

You will implement a state machine that is similar to hw12. The machine will accept a sequence of characters, 'n', 'd', and 'q', ending with a newline character (when you hit the <Enter> key).

Without using any arithmetic operations in C, track a set of states, representing the machine haven seen combinations of coins that represent zero, five, ten, fifteen, etc., up to forty-five and a state representing any values above forty-five. There will therefore be eleven possible states:

State
zero
five
ten
fifteen
twenty
twentyfive
thirty
thirtyfive
forty
fortyfive
overfortyfive

In your implementation, use no arithmetic operations. Only use while and switch for control flow and assignments to update states (and enum if desired). Use printf to output states and scanf to read individual characters. Feel free to use assert, but no invalid inputs will be tested. See the coding tips below for suggestions on input handling.

The machine will print the list of states the machine reaches, in order, including the initial and final states. For instance, when the input is "qnnd\n", the output will be:

twentyfive
thirty
thirtyfive
fortyfive

An easier way to test the program is to use the echo command to pass the entire string to the program, e.g.,

echo "qnnd" | ./state

3.2. More examples

Running

echo "qqq" | ./state 

outputs

twentyfive
overfortyfive
overfortyfive

Running

echo "qqq" | ./state 

outputs

twentyfive
overfortyfive
overfortyfive

Running

echo "nd" | ./state 

outputs

five
fifteen

3.3. Coding tips

To check for the end of the input, e.g., \n, you can test for it after running scanf and exit before checking.

To use exit, add the following include to the top of your C file.

#include <stdlib.h>

To check for the end of input use the following the code snippet:

while (1) {
  char c;
  scanf("%c", &c);
  if ('\n' == c) {
    exit(0);
  }

  // add your code here

}

3.4. Program name

The program must be called state.c and must be in the state directory, i.e., the full path should be

~/cop3223fall26/assignments/state/state.c

Compile and run the program whenever you make changes using

cd ~/cop3223fall26/assignments/state/
gcc -o state state.c
./state

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 state.c
git commit state.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 state.c~ nor the state 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.

then remove the previous self-check.

5.3. Enter the fresh clone's directory

cd ~/tmp/assignments_selfcheck/state

5.4. Make sure state runs correctly

cd state
gcc -o state state.c
./state

6. Grading feedback

Receiving feedback

If you successfully completed the tools project, you can use the feedback repo to see the grading script logs for your project.

7. Grading schema

Criterion Points
state.c exists and compiles 1
The program runs correctly, prorated by successful test cases 3
TOTAL 4

Author: Paul Gazzillo

Created: 2026-11-03 Tue 14:18

Validate