Answer to Question #230069 in C++ for Arup

Question #230069

WAP to find sum of all five marks of student using array inside a class.


1
Expert's answer
2021-08-26T23:46:28-0400
#include <iostream>
using namespace std;
class Student{
    float marks[5];
    public:
    Student(){
        for(int i = 0; i < 5; i++){
            cout<<"Enter marks for subject "<<i + 1<<endl;
            cin>>marks[i];
        }
    }
    float total(){
        int sum = 0;
        for(int i = 0; i < 5; i++){
            sum += marks[i];
        }
        return sum;
    }
};
int main(){
    Student s;
    cout<<s.total();
    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