Thuta Learning
AdvancedProgrammingbeginner

Mini Project

Relax. We'll talk through this in plain words — no textbook voice.

In this mini project, we'll build a student score analyzer. We'll store marks in a vector, calculate the average with a function, and decide the pass/fail status with if/else. Since this project ties together basic syntax, loops, vectors, functions, and conditions all at once, it's a great way to put your C++ foundations to the test.

cpp
#include <iostream>
#include <vector>
using namespace std;

double calculateAverage(vector<int> marks) {
    int total = 0;

    for (int mark : marks) {
        total += mark;
    }

    return static_cast<double>(total) / marks.size();
}

int main() {
    vector<int> marks = {80, 72, 65, 90, 58};
    double average = calculateAverage(marks);

    cout << "Average mark: " << average << endl;

    if (average >= 80) {
        cout << "Result: Excellent";
    } else if (average >= 40) {
        cout << "Result: Pass";
    } else {
        cout << "Result: Fail";
    }

    return 0;
}

marks vector stores the student marks. The calculateAverage() function loops through, totals them up, and returns the average. static_cast<double> is used to avoid integer division. Finally, based on the average, the result is decided with if/else.

You should see
Average mark: 73 Result: Pass

Info

This project uses data storage, loops, functions, conditions, and type casting all in one place. In real apps too, concepts aren't used in isolation — you end up combining them just like this.

Summary

As a next step, you could add letting the user enter marks themselves, finding the highest/lowest mark, or saving the result to a file.

Easy traps

  • Calculating the average when there are no marks in the vector can cause a divide-by-zero error. As a bonus step, you should check marks.empty() before calculating the average.
Mini Project | Thuta Learning