I was doing some revisions and while making this program I got these errors I can't really figure out:
The program is supposed to receive a students' name, midterm grade, final grade and homework grades (using a struct), and display two lists: One for students who failed, and one for students who passed, both sorted alphabetically.
Here's the code:
main.cpp
studentdata.hCode:#include <iostream> #include <vector> #include <algorithm> #include "studentdata.h" #include "grades.h" using std::cout; using std::cin; using std::endl; using std::vector; using std::sort; int main() { StudentData student; vector<StudentData> students; cout << "Enter student data (name, first exame, last exame, homework): "; while (readData (cin, student)) { students.push_back (student); cout << "Enter student data (name, first exame, last exame, homework): "; } sort (students.begin(), students.end(), alphabetically); vector<StudentData> failures = extractResult (students); cout << "Passes: " << endl; vector<StudentData>::size_type size = students.size(); for (vector<StudentData>::size_type i = 0; i < size; i++) { cout << students[i].name << endl; } cout << "Failures: " << endl; size = failures.size(); for (vector<StudentData>::size_type i = 0; i < size; i++) { cout << failures[i].name << endl; } return 0; }
studentdata.cppCode:#ifndef STUDENTDATA_H #define STUDENTDATA_H #include <iostream> #include <string> #include <vector> #include "grades.h" struct StudentData { std::string name; double midterm, final; std::vector<double> hw; }; std::istream& readData (std::istream& input, StudentData& data); std::istream& readHW (std::istream& input, std::vector<double>& vec); bool alphabetically (const StudentData& a, const StudentData& b); std::vector<StudentData> extractResult (std::vector<StudentData>& students); #endif
grades.hCode:#include <iostream> #include <string> #include <vector> #include "grades.h" using std::istream; using std::vector; istream& readData (istream& input, StudentData& data) { input >> data.name >> data.midterm >> data.final; readHW (input, data.hw); return input; } istream& readHW (istream& input, vector<double>& vec) { if (input) { vec.clear(); double x; while (input >> x) vec.push_back(x); input.clear(); } return input; } bool alphabetically (const StudentData& a, const StudentData& b) { return (a.name < b.name); } vector<StudentData> extractResult (vector<StudentData>& students) { vector<StudentData>::size_type size = students.size(); vector<StudentData> success; vector<StudentData> failures; for (vector<StudentData>::size_type i = 0; i < size; i++) Positive (students[i])? success.push_back (students[i]) : failures.push_back (students [i]); students = success; return failures; }
grades.cppCode:#ifndef GRADES_H #define GRADES_H #include <vector> #include "studentdata.h" double Grade (const StudentData& student); double Median (std::vector<double> vec); double Grade (double midterm, double final, const std::vector<double>& hw); bool Positive (const StudentData& student); double Grade (double midterm, double final, double hw); #endif
Compiler complains about grades.h with the following errors:Code:#include <vector> #include <algorithm> #include "grades.h" using std::vector; using std::sort; double Grade (const StudentData& student) { return Grade (student.midterm, student.final, student.hw); } double Median (vector<double> vec) { sort (vec.begin(), vec.end()); vector<double>::size_type size = vec.size(); vector<double>::size_type mid = size / 2; return size % 2 == 0? (vec[mid] + vec[mid-1]) / 2 : vec[mid]; } double Grade (double midterm, double final, const vector<double>& hw) { return Grade (midterm, final, Median (hw)); } bool Positive (const StudentData& student) { return Grade (student) >= 50? 1 : 0; } double Grade (double midterm, double final, double hw) { return (0.2 * midterm + 0.4 * final + 0.4 * hw); }
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2143: syntax error : missing ',' before '&'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2143: syntax error : missing ',' before '&'
I looked through the code tons of times but I just can't seem the find the problem. It complains about missing type specifier on the first Grade function in grades.h and Positive function, yet their type is specified...
I must be missing something but I really can't find it so... Any help appreciated.



LinkBack URL
About LinkBacks



