Answer to Question #255155 in C++ for Jagan

Question #255155
A class defines a blueprint for an object. We use the same syntax to declare objects of a class as we use to declare variables of other basic types. Shivan is a contender for valedictorian of his high school. He wants to know how many students (if any) have scored higher than his in the exams given during this semester. · Create a class named Student with the following specifications: · An instance variable named scores to hold a student's 5 exam scores · Use default constructor that reads integers and saves them to scores · An int calculateTotalScore() function that returns the sum of the student's scores.
1
Expert's answer
2021-10-22T07:39:38-0400
#include<iostream>
using namespace std;
class  Student{
	private:
		int scores[5];
	public:
		Student(){
			cout<<"Enter the student scores:\n";
			for(int i=0; i<5; i++){
				cout<<"Score "<<(i+1)<<":\n";
				cin>>scores[i];
			}
			
		}
		int calculateTotalScore(){
			int sum = 0;
			for(int i=0; i<5; i++){
				sum += scores[i];
			}
			return sum;
		}
};


int main(){
	Student st;
	cout<<"Total score is:  "<<st.calculateTotalScore()<<endl;
}

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