i keep getting this error message: error LNK2019: unresolved external symbol \"p
ID: 3529890 • Letter: I
Question
i keep getting this error message: error LNK2019: unresolved external symbol "public: __thiscall TestScore::TestScore(double const * const,int)" (??0?$TestScore@N@@QAE@QBNH@Z) referenced in function _main 1>Source.obj : error LNK2019: unresolved external symbol "public: __thiscall TestScore::~TestScore(void)" (??1?$TestScore@N@@QAE@XZ) referenced in function _main //********************************TestScore.h File*****************************************************************88 #include "TestScore.h" template TestScore::TestScore(void) { scoreArray = new T[COUNT]; numScore=0; for(int i=0; iTestScore::TestScore(const T score[], int n){ scoreArray = new T[n]; copy(score, score+n, scoreArray); /*for(int i=0; i<=n; i++){ scoreArray[i] = score[i]; }*/ numScore = n; } template TestScore::~TestScore(void) { delete [] scoreArray; } template T TestScore:: averageScore() const { T totalScore = 0; for(int i=0; i<=numScore; i++) totalScore=+ scoreArray[i]; totalScore = totalScore/numScore; return totalScore; } //******************************************TestScore.cpp File************************************************ #pragma once #include #include #include using namespace std; template class TestScore { private: static const int COUNT=20; T *scoreArray; int numScore; public: TestScore(); TestScore(const T score[], int n); ~TestScore(); //calculate average score T averageScore() const; }; //*************************main************************************************** #include #include "TestScore.h" using namespace std; int main(){ double newScore[] ={12.2,36.5,36.2,36.3,65.5,63.8,65.6,96.6,56.5,65.5}; TestScore myTest(newScore, 10); TestScore test(); return 0; } Thank you in advanceExplanation / Answer
By making it a reference to a pointer, array-to-pointer decay is prevented and the array constructor is chosen.
Also, I don't see how your code compiles, I see many errors:
Your template constructor has a parameterclass T, this conflicts with theclass Tof the class template:
#include <iostream>
using namespacestd;
float findAverage (int [], int); // finds average of all grades
int findHighest (int [], int&); // finds highest of all grades
int findLowest (int [], int&); // finds lowest of all grades
int main()
{
const intSIZE=100;
int grades[SIZE]; // == ???
int numberOfGrades; // == ???
int pos; // == ???
int size; // == ???
float avgOfGrades; // == ???
int highestGrade; // == ???
int lowestGrade; // == ???
// Read the values into the array
// pos == 0, grades[0] == ???
pos = 0;
cout << "Please input a grade from 1 to 100, (or -99 to stop)" << endl;
// Fake input: 1
cin >> grades[pos];
// pos == 0, grades[0] == 1
// 1: pos == 0, grades[0] == 1, grades[0] != -99
// 2: pos == 0, grades[0] == 75, grades[0] != -99
// 3: pos == 0, grades[0] == 84, grades[0] != -99
// 4: pos == 0, grades[0] == 99, grades[0] != -99
// 5: pos == 0, grades[0] == 100, grades[0] != -99
// 6: pos == 0, grades[0] == -99, grades[0] == -99 --->
while (grades[pos] != -99)
{
// 1: (pos + 1) == 1, grades[1] == ???
// 2: (pos + 1) == 1, grades[1] == ???
// 3: (pos + 1) == 1, grades[1] == ???
// 4: (pos + 1) == 1, grades[1] == ???
// 5: (pos + 1) == 1, grades[1] == ???
cout << "enter test score number " << (pos + 1) << ":";
// 1: Fake input 75
// 2: Fake input 84
// 3: Fake input 99
// 4: Fake input 100
// 5: Fake input -99
cin >> grades[pos];
// 1: pos == 0, grades[0] == 75
// 2: pos == 0, grades[0] == 84
// 3: pos == 0, grades[0] == 99
// 4: pos == 0, grades[0] == 100
// 5: pos == 0, grades[0] == -99
}
// --->
// pos == 0, grades[0] == -99, numberOfGrades == -99
numberOfGrades = grades[pos]; // Fill blank with appropriate identifier
// call to the function to find average
// avgOfGrades == ???
// avgOfGrades == findAverage(grades, -99) --->
avgOfGrades = findAverage(grades, numberOfGrades);
// --->
// avgOfGrades == 0
cout << endl << "The average of all the grades is " << avgOfGrades << endl;
// Fill in the call to the function that calculates highest grade
// highestGrade == ???
// highestGrade == findHighest(grades, -99) --->
highestGrade = findHighest(grades, size);
// --->
// highestGrade == ???
cout << endl << "The highest grade is " << highestGrade << endl;
// Fill in the call to the function that calculates lowest grade
// lowestGrade == ???
// lowestGrade == findLowest(grades, -99) --->
lowestGrade = findLowest(grades, size);
// Fill in code to write the lowest to the screen
// --->
// lowestGrade == ???
cout << endl << "The highest grade is " << lowestGrade << endl;
return 0; // ---> (0)
}
//****************************************************************************
// findAverage
//
// task: This function receives an array of integers and its size.
// It finds and returns the average of the numbers in the array
// data in: array of floating point numbers
// data returned: avarage of the numbers in the array
//
//****************************************************************************
float findAverage (int array[], intsize)
{
// --->
float sum = 0; // holds the sum of all the numbers
// for (pos = 0, pos < -99; pos++) --->
for (intpos = 0; pos < size; pos++)
sum = sum + array[pos];
// --->
// sum == 0, size == -99
return (sum / size); // --->
}
int findHighest (int array[], int& size)
{
// Fill in the code for this function
// --->
// array == grades, size == -99, SIZE == 100
const intSIZE=100;
int highest; // == ???
int grades[SIZE]; // == ???
// grades[0] == ???, highest == ???
highest = grades[0];
// for (pos == 1, pos < 100; pos++)
for (intpos = 1; pos < SIZE; pos++)
{
// grades[pos] == ???, highest == ???
if(grades[pos] > highest)
// highest == ???
highest = grades[pos];
// etc...
}
// highest == ???
return highest; // --->
}
int findLowest(intarray[], int& size)
{
// --->
// Fill in the code for this function
const intSIZE=100;
int lowest; // == ???
int grades[SIZE]; // == ???
// grades[0] == ???, lowest == ???
lowest = grades[0];
// for (pos == 1; pos < 100; pos++)
for (intpos = 1; pos < SIZE; pos++)
{
// grades[pos] == ???, lowest == ???
if(grades[pos] < lowest)
// grades[pos] == ???, lowest == ???
lowest = grades[pos];
// etc...
}
// lowest == ???
return lowest; // --->
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.