I have many .h and .cpp programs linked into a main to generate a computation on a vector filled with student grades.
I have tried g++ main.cpp grades.cpp Student_info.cpp median.cpp and I don't get a notice of error.
I get the following error:
ja@ja-desktop:~/StudentReports$ g++ main.cpp -o main
/tmp/ccIEOX7Y.o: In function `main':
main.cpp:(.text+0x77): undefined reference to `read(std::basic_istream<char, std::char_traits<char> >&, Student_info&)'
main.cpp:(.text+0xc3): undefined reference to `compare(Student_info const&, Student_info const&)'
main.cpp:(.text+0x191): undefined reference to `grade(Student_info const&)'
collect2: ld returned 1 exit status
#include<algorithm>
#include<iomanip>
#include<ios>
#include<iostream>
#include<stdexcept>
#include<string>
#include<vector>
//main.cpp
#include "grade.h"
#include "Student_info.h"
#include "median.h"
using std::cin;
using std::cout;
using std::domain_error;
using std::endl;
using std::max;
using std:: setprecision;
using std:: sort;
using std:: streamsize;
using std:: string;
using std:: vector;
int main()
{
vector<Student_info> students;
Student_info record;
string:: size_type maxlen = 0;
// the length of the longest name
// read and store all the students data.
// Invariant: students contains all the student records read so far
//maxlen contains the length of the longest name in students
while (read(cin, record))
{
// find length of longest name
maxlen = max(maxlen, record.name.size() );
students.push_back(record);
}
// alphabetize the student records
sort(students.begin(), students.end(), compare);
// write the names and grades
for (vector<Student_info> :: size_type i = 0; i != students.size(); ++i) {
// write the name, padded on the right to maxlen + 1 characters
cout << students[i].name
<< string(maxlen + 1 - students[i].name.size(), ' ');
// compute and write the grade
try {
double final_grade = grade(students[i]);
streamsize prec = cout.precision();
cout << setprecision(3) << final_grade
<< setprecision(prec);
}
catch (domain_error e) {
cout << e.what();
}
cout << endl;
}
return 0;
}