WAP to find sum of all five marks of student using array inside a class.
#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;
}
Comments
Leave a comment