Member data, member functions, private and public, accessors and mutators, OOP, classes and objects.
Here is my data file trivia.txt consisting of 10 trivia questions:
jacobson[weblab]:~$ wc trivia.txt <------ Do the wc word count command 60 218 1210 trivia.txt -- --- ---- It has 60 lines, 218 words and 1,210 characters (bytes). There are 6 lines for each question, so it does have 10 questions. Example question from trivia.txt file... What does the acronym VET stand for in VET SAT AUC TVV SO YMDC? Viral Effects Treated <--- choice #1 Vensim Email Target <--- choice #2 Very Effective Thinking <--- choice #3 Various Effects Tuning <--- choice #4 3 <---- What is number of correct answer? 3 for this one. Note: The first line is the question. The 2nd line to the 5th line of a group is the four choices. The 6th and last line of a group is the number of the correct choice and answer to the question.
jacobson[weblab]:~$ ./a.out QUESTION: What is the name of the character that Kevin Costner plays in Dances With Wolves? 1. Stands With A Fist 2. Smiles A Lot 3. John Dunbar 4. Joseph Snitker The correct answer is: 3
int main () { ifstream qFile; // qFile is the file handle... q as in question qFile.open("trivia.txt"); // ----- - - string theString; for (int j = 0; j <= 5; j++) { getline(qFile, theString); if (j == 0) cout << "QUESTION: " << theString; else if (j < 5) cout << setw(5) << j << ". " << theString; else cout << "The correct answer is: " << theString << endl; cout << endl; } return 0; }