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

In C++ ! The task is to write Student.cpp to complete the implementation of the

ID: 3792104 • Letter: I

Question

In C++ !

The task is to write Student.cpp to complete the implementation of the Student class, as defined in the provided header file, Student.h, and then to complete a program (called grades) that makes use of the class. The program will read student names and grade information from a data file. The grade information will consist of test, student program, and final exam scores in the following format (the quizzes from the first project are dropped): name   tests   programs  final As with the first assignment, the program will first output the raw data in a well formatted table. The program will then sort the data, by student name, in alphabetical order, and output a table of the sorted data containing the name, average, and letter grade. Lastly, the program will resort the data, this time by average in descending order, and output the sorted data table again. A working executable file called grades is supplied. Use it to guide decisions on what output formatting should look like and to verify computations. Make your program work like this example! Student class: Details of the Student class will be discussed in the classroom, but here are some important observations. First, only the student’s name and raw data scores are actually stored in the class. Methods are defined to set and retrieve the internally stored data. Good objectoriented programming practices dictate that methods should be used to access the data. Second, as mentioned, only the raw data are stored, which means that the average and letter grades are not stored in the class. Instead, two methods are provided to get that information, getAverage() and getGrade(). These methods will use the internally stored data to calculate the average and grade and return the result. (Note that, since the getGrade() method will need the average to compute the grade, the first thing it should do is to call getAverage().) In order to compute the average, the weighting for each of the three grade components will be needed. These will be stored in three private static const floats. They should be defined and used for the computation (do not hardwire percentages – use the static variables). The final average is weighted as follows:               tests: 35%         programs: 40%         final: 25% Overloading: Included in the class are overloads for the greaterthan “>” and lessthan “<” operators. These should be used by the sorting routines in the grades program to sort by name and average. The sorting routines should NOT access the student data directly, but use the overloaded operators. The operators should work as follows: Greater than (operator>):   will compare student’s grade averages Less than (operator<):   will compare student’s names (string compare) External to the class, the input and output stream operators are overloaded. These will behave as follows: Output stream (operator>>):    Will output the student’s raw data in “name tests programs final” format should be used to format the “raw data” output in dumpData() Input Stream (operator<<):     Will read data in “name tests programs final” format   should be used to read data form the input file in readDataFile()

grades .cpp file

#include <iostream>

#include <fstream>

#include <iomanip>

using namespace std;

#include "Student.h"

#define ARRAYSIZE 12

// read the data file, store in arrays

int readDatafile(Student[], int);

// output the formatted "raw data"

void dumpData( ... );

// output the names, average, grade data (formatted)

void dumpSorted( ... );

// sorting routines - use a bubble sort

void sortAscend( ... ); // set this up to sort by name

void sortDescend( ... ); // set this up to sort by average

void swap( ... ); // used by the bubble sort

main() {

Student slist[ARRAYSIZE];

return 0;

}

student.h file

#ifndef STUDENT_H
#define STUDENT_H

#include <string>
using namespace std;

// struct definition for a student object
class Student {
public:

// constructor
Student(string n="", int t=0, int p=0, int f=0);

// modifiers
void setName(string n);
void setTests(int v);
void setProgs(int v);
void setFinal(int v);
  
// inspectors
string getName() const;
int getTests() const;
int getProgs() const;
int getFinal() const;
  
float getAverage() const;
char getGrade() const;

// overloads
// greater than - compares grade "average"
bool operator>(const Student &) const; // greater than
// less than - compares student names
bool operator<(const Student &) const; // less than

private:
string name; // student name
int tests; // student test score
int progs; // student progam score
int final; // student final exam score

static const float testPCT; // fraction of average for tests
static const float progsPCT; // fraction of average for progs
static const float finalPCT; // fraction of average for final
};

// overload of external stream operators
ostream &operator<<(ostream &, const Student &);
istream &operator>>(istream &, Student &);

#endif

file.data

Veronica 78 73 75

Chris 80 79 75

Oscar 90 84 85

Victor 73 54 73

Alicia 96 91 94

Casey 91 84 80

Kyra 75 73 73

James 90 84 91

Aaron 69 61 77

Joey 72 39 55

Alex 78 72 75

Donald 91 93 93

Explanation / Answer

#include <iostream>

#include <fstream>

#include <iomanip>

using namespace std;

#include "Student.h"

#define ARRAYSIZE 12

// read the data file, store in arrays

int readDatafile(Student[], int);

// output the formatted "raw data"

void dumpData( ... );

// output the names, average, grade data (formatted)

void dumpSorted( ... );

// sorting routines - use a bubble sort

void sortAscend( ... ); // set this up to sort by name

void sortDescend( ... ); // set this up to sort by average

void swap( ... ); // used by the bubble sort

main() {

Student slist[ARRAYSIZE];

return 0;

}

student.h file

#ifndef STUDENT_H
#define STUDENT_H

#include <string>
using namespace std;

// struct definition for a student object
class Student {
public:

// constructor
Student(string n="", int t=0, int p=0, int f=0);

// modifiers
void setName(string n);
void setTests(int v);
void setProgs(int v);
void setFinal(int v);
  
// inspectors
string getName() const;
int getTests() const;
int getProgs() const;
int getFinal() const;
  
float getAverage() const;
char getGrade() const;

// overloads
// greater than - compares grade "average"
bool operator>(const Student &) const; // greater than
// less than - compares student names
bool operator<(const Student &) const; // less than

private:
string name; // student name
int tests; // student test score
int progs; // student progam score
int final; // student final exam score

static const float testPCT; // fraction of average for tests
static const float progsPCT; // fraction of average for progs
static const float finalPCT; // fraction of average for final
};

// overload of external stream operators
ostream &operator<<(ostream &, const Student &);
istream &operator>>(istream &, Student &);

#endif