Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to de-bug the C++ program to make it compile? ( I'm currently getting 3 error messages which i'm having a hard time trying to

How to de-bug the C++ program to make it compile?

( I'm currently getting 3 error messages which i'm having a hard time trying to figure out. I've added comments where the errors are located and the messages i'm receiving from the compiler. If I can get some help on this i'd really appreciate it.)

#include

using namespace std;

template

class Student {

private:

string firstName, lastName;

int ID;

float weights[4];

T scores[4];

public:

Student (string x, string y, int z, float wt[], T sc[]);

void setfirstName(string fn);

string getfirstName();

void setlastName(string ln);

string getlastName();

void setID(int num);

int getID();

void setWeights(float w[]);

float getWeights();

T setScores(T s[]);

T getScores();

float weightedAvg();

char gradeScale(int p);

};

//Main Test Function

int main (){

string fn, ln;

int id;

float wt[4];

T sc[4]; // ERROR: Unknown typename 'T'

char grade;

float avg;

cout << "Enter First name > ";

cin >> fn;

cout << "Enter Last Name > ";

cin >> ln;

cout << "Enter ID > ";

cin >> id;

cout << "Enter Weighed Scores > ";

for(int i=0;i<4;i++){

cin>>wt[i];

}

cout << "Enter Test Scores > ";

for(int i=0;i<4;i++){

cin>>sc[i];

}

Student s = new Student(fn,ln,wt,sc); //ERROR: Use of class template 'Student' requires template arguments

avg = s.weightedAvg();

grade = s.gradeScale(avg);

cout<<"The grade of " <

return 0;

}

// Implementations

//-----------------

template

Student::Student(string x, string y, int z, float wt[], T sc[]){

setfirstName(x);

setlastName(y);

setID(z);

setWeights(wt);

setScores(sc);

}

template

void Student::setfirstName(string fn){

firstName = fn;

}

template

string Student::getfirstName(){

return firstName;

}

template

void Student::setlastName(string ln){

lastName = ln;

}

template

string Student::getlastName(){

return lastName;

}

template

void Student::setID(int num){

ID = num;

}

template

int Student::getID(){

return ID;

}

template

void Student::setWeights(float w[]){

for (int i = 0; i < 4; i++)

{

weights[i] = w[i];

}

}

template

float Student::getWeights(){

for (int i = 0; i < 4; i++){

return weights[i];

}

}

template

T Student::setScores(T s[]){

for (T i = 0;i < 4; i++){

scores[i] = s[i];

}

}

template

T Student::getScores(){

for (T i = 0; i < 4; i++){

return scores[i];

}

}

template

float weightedAvg (){

//ERROR: Use of undeclared identifier 'scores' and 'weights'

return weights[0]*scores[0] + weights[1]*scores[1] + weights[2]*scores[2] + weights[3]*scores[3];

}

template

char gradeScale(int p)

{

if(p>=90)

return 'A';

else if(p < 90 && p >= 80)

return 'B';

else if(p > 80 && p <= 70)

return 'C';

else if(p > 70 && p <= 60)

return 'D';

else

return 'F';

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions