EECE 2140 · Week 14 · Class Project · Complete worked solution
Modern C++ Sensor Summary
Week #14 Mini Project: Modernize Your Engineering App
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: RAII, STL, algorithms, and modern C++ features taught in class.
Objectives: Replace manual ownership with standard containers; use optional for missing results; prove behavior preservation.
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 gdb1. Understand the acceptance criteria
Replace manual ownership with standard containers; use optional for missing results; prove behavior preservation.
| Input | Expected output |
|---|---|
| |
| |
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 week14-class-project with a README, then substitute your username:
git clone https://github.com/YOUR-USERNAME/week14-class-project.git
cd week14-class-project
git switch -c feature/implementation
mkdir -p src tests .github/workflows
printf "build/\n" > .gitignore3. 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 <vector>
#include <optional>
#include <numeric>
std::optional<double> mean(const std::vector<double>& v){if(v.empty())return std::nullopt;return std::accumulate(v.begin(),v.end(),0.0)/v.size();}
int main(){int n;if(!(std::cin>>n)||n<0||n>1000){std::cout<<"Invalid count\n";return 0;}std::vector<double> v(n);for(double& x:v)if(!(std::cin>>x)){std::cout<<"Invalid reading\n";return 0;}auto result=mean(v);if(result)std::cout<<"Mean: "<<*result<<"\n";else std::cout<<"No data\n";}
EOF4. Create test fixtures
cat > tests/input1.txt <<'EOF'
3 2 4 6
EOF
cat > tests/expected1.txt <<'EOF'
Mean: 4
EOFcat > tests/input2.txt <<'EOF'
0
EOF
cat > tests/expected2.txt <<'EOF'
No data
EOF5. 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.shThe 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
EOFgit add src tests test.sh .github .gitignore
git commit -m "Implement application with acceptance tests and CI"
git push -u origin feature/implementationOpen 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/week14-class-project.git week14-verify
cd week14-verify
bash test.sh
git tag -a v1.0 -m "Verified class project"
git push origin v1.0Completion: 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.