Hello paulpaul,
For the compiler problem, I think I still need to use ".c.str()". |
he ".c_str()" is only needed pre "C++11", but it will work.
In line 44, the type is given in the problem.txt. |
, so I will ask this way. Where did you get the value for "type" from? Yes it is in the "problems.txt" file, but you do not read this file in the "grade" function. And it is available in the "problems" array, but you are not using this array. So, where does "type" get its value from.
If
int Problem::grade(std::string student_answer)
was provided to you then you have to realize this is only a starting point and needs more to make the function work. This is my solution to the "grade" function:
1 2 3 4 5 6 7
|
int Student::grade(Problem (&problems)[50], std::string student_answer, int index)
{
int marks;
std::string standard_answer = problems[index].GetStandardAnswer();
std::string type = problems[index].GetType();
if (type == "M")
|
I should back up and start with the
void Student::calculateScore(Problem (&p)[50], Student (&students)[50], int numProblems)
function. I had to pass the two arrays "problems" and "students" to "calculateScore" because both arrays are needed to calculate the score for each answer from the "students" array. From the "calculateScore" function you have to pass the "problems" array to the grade function. Notice the code
Student (&students)[50]
. This is passing by reference. This is not needed,
Student students[]
will work fine. I did the by reference for my use during testing. It allows me to see the entire array not just one element.
In the section for type "S" the third for loop along with the find is wrong. In the condition
g < num_keywords
You are trying to access "num_keyWords" directly from the class and you can not do it this way I had to add the function
int GetNumKeyWords() { return num_keywords; }
to the class and write the for loop as
for (int g = 0; g < problems[index].GetNumKeyWords(); g++)
to get the correct number on the rhs of <.
In the find part you will need to access the "problems" array then the "keywords" array to each possible answer.
You deleted the message I was working from, but as I remember it I had to change
if (h != string::npos)
to
if (h == string::npos)
to get the if statement to work the way you have it written. Otherwise you would have to switch the lines after "if" and "else".
Still have not reached the "setRank" function yet because I got stuck on the "sort" function last night.
If your teacher gave you this then I would say that it is OK to use, but I would otherwise caution against putting code into the std namespace unless you know what you are doing. IMHO.
1 2 3 4 5 6 7 8 9
|
namespace std
{
template <class A>
void sort(A, A)
{}
template <class A, class T>
void sort(A, A, T)
{}
}
|
Hope that helps,
Andy