Part Il: Programming Note: a) -3 point for each and every syntax error; repeated
ID: 3716158 • Letter: P
Question
Part Il: Programming Note: a) -3 point for each and every syntax error; repeated offenses will results in multiple times of deductions; b) -5 or more points for each logical errors depending on the severity of the errors) Given the student class interface below: class student friend istream& operator>istceams, student&); // Prompt the user to enter a student name and the performance record including name, scores for quizzes, final, HW, etc. for the student // Postcondition: a student record is loaded with values entered by the user friend 9atcea0& operator(wtceank, student&): 10% 2. Implement the 9 strea0&operator;Explanation / Answer
//student.h
#include <iostream>
#include <string>
using namespace std;
class student
{
friend istream& operator >> (istream&, student&);
friend ostream& operator << (ostream&, student&);
public:
student() {}
void computeOverallGrade();
int compareOverallGrade(student&);
private:
string name;
int quiz[4];
int final;
int HW;
int programming;
double overAllGrade;
};
//student.cpp
#include "student.h"
#include <vector>
#include <algorithm>
bool compare(student& student1, student& student2)
{
return student1.compareOverallGrade(student2) == 1 ? true : false;
}
void sortRecords(vector<student>& records)
{
sort(records.begin(), records.end(), compare);
}
istream& operator >> (istream& is, student& student)
{
cout << "Enter student name, scores for quizzes, final, HW: ";
is >> student.name;
is >> student.quiz[0] >> student.quiz[2] >> student.quiz[2] >> student.quiz[3] >> student.final >> student.HW >> student.programming;
return is;
}
ostream & operator<<(ostream& os, student& student)
{
os << endl << "Student name: " << student.name << endl;
os << "Quiz scores: " << student.quiz[0] << " " << student.quiz[2] << " " << student.quiz[2] << " " << student.quiz[3] << endl;
os << "Final: " << student.final << endl;
os << "HW: " << student.HW << endl;
os << "Programming: " << student.programming << endl;
os << "Overallgrading: " << student.overAllGrade << endl;
return os;
}
void student::computeOverallGrade()
{
overAllGrade = (HW*0.10) + (programming*0.40) + (((quiz[0] + quiz[1] + quiz[2] + quiz[3]) / 4)* 0.25) + (final * 25);
}
int student::compareOverallGrade(student& student)
{
return student.overAllGrade > overAllGrade ? 1 : student.overAllGrade == overAllGrade ? 0 : -1;
}
//main.cpp
#include "student.h"
int main()
{
student student;
std::cin >> student;
student.computeOverallGrade();
std::cout << student;
return 0;
}