I was able to read everything into the program this way.
PHP Code
<?php
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
void read_questions(fstream &);
int main()
{
fstream fin;
string input;
fin.open("questions.txt", ios::in);
read_questions(fin);
return 0;
}
void read_questions(fstream &fin)
{
string input;
if (fin)
{
getline(fin, input);
while (fin)
{
cout << input << endl;
getline(fin, input);
}
fin.close();
}
}
It outputted like this:
Where does a C++ program begin its execution?
The first function in the file
The first function by alphabetic order of names
The function main( )
The function specified in the #DEFINE FirstFunction
How many values can be returned from a function by means of the "return" statement?
1
2
3
Lots and Lots
Which loop type is guaranteed to execute at least once?
for
while
do...while
all the above
Arrays are passed to functions by:
reference
value
either method
neither method
Global variables should be used...
in place of function parameters
only when absolutely needed
never
only during the full moon
When storing a floating point value to an integer type variable, the fractional part is:
rounded up
rounded down
branched
truncated
Which of the following is NOT a reason for writing functions?
modularity
reusability
easier testing and verification
reduced code size
Process returned 0 (0x0) execution time : 0.035 s
Press any key to continue.
Now I need to figure out how to "A" "B" "C" "D" Before each answer choice for every question. I'm thinking a basic for loop will work. Will update when I figure it out. =)
Update:
Changed EVERYTHING. UGH.
Couldn't get ABCD to show for each question using a while loop, so i switched to for loop. Here is what I did.
PHP Code
<?php
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
// Function Prototype
void read_questions();
int main()
{
// fstream fin; // File stream input
// string question; // To hold file input
// Opening the file in input mode
// fin.open("questions.txt", ios::in);
read_questions();
return 0;
}
void read_questions()
{
string question;
string choice1;
string choice2;
string choice3;
string choice4;
string space;
fstream fin;
fin.open("questions.txt");
for (int x = 0; x < 7; x++)
{
getline(fin, question);
getline(fin, choice1);
getline(fin, choice2);
getline(fin, choice3);
getline(fin, choice4);
getline(fin, space);
cout << question << endl;
cout << "A: " << choice1 << endl;
cout << "B: " << choice2 << endl;
cout << "C: " << choice3 << endl;
cout << "D: " << choice4 << endl;
cout << space << endl;
}
Here is the result thus far:
Where does a C++ program begin its execution?
A: The first function in the file
B: The first function by alphabetic order of names
C: The function main( )
D: The function specified in the #DEFINE FirstFunction
How many values can be returned from a function by means of the "return" statement?
A: 1
B: 2
C: 3
D: Lots and Lots
Which loop type is guaranteed to execute at least once?
A: for
B: while
C: do...while
D: all the above
Arrays are passed to functions by:
A: reference
B: value
C: either method
D: neither method
Global variables should be used...
A: in place of function parameters
B: only when absolutely needed
C: never
D: only during the full moon
When storing a floating point value to an integer type variable, the fractional part is:
A: rounded up
B: rounded down
C: branched
D: truncated
Which of the following is NOT a reason for writing functions?
A: modularity
B: reusability
C: easier testing and verification
D: reduced code size
Process returned 0 (0x0) execution time : 0.028 s
Press any key to continue.
UPDATE: Now I put it through an array to handle the ABCD and have it stored into a 2D array.
PHP Code
<?php
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
// Function Prototype
void read_questions();
int main()
{
read_questions();
return 0;
}
void read_questions()
{
string question;
string choice1;
string choice2;
string choice3;
string choice4;
string space;
fstream fin;
string input_arr[50][50];
fin.open("questions.txt");
for (int q = 0; q < 7; q++)
{
getline(fin, question);
getline(fin, choice1);
getline(fin, choice2);
getline(fin, choice3);
getline(fin, choice4);
getline(fin, space);
input_arr[q][0] = question;
input_arr[q][1] = "A. " + choice1;
input_arr[q][2] = "B. " + choice2;
input_arr[q][3] = "C. " + choice3;
input_arr[q][4] = "D. " + choice4;
input_arr[q][5] = space;
cout << input_arr[q][0] << endl;
cout << input_arr[q][1] << endl;
cout << input_arr[q][2] << endl;
cout << input_arr[q][3] << endl;
cout << input_arr[q][4] << endl;
cout << input_arr[q][5] << endl;
}
}