Hi Guys. I am new to this. I have to read data from a.txt file using C++.
--------------------------------------------------------------------
The text file says:
The cout statement comes from what library?:a:abcdabdcbadcbabdcbabdabcabaabacbadba(fi rst line)
What was the output of this statement?:c:bdcbabdabcabaabacbadbaccccccccccbadcb a (second line)
--------------------------------------------------------------------
The output should be :
Question: The cout statement comes from what library?
Answer: a
Responses: 36
A: 12 (33%)
B: 12 (33%)
C: 6 (16.6%)
D: 6 (16.6%)
Question: What was the output of this statement?
Answer: c
Responses: 38
A: 10 (26.3%)
B: 10 (26.3%)
C: 14 (38.8%)
D: 4 (11.1%)
------------------------------------------------------------------------------------
This is the code I have done so far: ( As you can see I have not done it all, but I am stuck because I am not sure what to put in the function parts, which is my my while loops are blank now. And I am not sure IF WHAT I DID is even right or not. SO any help will be greatly appreciated. Please help if you can. Thanks)
-----------------------------------------------------------------------------------
Code:
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <iomanip>
using namespace std;
string GetQuestion(ifstream &in);
char GetAnswer(ifstream &in);
string GetResponse(ifstream &in);
int main()
{
cout << " Sandeep Pulugurtha's Class Results " << endl;
cout << " Mr. Lupoli CMSC 201 PROJECT #2 " << endl;
cout << " December 1 , 2007 " << endl;
string question;
char answer;
string response;
ifstream infile;
inFile.open("ExamResponses.txt", ios_base::in);
if (!inFile) {
cout << "Unable to open file";
exit(1); // terminate with error
}
while(!(infile.eof()))
{
question = GetQuestion(infile);
cout << question << endl;
}
while(!(infile.eof()))
{
answer = GetAnswer(infile);
cout << answer << endl;
}
while(!(infile.eof()))
{
response = GetResponse(infile);
cout << response << endl;
}
infile.close();
}
string GetQuestion(ifstream &in)
{
string question;
while(!(in.eof()))
{
getline(in, question, ‘:’)
}
}
char GetAnswer(ifstream &in)
{
char answer;
while(!(in.eof()))
{
getline(in, answer, ‘:’)
}
}
string GetResponse(ifstream &in)
{
string response;
while(!(in.eof()))
{
getline(in, response, ‘:’)
}
}
return 0;
}