Cześć, piszę quiz w obiektowym C++ i trapią mnie dwa błędy (linie zaznaczone w kodzie), główkuję i nie mam pomysłu, co może działać źle. Pomożecie? Pliki załączam poniżej. Błędy występują w pliku Table_Of_Contents.cpp.
#include <iostream>
#include "Table_Of_Contents.h"
using namespace std;
int main()
{
Question itself[5]; // Class's array.
int sum = 0;
for (int i = 0; i <= 4; i++)
{
itself[i].numberQ = i + 1;
itself[i].load();
itself[i].ask_question();
itself[i].check_answer();
sum += itself[i].points;
}
cout << "This is already the end! You scored " << sum << " points.";
return 0;
}
// Table_Of_Contents.cpp
#include <iostream>
#include <fstream>
#include <stdlib.h> // The .h ending tells us that this library consists of useful functions and classes,
#include "Table_Of_Contents.h" // This line includes Table_Of_Contents.h file and expands stuff declared in it.
using namespace std;
void Question::load() // This sends compiler to the right class. It needs a guide, always.
{
fstream file;
file.open("quiz.txt",ios::in);
if(file.good() == false)
{
cout << "I am unable to read this file.";
exit(0);
}
int line_as_int = (numberQ - 1) * 6 + 1; // This represent number of a line.
int current_number = 1; // That is number of a current line.
string line_as_string; // A variable representing the line itself.
// Loop below is useful for expanding number of questions.
while(getline(file,line_as_string)) // This loop reads needed lines from the file.
{
if(current_number == line_as_int) content = line_as_string;
if(current_number == line_as_int + 1) a = line_as_string;
if(current_number == line_as_int + 2) b = line_as_string;
if(current_number == line_as_int + 3) c = line_as_string;
if(current_number == line_as_int + 4) d = line_as_string;
if(current_number == line_as_int + 5) rightAnswer = line_as_string;
current_number++;
}
void Question::ask_question() // Error: qualified-id in declaration before '(' token.
{
cout << content << endl;
cout << a << endl;
cout << b << endl;
cout << c << endl;
cout << d << endl;
cout << endl;
cout << "Your answer is... "; cin >> answer;
}
void Question::check_answer() // Error: qualified-id in declaration before '(' token.
{
if (answer == right_answer)
{
points = 1;
}
else
{
points = 0;
}
}
file.close();
} // Error: expected '}' at end of input.
// Table_Of_Contens.h
#include <iostream>
using namespace std;
class Question
{
public:
string content;
string a, b, c, d;
int numberQ;
string rightAnswer;
string answer;
int points;
// int points = 0;
// Such operation is invalid when it comes to the .h file, it pops up an error.
void load(); // This method will load information such as content and answers from the text file.
// This function's body is located in .cpp file.
void ask_question();
void check_answer();
};
// This file is just a table of stuff in .cpp file, but its existence makes it easier to look at the application.
// Here there are only headers.