The intent of this assignment is to expose you to a program that creates a new d
ID: 653986 • Letter: T
Question
The intent of this assignment is to expose you to a program that creates a new data type by creating a class called Student. You will use the provided .cpp and .h files. You simply need to complete the implementation of the Student class. You do not need to change the main() program or the class declaration in the .h file.
BACKGROUND
A program has been created that will read student data from a text file (grades.txt). This document stores student names, both first and last names, the student EID, and a list of exam grades. Using a new data type, the Student class, the program will read multiple students into an array of Student objects. The program will then produce a report that lists all students, the course exam grades, the grade average and the letter grade for each student.
The program is
Explanation / Answer
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<cstring>
using namespace std;
class Student{
private:
string firstName;
string lastName;
string EID;
double grades[20];
int numGrades;
public:
Student(){
numGrades=0;
}
void setFirstName(string newName){
firstName=newName;
}
void setLastName(string newName){
lastName=newName;
}
void setName(string name){
int space=0;
int j=0;
int k=0;
for(int i=0;i<name.size();i++){
if(name[i]==' '){
space=1;
continue;
}
if(name[i]!=' '&&space==0){
firstName[j++]=name[i];
}
if(space==1){
lastName[k++]=name[i];
}
}
firstName='';
lastName[k]='';
}
void setEID(string newEID){
EID=newEID;
}
string getFirstName(){
return firstName;
}
string getLastName(){
return lastName;
}
string getFullName(){
return firstName+" "+lastName;
}
string getEID(){
return EID;
}
int getNumGrades(){
for(int i=0;grades[i]!=-1;i++){
}
return i;
}
double getGrade(int index){
return grades[i];
}
void addGrade(double newGrade){
int i;
for(i=0;grades[i]!=-1;i++){
}
grades[i]=newGrade;
}
double getAverage(){
double sum=0;
double avg=0;
for(int i=0;grades[i]!=-1;i++){
sum+=grades[i];
}
avg=sum/i;
return avg;
}
char getLetterGrade(){
char letterGrade;
double avg=getAverage();
if(avg>=90){
letterGrade='A';
}else if(avg>=80&&avg<90){
letterGrade='B';
}else if(avg>=70&&avg<80){
letterGrade='C';
}else if(avg>=60&&avg<70){
letterGrade='D';
}
return letterGrade;
}
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.