Duplicate symbols for architecture?

I have an assignment where I am supposed to create a header file, a function.cpp file, and a main.cpp to create a gradebook for students where you can set and adjust data using vectors of objects. My code has no syntactical errors, but it is not running. My error message is:

"linker command failed with exit code 1 (use -v to see invocation)
13 duplicate symbols for architecture x86_64"

This is my first time posting so sorry about formatting issues. Thank you in advance...

// Header file Student.h

#ifndef Student_h
#define Student_h

#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
using namespace std;

class Student {
public:
Student();
Student(string, char, int, int);

string getName();
char getGender();
int getMath();
int getProg();

void setName(string);
void setGender(char);
void setMath(int);
void setProg(int);

void setRecord(string, char, int, int);
void printRecords();
void findRecord(vector<Student>,string, int, int);

private:
string newName;
char newGender;
int newMath;
int newProg;

string name;
char gender;
int math_score;
int programming_score;


//vector<Student> studentVector;

};

#endif /* Student_h */

//
// function file StudentFunct.cpp

#include "Student.h"




// class functions?
/*Student::Student(){
newName = ' ';
newGender = ' ';
newMath = 0;
newProg = 0;
}
*/
Student::Student(string name, char gender, int math_score, int programming_score){
newName = name;
newGender = gender;
newMath = math_score;
newProg = programming_score;
}




string Student::getName(){
return newName;
}
char Student::getGender(){
return newGender;
}
int Student::getMath(){
return newMath;
}
int Student::getProg(){
return newProg;
}





// edit functions ex: Student[]
void Student::setName(string name){
newName = name;
}
void Student::setGender(char gender){
newGender = gender;
}
void Student::setMath(int math_score){
newMath = math_score;
}
void Student::setProg(int programming_score){
newProg = programming_score;
}





// required functions
void Student::setRecord(string name, char gender, int math_score, int programming_score){
newName = name;
newGender = gender;
newMath = math_score;
newProg = programming_score;
}

void Student::printRecords(){
cout << "Name Gender Math Prog";
cout << newName << " " << newGender << " " << newMath << " " << newProg;
cout << endl;
}


void Student::findRecord(vector<Student> studentVector,string name, int studentSize, int SAFETY){
int h = 0;
while(h < studentSize ) {
// OUTPUT STUDENT INFO, ASK TO ADJUST
if (studentVector[h].getName() == name) {
cout << "Name Gender Math Prog";
cout << studentVector[h].getName() << " " << studentVector[h].getGender() << " " << studentVector[h].getMath() << " " << studentVector[h].getProg();
cout << "Select the following sub-options\n 1. Edit math score\n 2. Edit prog score " << SAFETY << endl;


int userChoice2;
switch(userChoice2) {
// ADJUST MATH SCORE
case 1:{
//Enter math score
cout << "Enter the new score: ";
cin >> math_score;
cout << endl;

cout << "Name Gender Math Prog";
cout << studentVector[h].getName() << " " << studentVector[h].getGender() << " " << studentVector[h].getMath() << " " << studentVector[h].getProg();
}
// ADJUST PROG SCORE
case 2:{
// Enter prog score
cout << "Enter the new score: ";
cin >> programming_score;
cout << endl;

cout << "Name Gender Math Prog";
cout << studentVector[h].getName() << " " << studentVector[h].getGender() << " " << studentVector[h].getMath() << " " << studentVector[h].getProg();
}
default:
cout << "You did not enter a valid input.\n" ;
} // end switch


} // end of if
else cout << "Name: " << name << " not found.";
break; // NAME NOT FOUND
}
}

//
// main.cpp


#include "StudentFunct.cpp"


int main() {
int studentSize; // number of students
cout << "How many students do you have?" << endl;
cin >> studentSize;



// SET RECORDS
string name;
char gender;
int math_score;
int programming_score;


Student *myStudent;
vector<Student> studentVector;
for( int s = 1; s <studentSize; s++){
cout << "Enter new student records (name gender math_score programming_score)" << endl;
cout << s << ": ";
cin >> name >> gender >> math_score >> programming_score;
myStudent->setRecord(name, gender, math_score, programming_score); // setRecord used here
studentVector.push_back(*myStudent);
} // SET RECORDS USED


// INTRO PRINT RECORDS or SELECT AND REPLACE
int SAFETY = 1;
int quitCount = 1;
int userChoice;

while (SAFETY > 0) {
cout << "Select the following options:\n";
cout << " 1. Print all student records\n";
cout << " 2. Search student record by name\n";
cout << " 3. Quit " << quitCount++ << endl;
if (quitCount == 100){
cout << "Maximum loops reached. Please run program again.";
break;
}
cin >> userChoice;

switch (userChoice) {

// PRINT RECORDS
case 1: { // print all
vector<Student>::iterator it;
for ( it = studentVector.begin(); it != studentVector.end(); ++it ) {
it->printRecords(); // printRecords used here
}
break;
} // PRINT RECORDS USED
// FIND STUDENT USING WHILE LOOP
case 2: {
cout << "Enter student name for searching: ";
cin >> name;

myStudent->findRecord(studentVector, name, studentSize, SAFETY);

}
default:
break;
} // PRINT RECORDS END
} // PRINT RECORDS or SELECT AND REPLACE END

return 0;
} // END OF MAIN
One problem is that you have names in your class with the same name as the parameters.
1
2
3
4
5
6
Student::Student(string name, char gender, int math_score, int programming_score){
newName = name;
newGender = gender;
newMath = math_score;
newProg = programming_score;
}

It's common practice to start the variable names in a class with m_
Topic archived. No new replies allowed.