EECE 2140 · Week 13 · Class Project · Complete worked solution

Resilient Measurement Importer

Week #13 Mini Project: Configuration Validator

Plan, implement, test, document, and release a complete console application. Allow 1–2 hours; the reference capstone can take longer.

Tools, prerequisites, and learning objectives

Tools: Ubuntu terminal (Linux or Windows with WSL), g++ supporting C++17, Git, Bash, a GitHub account, and an optional editor. File projects use supplied text fixtures. Week 3 also uses GDB; Week 8 uses compiler sanitizers.

Prerequisites: Exceptions, parsing, validation, and recovery.

Objectives: Separate parsing errors from valid values; catch specific exceptions; continue safely.

Provisional course alignment: C++ implementation, problem solving, development tools, testing, and technical communication; team projects additionally assess collaboration. Exact official syllabus objective numbers have not been supplied.

g++ --version
git --version
# Install missing tools in Ubuntu:
sudo apt update
sudo apt install build-essential git gdb

1. Understand the acceptance criteria

Separate parsing errors from valid values; catch specific exceptions; continue safely.

InputExpected output
10 bad 101 20
Valid: 2 Invalid: 2
0 100
Valid: 2 Invalid: 0

Each row is an executable acceptance test. Input is read from standard input; output is printed to the terminal.

2. Create the repository and project folders

Create an empty GitHub repository named week13-class-project with a README, then substitute your username:

git clone https://github.com/YOUR-USERNAME/week13-class-project.git
cd week13-class-project
git switch -c feature/implementation
mkdir -p src tests .github/workflows
printf "build/\n" > .gitignore

3. Implement the complete solution

The following source is the worked solution. Read it first, predict the test results, then create the file from your terminal:

cat > src/main.cpp <<'EOF'
#include <iostream>
#include <string>
#include <stdexcept>
int main(){std::string token;int valid=0,bad=0;while(std::cin>>token){try{std::size_t pos=0;int x=std::stoi(token,&pos);if(pos!=token.size()||x<0||x>100)throw std::invalid_argument("range");++valid;}catch(const std::invalid_argument&){++bad;}catch(const std::out_of_range&){++bad;}}std::cout<<"Valid: "<<valid<<" Invalid: "<<bad<<"\n";}
EOF

4. Create test fixtures

cat > tests/input1.txt <<'EOF'
10 bad 101 20
EOF
cat > tests/expected1.txt <<'EOF'
Valid: 2 Invalid: 2
EOF
cat > tests/input2.txt <<'EOF'
0 100
EOF
cat > tests/expected2.txt <<'EOF'
Valid: 2 Invalid: 0
EOF

5. Build and test from the terminal

cat > test.sh <<'EOF'
#!/usr/bin/env bash
set -eu
mkdir -p build
g++ -std=c++17 -Wall -Wextra -pedantic src/main.cpp -o build/app
./build/app < tests/input1.txt > build/actual1.txt
diff -u tests/expected1.txt build/actual1.txt
./build/app < tests/input2.txt > build/actual2.txt
diff -u tests/expected2.txt build/actual2.txt
echo "All acceptance tests passed"
EOF
bash test.sh

The script stops on a compilation error or mismatched output. Successful completion prints “All acceptance tests passed”.

6. Automate with GitHub Actions

cat > .github/workflows/cpp.yml <<'EOF'
name: Build and test
on: [push, pull_request]
permissions:
  contents: read
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Compile and run acceptance tests
        run: bash test.sh
EOF
git add src tests test.sh .github .gitignore
git commit -m "Implement application with acceptance tests and CI"
git push -u origin feature/implementation

Open a pull request in GitHub, inspect its Actions logs, and merge only after checks pass. Intentionally alter one expected-output line on a temporary branch, observe the failure, then restore it. Do not change expectations to hide a defect.

7. Document and verify a release

Write README.md with purpose, input format, build/run/test commands, example output, limitations, and AI assistance. Include a short debugging reflection.

git switch main
git pull --ff-only
# Edit and commit README.md, then push.
cd ..
git clone https://github.com/YOUR-USERNAME/week13-class-project.git week13-verify
cd week13-verify
bash test.sh
git tag -a v1.0 -m "Verified class project"
git push origin v1.0

Completion: a fresh clone passes, the latest CI run is green, and the instructions reproduce your output.

Download and engineering review

Download the complete solution, tests, README, and workflow

Explain the data flow, validation choices, and how each test detects a failure. The downloadable solution is a learning reference, not a substitute for understanding the code.