我一直在完成任务,最后一部分要求我建立一个函数(通过逐步细化的过程)来计算学生的GPA。开始我给了包含参数的函数声明。但我仍然坚持使用未定义的引用,并且无法解决问题。
这里是在我的主驱动程序文件中调用函数(computeGPA)而忽略其他一些函数
#include <iostream>
#include <sstream>
#include <iomanip>
#include "gpa.h"
#include "vectorUtils.h"
void studentGradeSummary (istream& in)
{
vector<std::string> gradeCodes;
vector<bool> affectsGPA;
vector<bool> affectsCreditsEarned;
vector<double> pointValues;
initializeGradingScheme(gradeCodes, affectsGPA,
affectsCreditsEarned, pointValues);
int creditsEarned;
int gradedCreditsAttempted;
double gradePoints;
in >> creditsEarned >> gradedCreditsAttempted >> gradePoints;
string garbage;
getline (in, garbage);
vector<std::string> gradeReported;
vector<int> creditsRegisteredFor;
readSemesterGrades (in, gradeReported, creditsRegisteredFor);
int newCreditsEarned = -1;
int newGradedCreditsAttempted = -1;
double newGradePoints = -1.0;
double semesterGPA = -1.0;
double overallGPA = -1.0;
computeGPA (gradeCodes, affectsGPA, affectsCreditsEarned, pointValues,
creditsEarned, gradedCreditsAttempted, gradePoints,
gradeReported, creditsRegisteredFor,
newCreditsEarned, newGradedCreditsAttempted, newGradePoints,
semesterGPA, overallGPA);
//cout statements follow
}
接下来是我定义函数的gpa.cpp文件(这个单个函数在一个单独的文件中,因为我必须使用完整的逐步细化提交它)
#include "gpa.h"
#include "vectorUtils.h"
using namespace std;
void computeGPA (/* University Info */
const std::vector<std::string>& gradeCodes,
const std::vector<bool>& affectsGPA,
const std::vector<bool>& affectsCreditsEarned,
const std::vector<double>& pointValues,
/* student history info */
int creditsEarned,
int gradedCreditsAttempted,
double gradePoints,
/* student semester grades */
const std::vector<std::string>& gradeReported,
const std::vector<int>& creditsRegisteredFor,
/* outputs */
int& updatedCreditsEarned,
int& updatedGradedCreditsAttempted,
double& updatedGradePoints,
double& semesterGPA,
double& overallGPA)
{
//Calculate a student's current and overall GPA
//*Calculate grade points;
//*Calculate GPA;
//**Calculate current GPA;
//*** if attempted credits is 0, GPA is 0.0
if (gradedCreditsAttempted == 0) semesterGPA = 0.0;
//*** else compute GPA as grade points earned/# of graded credits attempted
else semesterGPA = (gradePoints/gradedCreditsAttempted);
//**Calculate overall GPA;
}
最后这里是头文件。
#ifndef GPA_H
#define GPA_H
#include <string>
#include <vector>
void computeGPA (/* University Info */
const std::vector<std::string>& gradeCodes,
const std::vector<bool>& affectsGPA,
const std::vector<bool>& affectsCreditsEarned,
const std::vector<double>& pointValues,
/* student history info */
int creditsEarned,
int gradedCreditsAttempted,
double gradePoints,
/* student semester grades */
const std::vector<std::string>& gradeReported,
const std::vector<int>& creditsRegisteredFor,
/* outputs */
int& updatedCreditsEarned,
int& updatedGradedCreditsAttempted,
double& updatedGradePoints,
double& semesterGPA,
double& overallGPA);
#endif
对未定义引用问题的任何帮助表示赞赏。我不是要求我的函数或任何东西的完整代码,因为通过逐步创建实际函数是我的任务的一部分。我只是在努力解决这个错误。