I am in my second c++ class in school and I am stuck on my latest project. I want to be upfront and say this is a homework assignment. My teacher said it is okay to look for guidance online and that is what I am graciously looking for.
My problem is the multiple linker errors I am getting when i try to rebuild the project. Below is the list of errors I am getting and below that is the code for my project. I am sorry to post so much code, but I have been on Spring Break for the week so i have not been able to consult my professor and I am really getting frustrated. Any help would be greatly appreciated. I can also post the assignment guidelines if someone needs them.
[Linker error] undefined reference to `Student::setstudentID(int)'
[Linker error] undefined reference to `Student::setfirstname(std::string)'
[Linker error] undefined reference to `Student::setgradeAve(double)'
[Linker error] undefined reference to `Student::setgradeAve(double)'
[Linker error] undefined reference to `Student::setletterGrade(char)'
[Linker error] undefined reference to `Student::setletterGrade(char)'
[Linker error] undefined reference to `Student::setletterGrade(char)'
[Linker error] undefined reference to `Student::setletterGrade(char)'
[Linker error] undefined reference to `Student::setletterGrade(char)'
[Linker error] undefined reference to `Student::count'
[Linker error] undefined reference to `Student::count'
[Linker error] undefined reference to `Student::count'
[Linker error] undefined reference to `Student::count'
[Linker error] undefined reference to `Student::count'
more undefined references to 'Student::count' follow
Id returned 1 exit status
[Build Error] [DesignClasses.exe] Error 1
---MAIN FILE----
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include "Student.h"
using namespace std;
bool repeat(void);
void gradeaverage (Student object1[], int testaverage1[], double& testsum1);
void printStudent (Student object1[], int testaverage1[], double& testsum1);
int main(int argc, char *argv[])
{
//Array of max 25 Student Objects
Student object[25];
bool check = true;
int testaverage[5];
double testsum = 0;
int int1;
string string1;
double double1;
char char1;
for (int h = 0; h < 5 ; h++) //setting testaverage equal to 0
{
testaverage[h] = 0;
}
for (int i = 0; i < 25 && check; i++)
{
cout << "Please enter the Student Id #: ";
cin >> int1;
cin.ignore (1);
object[i].setstudentID (int1);
cout << "Please enter first name: ";
getline (cin, string1);
object[i].setfirstname (string1);
cout << "Please enter last name: ";
getline (cin, string1);
object[i].setlastname (string1);
int array[5];
for (int j = 0; j < 5; j++)
{
cout << "Please enter the test score for test " << j + 1 << ": ";
cin >> int1;
array[j] = int1;
}
object[i].settestscores(array);
check = repeat();
system ("cls");
}
system("PAUSE");
return EXIT_SUCCESS;
}
void gradeaverage (Student object1[], int testaverage1[], double& testsum1)
{
for (int i = 0 ; i < object1[1].getcount() ; i++) //Loop equal to count of students - max of 25 students
{
for (int j = 0 ; j < 5 ; j++) //Loop for the 5 test scores
{
object1[i].setgradeAve (object1[i].getgradeAve() + object1[i].gettestscores(j) );
object1[i].setgradeAve (object1[i].getgradeAve() / 5);
testaverage1[j] += object1[i].gettestscores(j);
}
for (int k = 0 ; k < 5 ; k++)
{
testaverage1[k] /= object1[1].getcount();
testsum1 += testaverage1[k];
}
testsum1 /= 5;
if (object1[i].getgradeAve() >= 90)
{
object1[i].setletterGrade('A');
}
else if (object1[i].getgradeAve() >= 80)
{
object1[i].setletterGrade('B');
}
else if (object1[i].getgradeAve() >= 70)
{
object1[i].setletterGrade('C');
}
else if (object1[i].getgradeAve() >= 60)
{
object1[i].setletterGrade('D');
}
else
{
object1[i].setletterGrade('F');
}
}
}
void printStudent (Student object1[], int testaverage1[], double& testsum1)
{
cout << setw(4) << "ID" << "\t" << "Student Name" << "\t"
<< setw(5) << "1" << "2" << "3" << "4" << "5"
<< setw(5) << "Avg"
<< setw(5) << "GRD";
for (int i = 0 ; i < object1[1].getcount() ; i++)
{
cout << object1[i].print();
}
cout << "\t" << "Average:" << setw(15);
for (int j = 0 ; j < 5 ; j++)
{
cout << testaverage1[j];
}
cout << "\t" << testsum1 << endl;
}
// Bool function that will allow user to add another student or end
bool repeat(void)
{
char resp;
do
{
cout << "Do you want to add another student [Y]es | [N]o\n";
cin >> resp;
cin.ignore(50, '\n');
resp = tolower(resp);
}
while (resp != 'y' && resp != 'n');
return resp == 'y';
}
|
----Header FILE----
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream>
using namespace std;
class Student
{
//Variables
private:
int studentID;
string firstname;
string lastname;
double gradeAve;
char letterGrade;
static int count;
int testscores[5];
public:
//Accessors and Mutators
void setstudentID (int sID);
void setfirstname (string fname);
void setlastname (string lname);
void setgradeAve (double gAve);
void setletterGrade (char ltrGrade);
void settestscores (int score1[]);
int getstudentID() {return studentID;};
string getfirstname() {return firstname;};
string getlastname() {return lastname;};
double getgradeAve() {return gradeAve;};
char getletterGrade() {return letterGrade;};
int gettestscores(int score) {return testscores[score];};
int getcount () {return count;};
//Default Constructor
Student();
//Copy Constructor
Student(const Student&);
//Info Constructor
Student(int, string, string, double, char, int[]);
//Print method
string print();
};
|
----.CPP FILE----
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <iostream>
#include <iomanip>
#include <sstream>
#include "Student.h"
using namespace std;
//Default Constructor
Student::Student()
{
studentID = 0;
firstname = " ";
lastname = " ";
gradeAve = 0;
letterGrade = ' ';
count += 1;
for (int i = 0; i < 5 ; i++)
{
testscores[i] = 0;
}
}
//Copy Constructor
Student::Student(const Student& Student1)
{
count += 1;
studentID = Student1.studentID;
firstname = Student1.firstname;
lastname = Student1.lastname;
gradeAve = Student1.gradeAve;
letterGrade = Student1.letterGrade;
for (int i = 0; i < 5 ; i++)
{
testscores[i] = Student1.testscores[i];
}
}
//Info Constructor
Student::Student(int sID, string fname, string lname, double gAve, char lGrade, int tscores[])
{
studentID = sID;
firstname = fname;
lastname = lname;
gradeAve = gAve;
letterGrade = lGrade ;
count += 1;
for (int i = 0; i < 5 ; i++)
{
testscores[i] = tscores[i];
}
}
//Print method
string Student::print()
{
stringstream strstr;
strstr << setw(4) << studentID << "\t" << lastname << ", " << firstname << "\t";
for (int i = 0; i < 5; i++)
{
strstr << setw(5) << testscores[i];
strstr << fixed << showpoint << setprecision(1);
strstr << setw(5) << gradeAve;
strstr << setw(5) << letterGrade << endl;
return strstr.str();
}
}
//Setstudentscores Function
void Student::settestscores (int score1[])
{
for (int i = 0; i < 5; i++)
{
testscores[i] = score1[i];
}
}
|