Implement the functions to work with a student. This function were listed and ex
ID: 3710347 • Letter: I
Question
Implement the functions to work with a student. This function were listed and explained in class, and are copied here for your reference. Only submit student.h and student.cpp #pragma once #include #include using std::string; using std: :ostream; using std::istream; struct Studentí string id; string name; int grade [3] void Initialize (student&); void Writestudent (const Student&, ostream&); void Readstudent (Student&, istream&); int GetGrade (const Student&, size_t); int setGrade (Student&, size_t, int); int GetAverage (const Student&); Function Description This function takes a student as parameter and initializes the values of the grades array to void Initialize(Student&) zero void WriteStudent(const Stu dent&, ostream&) Sends the formatted contents of a student to the provided ostream void ReadStudent(Student&, istream&) Reads the id, major and three grades from the provided istream int Getorade (const student &, size_t); The second parameter specifies which grade of the student to return, need to validate that the second parameter value is between O and 2 int setGrade (student&, size -t, int); Sets the grade of the student. The second parameter specifies what grade and the third parameter specifies the value int GetAverage (const Studen t8) Calculates the average of the three grades of the student parameter, returns this averageExplanation / Answer
/*** Below is the Complete Code ***/
/** student.h**/
#pragma once
#include<iostream>
#include<string>
using std::string;
using std::ostream;
using std::istream;
struct Student{
string id;
string name;
int grade[3];
};
void Initialize(Student &);
void WriteStudent(const Student &, ostream & );
void ReadStudent(Student &, istream &);
int GetGrade(const Student&, size_t);
int SetGrade(Student &, size_t, int);
int GetAverage(const Student &);
/*** student.cpp***/
#include "student.h"
void Initialize(Student &s){
for(int i=0;i<3;i++){
s.grade[i] = 0;
}
}
void WriteStudent(const Student &s, ostream &o ){
o<<"Student Id: "<<s.id<<" ";
o<<"Name: "<<s.name<<" ";
o<<"Grades:";
for(int i=0; i<3; i++){
o<<" "<<s.grade[i];
}
o<<" ";
}
void ReadStudent(Student &s, istream &i){
string id;
string name;
int grade1;
int grade2;
int grade3;
i>>id>>name>>grade1>>grade2>>grade3;
s.id = id;
s.name = name;
s.grade[0] = grade1;
s.grade[1] = grade2;
s.grade[2] = grade3;
}
int GetGrade(const Student &s, size_t t) {
if(t <0 || t>2){
return -1;
}
else
return s.grade[t];
}
int SetGrade(Student &s, size_t t, int val){
if(t <0 || t>2){
return -1;
}
else
s.grade[t] = val;
return 1;
}
int GetAverage(const Student &s){
int sum =0;
for(int i=0; i<3; i++){
sum += s.grade[i];
}
return sum/3;
}
int main(){
return 0;
}