Answer to Question #324100 in C++ for king

Question #324100

. There are 15 students in the class. Students had their mid term result in INT105 and teacher from CSE domain wants to find the average marks of the class for course code INT105 and display it. Write a program using C++ programming language that consists of an class having name Student containing one integer array data member which stores the total marks of 15 students and float data member that calculate the stores average marks to 10 students. Use constructor to initialize data members and member functions to calculate and display average marks.


1
Expert's answer
2022-04-05T13:18:05-0400
#include <iostream>
using namespace std;


class Student {
    int marks[15];
    float average;
public:
    Student(int arr[]);
    void calcAverage();
    void displayAverage();
};


Student::Student(int arr[]) {
    for (int i=0; i<15; i++) {
        marks[i] = arr[i];
    }
}


void Student::calcAverage() {
    int sum = 0;
    for (int i=0; i<10; i++) {
        sum += marks[i];
    }
    average = sum / 10.0;
}


void Student::displayAverage() {
    cout << "Average marks is " << average << endl;
}


int main() {
    int arr[15] = {70, 80, 90, 98, 89, 95, 76, 88, 94, 67};
    Student students(arr);


    students.calcAverage();
    students.displayAverage();


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS