Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/* write a class called student that has 4 member data items; name-studnets name

ID: 3626529 • Letter: #

Question

/* write a class called student that has 4 member data items;
name-studnets name, a string
-average-the students average as a double
scores-an array of 4 ints-the students test scores
scorecount-the number of test scores currently in the array

write a default constructor for initializing an object with default name = "unknown",
and have it set the average,scorecount, and array of scores all to = 0. write member data, get functions for the name,average. write a getscore
function that retrieves one score from the scores array based an index provided as an argfor the function.
write an addscore function that puts a score into the array based on scorecount as the index for the score.
write an operator == member function to compare two student objects, and return true if their averages are equal to each other, otherwise it returns false.
write a friend function to overload the insertion operator << for the ostream that will allow the values of the member data
in the object to display in a cout statement.*/

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

class student
{
friend ostream& operator<<(ostream&, student&);
private:
string name;
double average;
int scores[4];
int scorecount;
public:
student(string = "unknown");
int getscore(int);
string getname();
double getaverage();
void addscore(int);
bool operator== (student&);
};
student::student(string newname)
{
name = _______;
scorecount = 0;
for (int i = 0; i<4; i++)
________[i]=0;
}
_____ student::getaverage()
{
double sum = 0;
for (int i=0; i<________; i++)
sum+= scores[i];
______=______/________;
return average;
}
int student::getscore(int index)
{
return______[_______];
}
_____student::getname()
{
return name;
}
void student::addscore(int score)
{
______ [______} = score
__________++;
}
______ _______operator ==(student& s2)
{
if (_____ == ___.________)
return true;
else
return false;
}
____ operator <<(ostream& out, student& s)
{
__<<" The values for this student are "
<<" Name: "<<s.name<<endl
<< "average: "<<_______<< endl;
for (int i=0 ; i< __________;i++)
______<<"Test "<< i+1<<": "<<_________[i]<<endl;
return _____;
}

Explanation / Answer

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

class student
{
friend ostream& operator<<(ostream&, student&);
private:
string name;
double average;
int scores[4];
int scorecount;
public:
student(string = "unknown");
int getscore(int);
string getname();
double getaverage();
void addscore(int);
bool operator== (student&);
};
student::student(string newname)
{
name = newname;
scorecount = 0;
for (int i = 0; i<4; i++)
scores[i]=0;
}
double student::getaverage()
{
double sum = 0;
for (int i=0; i<scorecount i++)
sum+= scores[i];

average=sum /scorecount;
return average;
}
int student::getscore(int index)
{
return scores[index];
}
string student::getname()
{
return name;
}
void student::addscore(int score)
{
scores [scorecount] = score
scorecount_++;
}
bool::student operator ==(student& s2)
{
if (this == s2)
return true;
else
return false;
}
friend ostream& operator <<(ostream& out, student& s)
{
out<<" The values for this student are "
<<" Name: "<<s.name<<endl
<< "average: "<<s.getaverage()<< endl;
for (int i=0 ; i< scorecount;i++)
out <<"Test "<< i+1<<": "<<scores[i]<<endl;
return out;
}