I have been given two classes, Person and Student, where Person is the base class and Student is the derived class. Any change in Person class or main function is not allowed.. Observe that Student inherits all the properties of Person. A Student class constructor, which has parameters: A string, first name A string, last name An integer, id. An integer array (or vector) of test scores, . char calculate() method that calculates a Student object's average and returns the grade character representative of their calculated average. Sample Input-
Heraldo Memelli 8135627 2 100 80
Expected Output-
Name: Memelli, Heraldo ID: 8135627 Grade: O
Error which I am getting is while declaring constructor can you please explain me why and is there any other approach which you would suggest. Thanks in advance. Here's my code-
#include <iostream>
#include <vector>
using namespace std;
class Person {
protected:
string firstName;
string lastName;
int id;
public:
Person(string firstName, string lastName, int identification) {
this - > firstName = firstName;
this - > lastName = lastName;
this - > id = identification;
}
void printPerson() {
cout << "Name: " << lastName << ", " << firstName << "\nID: " << id << "\n";
}
};
class Student: public Person {
private: vector < int > testScores;
public: Student(string firstName, string lastName, int identification, vector < int > & scores) {
for (int i = 0; i < & scores.size(); i++)
this - > testScores.pushback( & scores[i]);
}
char calculate() {
int avg, sum = 0, count = 0;
for (int i = testScores.begin(); i < testScores.size(); i++) {
sum = sum + testScores[i];
count++;
}
avg = sum / count;
if (avg >= 90 && avg <= 100)
return ('O');
else if (avg >= 80 && avg < 90)
return ('E');
else if (avg >= 70 && avg < 80)
return ('A');
else if (avg >= 55 && avg < 70)
return ('P');
else if (avg >= 40 && avg < 55)
return ('D');
else if (avg0 < 40)
return ('T');
}
};
int main() {
string firstName;
string lastName;
int id;
int numScores;
cin >> firstName >> lastName >> id >> numScores;
vector < int > scores;
for (int i = 0; i < numScores; i++) {
int tmpScore;
cin >> tmpScore;
scores.push_back(tmpScore);
}
Student * s = new Student(firstName, lastName, id, scores);
s - > printPerson();
cout << "Grade: " << s - > calculate() << "\n";
return 0;
}