Write a class called Student that has two data members a st
Write a class called Student that has two data members - a string variable called name and a double variable called score. It should have a constructor that takes two values and uses them to initialize the data members. It should have get methods for both data members (getName and getScore), but doesn\'t need any set methods.
Write a separate function called stdDev that takes two parameters - an array of pointers to Students and the size of the array - and returns the standard deviation for the student scores (the population standard deviation that uses a denominator of N, not the sample standard deviation, which uses a different denominator).
(Note: I could have had you use an array of Students for this instead of an array of pointers to Students, but I want you to practice pointer syntax.)
The files must be named Student.hpp, Student.cpp and stdDev.cpp.
Solution
Answer:
Student.hpp
#ifndef STUDENT_HPP
#define STUDENT_HPP
//Header files
#include <iostream>
#include<cmath>
using namespace std;
//Implements the class Student
class Student
{
//Access specifier
public:
//constructor for the class
Student(string,double);
//method declaration for getting the name
string getNameS();
//method declaration for getting scores
double getScoreS();
//Private access specifier
private:
//declares the data members
string Stuname;
double Stuscore;
};
#endif
Student.cpp
#include \"Student.hpp\"
#include \"stdDev.cpp\"
//Passing arguments through the constructor
Student::Student(string studentNameS, double studentScoreS)
{
//assigns the name
Stuname = studentNameS;
//assigns the score
Stuscore = studentScoreS;
}
//method to getnames
string Student::getNameS()
{
//returns the name
return Stuname;
}
//method to getscores
double Student::getScoreS()
{
//returns score
return Stuscore;
}
stdDev.cpp
#include \"Student.hpp\"
//method to get stdDev
double stdDev(Student** students,int sizeV)
{
//declares the data members
double sumVal = 0.0, meanS, standardDeviationN = 0.0;
int it;
//loop to calculate scores
for(it = 0; it < sizeV; ++it)
{
//calculates the sum
sumVal += students[it]->getScoreS();
}
//Calculates the means
meanS = sumVal/sizeV;
for(it = 0; it < sizeV; ++it)
//calculating the standard deviation
standardDeviationN += pow(students[it]->getScoreS() - meanS, 2);
//returns the value
return sqrt(standardDeviation N/ sizeV);
}


