double ComputeGPA(const vector <student>& a)
{
double GPA = 0;
double sum = 0;
for( int i = 0; i<a.courses.size(); i++)
{
if(a.courses.at(i).lettergrade == "A+")
sum += 4.0;
if(a.courses.at(i).lettergrade == "A")
sum += 4.0;
if(a.courses.at(i).lettergrade == "A-")
sum += 3.7;
if(a.courses.at(i).lettergrade == "B+")
sum += 3.3;
if(a.courses.at(i).lettergrade == "B")
sum += 3.0;
if(a.courses.at(i).lettergrade == "B-")
sum += 2.7;
if(a.courses.at(i).lettergrade == "C+")
sum += 2.3;
if(a.courses.at(i).lettergrade == "C")
sum += 2.0;
if(a.courses.at(i).lettergrade == "C-")
sum += 1.7;
if(a.courses.at(i).lettergrade == "D")
sum += 1.0;
if(a.courses.at(i).lettergrade == "F")
sum += 0.0;
}
GPA = sum/a.courses.size();
cout << "Average GPA:" << GPA << endl;
}
Which gives me:
PI.cc: In function `double ComputeGPA(const std::vector<student, std::allocator<student> >&)':
PI.cc:117: error: 'const class std::vector<student, std::allocator<student> >' has no member named 'courses'
PI.cc:119: error: 'const class std::vector<student, std::allocator<student> >' has no member named 'courses'
PI.cc:121: error: 'const class std::vector<student, std::allocator<student> >' has no member named 'courses'
PI.cc:123: error: 'const class std::vector<student, std::allocator<student> >' has no member named 'courses'
PI.cc:125: error: 'const class std::vector<student, std::allocator<student> >' has no member named 'courses'
PI.cc:127: error: 'const class std::vector<student, std::allocator<student> >' has no member named 'courses'
PI.cc:129: error: 'const class std::vector<student, std::allocator<student> >' has no member named 'courses'
PI.cc:131: error: 'const class std::vector<student, std::allocator<student> >' has no member named 'courses'
PI.cc:133: error: 'const class std::vector<student, std::allocator<student> >' has no member named 'courses'
PI.cc:135: error: 'const class std::vector<student, std::allocator<student> >' has no member named 'courses'
PI.cc:137: error: 'const class std::vector<student, std::allocator<student> >' has no member named 'courses'
PI.cc:139: error: 'const class std::vector<student, std::allocator<student> >' has no member named 'courses'
PI.cc:142: error: 'const class std::vector<student, std::allocator<student> >' has no member named 'courses'
Compilation exited abnormally with code 1 at Mon Apr 16 19:47:14
Those lines correspond to the if(a.courses.at(i).lettergrade == "A-") etc.
If needed:
#include <fstream>
#include <vector>
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
struct course
{
char session;
int year;
string coursename;
int coursenumber;
double percentage;
string lettergrade;
};
struct student
{
vector <course> courses;
string firstname;
string lastname;
int id;
};
What's the problem now?