#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

class Student {
private:
    std::string name;
    int rollNumber;
    std::vector<int> marks;

public:
    Student() : rollNumber(0) {}

    void setData(std::string studentName, int studentRollNumber, const std::vector<int>& studentMarks) {
        name = studentName;
        rollNumber = studentRollNumber;
        marks = studentMarks;
    }

    double calculateAverageMarks() {
        if (marks.empty()) {
            std::cout << "No marks available for " << name << " (Roll Number: " << rollNumber << ").\n";
            return 0.0;
        }

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

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

int main() {
    Student student1;
    std::vector<int> marks1 = {83, 92, 91, 89, 88};
    student1.setData("Virgilio V. Pomperada", 201, marks1);

    Student student2;
    std::vector<int> marks2 = {76, 83, 94, 83, 95};
    student2.setData("Lydia R. Pomperada", 202, marks2);

    std::cout << "\n\tAverage Score Using OOP in C++\n\n";

    std::cout << "\tAverage Marks for " << student1.calculateAverageMarks() << std::fixed << std::setprecision(2) << std::endl;
    std::cout << "\tAverage Marks for " << student2.calculateAverageMarks() << std::fixed << std::setprecision(2) << std::endl;
    std::cout << "\n\tEnd of Program\n";

    return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *