Hi JLBorges, and thank you for your help I will try this again , maybe I missed a step the first time, at this point I am willing to try anything.
Hi CodeWriter, Thank you again for your help.
Here are the codes my Instructor and I worked on.
it is kinda long but I will put an <<<< ERROR MESSAGE <<< where my problem is
what I have already tried:
I have seen the responses about C++11 and have followed the instructions to the tee, and after I am still receiving the same error message stoi() not declared, also when I tried to switch to std::atoi I still g0t the same error message.
I have also already tried adding #include <stdlib.h> /* atoi */ and still I get the same error message.
I have read and tried to use stringstream ss
I have uninstalled Code::Blocks and installed DEV C++ from Orwell, from what I was told this version of DEV C++ supports C++11 and still same error message.
I also read somewhere to try adding -std=c++0x
I Also tried downloading Net beans with C++
I tried #include<string> and using std::stoi
I have already completed the class and my final grade was B ... I am doing this cause I need to know what I did wrong or where.
there was this project and another that Killed my final grade.
LOOK FOR <<<<<<<<<< ERROR CODE<<<<<<
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
#include <iostream>
#include <cstdlib>
#include <exception>
#include <string>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <iomanip>
using namespace std;
//the files used
ofstream outfile; // ERROR MESSAGE <<<<< ofstream incomplete does not name a type <<<<<<<<<
ifstream infile;
class Question // super class
{
public:
string getQuestion()//gets the question
{
return question;
}
int getValue() //gets the point value of the question
{
return value;
}
virtual void setQuestion(string answer, int value)
{
}
virtual void printOptions()
{
}
virtual string getAnswer()
{
return answer;
}
private:
string question, answer;
int value;
};
class QuestionTF : public Question// class for true and false questions
{
public:
void setQuestion(string theQuestion, int pointValue)
{
string theAnswer;
question = theQuestion;
points = pointValue;
options = "true/false";
//get the answer from the file
getline(infile, theAnswer);
answer = theAnswer;
}
void printOptions()//prints the options for that question
{
cout << question << endl;
cout << answer << endl;
}
string getAnswer()//outputs the answer for that question
{
return answer;
}
private:
string question;
string answer;
int points;
string options;
};
class QuestionMC : public Question//class for multiple choice
{
public:
void setQuestion(string theQuestion, int pointValue)
{
string line;
//get the number of choices from the file
getline(infile, line);
numberOfOptions = stoi(line); // <<<<<<<<<ERROR MESSAGE <<<<< stoi not declared <<<<
question = theQuestion;
value = pointValue;
//get the individual choice lines and load to options array
for (int count = 0; count<numberOfOptions; count++){
getline(infile, line);
options[count] = line;
}
//get the answer from the file and load into answer
getline(infile, line);
answer = line;
}
void printOptions()// prints the questions, options, and answer
{
char first = 'A';
cout << question << endl;
for (int count = 0; count<numberOfOptions; count++){
cout << first++ << ". " << options[count] << endl;
}
cout << "Answer: " << answer << endl;
}
string getAnswer()// prints the answer
{
return answer;
}
private:
int value, numberOfOptions;
string question, answer;
string options[6];
};
int main() {
Question *myQuestions[10];
string questiontype, questiontxt;
string answertxt, optiontxt;
int numquestions, questionvalue;
// this is the test bank test file
outfile.open("testbank.txt");
if (outfile.is_open())
{
outfile << "3\n";
outfile << "TF 5\n";
outfile << "There exists birds that cannot fly?\n";
outfile << "true\n";
outfile << "MC 10\n";
outfile << "Who was the President of the USA in 1991?\n";
outfile << "6\n";
outfile << "Richard Nixon\n";
outfile << "Gerald Ford\n";
outfile << "Jimmy Carter\n";
outfile << "Ronald Reagan\n";
outfile << "George Bush Sr.\n";
outfile << "Bill Clinton\n";
outfile << "E\n";
outfile << "TF 10\n";
outfile << "The city of Boston hosted the 2004 Summer Olympics?\n";
outfile << "false\n";
outfile.close();
}
else cout << "Unable to open file";
//opening the testbank file and processing as a question of each type
infile.open("testbank.txt");
string line, theQuestion, theAnswer;
if (infile.is_open())
{
//get the number of questions from the first line in the file
getline(infile, line);
numquestions = stoi(line); // <<<<<<<<<< Error MESSAGE <<< stoi not declared <<<<<<
for (int count = 0; count<numquestions; count++){
getline(infile, line);
//get the next line with the question type and the value of the question
int npos = line.size();
int prev_pos = 0;
int pos = 0;
while (line[pos] != ' ')
pos++;
questiontype = line.substr(prev_pos, pos - prev_pos);
prev_pos = ++pos;
questionvalue = stoi(line.substr(prev_pos, npos - prev_pos)); // Last word <<<< ERROR MESSAGE stoi not declared
//process a true/false question
if (questiontype == "TF")
{
myQuestions[count] = new QuestionTF;
getline(infile, theQuestion);
myQuestions[count]->setQuestion(theQuestion, questionvalue);
}
//process a multiple choice question
if (questiontype == "MC")
{
myQuestions[count] = new QuestionMC;
getline(infile, theQuestion);
myQuestions[count]->setQuestion(theQuestion, questionvalue);
}
}
}
//print out the questions that have been processed
for (int count = 0; count<numquestions; count++)
{
myQuestions[count]->printOptions();
cout << endl;
}
getchar();
return 0;
}
|