Final Project and Next Steps

A small project: gradebook

This program uses many things from the course: a class, a vector of structs, a map, functions, loops, sort with a lambda and formatted output:

#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

struct Result {
    string student;
    string subject;
    int mark;
};

class Gradebook {
    vector<Result> results;
public:
    void add(const string& student, const string& subject, int mark) {
        results.push_back({student, subject, mark});
    }

    void report() const {
        map<string, vector<int>> byStudent;
        for (const Result& r : results) {
            byStudent[r.student].push_back(r.mark);
        }
        vector<pair<string, double>> averages;
        for (const auto& [name, marks] : byStudent) {
            double sum = 0;
            for (int m : marks) sum += m;
            averages.push_back({name, sum / marks.size()});
        }
        sort(averages.begin(), averages.end(), [](const auto& a, const auto& b) {
            return a.second > b.second;
        });
        cout << fixed << setprecision(1);
        int place = 1;
        for (const auto& [name, avg] : averages) {
            cout << place++ << ". " << name << " - " << avg << "\n";
        }
    }
};

int main() {
    Gradebook book;
    book.add("Ana", "maths", 91);
    book.add("Ben", "maths", 78);
    book.add("Ana", "science", 85);
    book.add("Cy", "maths", 88);
    book.add("Ben", "science", 95);
    book.add("Cy", "science", 70);
    book.report();
    return 0;
}

Output

1. Ana - 88.0
2. Ben - 86.5
3. Cy - 79.0

What you've learned

  • Output, input, variables, types and maths.
  • Decisions and loops.
  • Functions, references and recursion.
  • Arrays, vectors and strings.
  • Pointers and dynamic memory.
  • Structs, enums, classes, inheritance and polymorphism.
  • Operator overloading, RAII and smart pointers.
  • The STL: maps, sets, stacks, queues, iterators and algorithms.
  • Templates, lambdas, exceptions, files and multi-file programs.

That is the core of C++. Seriously – well done!

Where to go next

  • Practise – the C++ Labs on this site have many more challenges, from easy to hard.
  • Build something – a to-do list that saves to a file, a quiz game, a text adventure, a bank system.
  • Learn the tools – a debugger (gdb or your IDE's), and a build system like CMake for bigger projects.
  • Go further – move semantics, constexpr, threads, and libraries like SFML (games) or Qt (apps).
  • Security – now that you understand memory and pointers, you're ready to learn how buffer overflows and use-after-free bugs are found and fixed.

Remember: Every expert was once a beginner who kept going. Write a little code every day, and you'll be amazed how fast you grow.

HOME LABS COMMUNITY DASHBOARD