Can someone please compile my code and see what the problem I am getting an undefined reference error and I am just stumped on what to do I have tried about everything. The only file I allowed to edit is students.cpp
to use the function if it compiles = ./registration courseList.dat enrollmentList.dat outputReport.csv
Error I am getting
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
sirius: make
touch registration.d
touch courses.d
touch students.d
cat registration.d courses.d students.d > make.dep
g++ -g -DUnix -MMD -o registration.o -c registration.cpp
g++ -g -DUnix -MMD -o courses.o -c courses.cpp
g++ -g -DUnix -MMD -o students.o -c students.cpp
g++ -g -DUnix -o registration registration.o courses.o students.o
registration.o: In function `printReport(std::ostream&)':
/home/x/cs333/array/registration.cpp:53: undefined reference to `students'
/home/x/cs333/array/registration.cpp:54: undefined reference to `students'
/home/x/cs333/array/registration.cpp:55: undefined reference to `students'
/home/x/cs333/array/registration.cpp:57: undefined reference to `students'
/home/x/cs333/array/registration.cpp:56: undefined reference to `students'
collect2: error: ld returned 1 exit status
make: *** [registration] Error 1
#include "arrayUtils.h"
#include "courses.h"
usingnamespace std;
int numCourses;
Course* courses; // array of courses
// Initialize all course data, allowing for at least the indicated
// number of courses
void initializeCourses(int maxCourses)
{
numCourses = 0;
courses = new Course[maxCourses];
}
// Clean up course data
void cleanUpCourses()
{
delete [] courses;
}
// Read course info from an input stream
void readCourses (std::istream& in)
{
int maxCourses;
in >> maxCourses;
initializeCourses (maxCourses);
string name;
while (in >> name)
{
int credit;
in >> credit;
//cerr << name << " " << credit << endl;
addCourse (name, credit);
}
}
// Search an array for a given value, returning the index where
// found or -1 if not found.
int seqSearch(const Course list[], int listLength, std::string searchItem)
{
int loc;
for (loc = 0; loc < listLength; loc++)
if (list[loc].name == searchItem)
return loc;
return -1;
}
// Add a course with the indicated number of credits
void addCourse (std::string courseName, int credits)
{
courses[numCourses].name = courseName;
courses[numCourses].credits = credits;
++numCourses;
}
// Get the number of credits for a course
int getCredits (std::string courseName)
{
int pos = seqSearch (courses, numCourses, courseName);
if (pos >= 0)
return courses[pos].credits;
elsereturn 0;
}
#ifndef COURSES_H
#define COURSES_H
#include <iostream>
#include <string>
struct Course {
std::string name; // course name
int credits; // number of credits this course is worth
};
externint numCourses;
extern Course* courses; // array of courses
// Initialize all course data, allowing for at least the indicated
// number of courses
void initializeCourses(int maxCourses);
// Clean up course data
void cleanUpCourses();
// Read course info from an input stream
void readCourses (std::istream& in);
// Add a course with the indicated number of credits
void addCourse (std::string courseName, int credits);
// Get the number of credits for a course
int getCredits (std::string courseName);
#endif
#ifndef STUDENTS_H
#define STUDENTS_H
#include <string>
struct Student {
std::string name; // name of this student
int credits; // total number of credits for this student
};
externint numStudents;
extern Student* students; // array of students
// Initialize all student data, allowing for at least the indicated
// number of students
void initializeStudents(int maxStudents);
// Clean up student data
void cleanUpStudents();
// Add a student, starting with 0 credits. Return position where
// inserted.
int addStudent (std::string studentsName);
// Add a number of credits taken by a student
int addCredits (std::string studentName, int credits);
#endif