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

C++ pointer program: Write a class called Student that has two data members - a

ID: 3851137 • Letter: C

Question

C++ pointer program:

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.

Explanation / Answer

Here is the code for Student.hpp:

#include <iostream>
using namespace std;
class Student
{
//a string variable called name
string name;
//a double variable called score.
double score;
public:
   //It should have a constructor that takes two values and uses them to initialize the data members.
   Student(string name, double score);
   //It should have get methods for both data members (getName and getScore)
   string getName();
   double getScore();
};

And the code for Student.cpp:

#include <iostream>
#include "StudentPointers.hpp"
using namespace std;

//It should have a constructor that takes two values and uses them to initialize the data members.
Student::Student(string name, double score)
   {
      this->name = name;
      this->score = score;
   }
//It should have get methods for both data members (getName and getScore)
string Student::getName() {   return name;   }
double Student::getScore() {   return score;   }

And the code for stdDev.cpp is:

#include <cmath>
#include "StudentPointers.cpp"
using namespace std;
//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
double stdDev(Student *students, int size)
{
if(size == 0)
return 0;
double sum = 0;
//Calculates the sum of elements in the array.
for(int i = 0; i < size; i++)
sum += (students+i)->getScore();
//Calculates the mean of the array.
double mean = sum / size;
if(size == 0)
return 0;
sum = 0;
for(int i = 0; i < size; i++)
sum += pow(((students+i)->getScore() - mean), 2);
double std = sum / size;
std = sqrt(std);
return std;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote