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.
#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.
Average mark: 73 Result: PassInfo
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.