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

Sensor File Processor

Week #10 Mini Project: Energy Usage Report 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: File streams, loops, and parsing.

Objectives: Read reproducible fixtures; report file failures; write a summary artifact.

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

Read reproducible fixtures; report file failures; write a summary artifact.

InputExpected output
2 4 6
Mean: 4

Each row is an executable acceptance test. Input comes from a file; the program writes a report to the second command-line path.

2. Create the repository and project folders

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

git clone https://github.com/YOUR-USERNAME/week10-class-project.git
cd week10-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 <fstream>
int main(int argc,char** argv){if(argc!=3){std::cout<<"Usage: app input output\n";return 1;}std::ifstream in(argv[1]);if(!in){std::cout<<"Cannot open input\n";return 1;}double x,sum=0;int n=0;while(in>>x){sum+=x;++n;}if(!in.eof()||n==0){std::cout<<"Invalid data\n";return 1;}std::ofstream out(argv[2]);if(!out){std::cout<<"Cannot open output\n";return 1;}out<<"Mean: "<<sum/n<<"\n";out.close();if(!out){std::cout<<"Write failed\n";return 1;}std::cout<<"Report saved\n";}
EOF

4. Create test fixtures

cat > tests/input1.txt <<'EOF'
2 4 6
EOF
cat > tests/expected1.txt <<'EOF'
Mean: 4
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
if ./build/app tests/missing.txt build/missing-report.txt; then
  echo "FAIL: missing input accepted"; exit 1
fi
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/week10-class-project.git week10-verify
cd week10-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.