Input data from file/write data to file

Any help with this would be appreciated. I can't figure much of it out. The parts I have are written in a comment.


Ben has been administering a MBTI personality test. Now he has all the responses, but the task of scoring and compiling results seems daunting. He is hoping you can write a program to help him accomplish this task.
The personality test* is a series of 70 questions for which the available responses are ‘A’ and ‘B’. Based upon the answers to the 70 questions, a personality profile is determined, categorizing the degree to which the responses place the person on four scales:
Extrovert vs. Introvert (E/I)
Sensation vs. iNtuition (S/N)
Thinking vs. Feeling (T/F)
Judging vs. Perceiving (J/P).

Each of the 70 questions relates to one of the four scales, with an ‘A’ response indicating the first of the corresponding pair (E, S, T, or J) and a ‘B’ indicating the second (I, N, F, or P). For instance, an ‘A’ response on the question:
At a party do you:
A. Interact with many, including strangers
B. Interact with a few, known to you

indicates an Extrovert rather than an Introvert; just the opposite for a ‘B’.

For this test, each question is designed to influence one of the four scales as follows:
questions 1, 8, 15, 22, 29 … are used to determine E/I,
questions 2, 9, 16, 23, 30 … and 3, 10, 17, 24, 31 … to determine S/N,
questions 4, 11, 18, 25, 32 … and 5, 12, 19, 26, 33 … to determine T/F, and
questions 6, 13, 20, 27, 34 … and 7, 14, 21, 28, 35 … to determine J/P.
Notice these come in sequences of “every 7th” question.


The goal of the test is to determine which end of each of the four scales a person leans, and to thus classify him/her based on those leanings (e.g., as ENFJ, INTJ, etc.). Since Ben would also like an indication of how strongly the test taker fell into each of the four, the program should print the percentage of ‘A’ responses for that scale.

Input for this program should come from a file responses.txt. The first line of the file will contain a single integer, n, indicating the number of test results to follow. Each of the following n lines will contain the first name of the test taker, a single blank, his/her last name, a single blank, then the 70 responses he/she gave on the test. Although the test instructions indicate that the results are most valid when all questions are answered, sometimes respondents leave questions blank. In that case, a dash appears at the corresponding place in the list of responses.

Output for the program should be written to the file types.txt. It should include a well-formatted report listing, for each test taker, his/her name, the percentage of ‘A’ responses in each scale, and the resulting personality type. A tie within a scale should result in a dash (‘-‘) for that part of the personality type.

For example, if the contents of responses.txt is
3
Mickey Mouse AABABBBBAAABBBABBBBAAAAABBABBAABB-BBAAABBABBABBBBABABBBABABBABBBAAA-BA
Minnie Mouse BAAABABABBAAABBBABABA-BBAAAABBABABBABBABABBBABABABBBABBBABAAABABABABB-
Donald Duck A-BBAAAB-BBAABBBABAABBBABABABAB-BABABABBBBABAAABABABBABABBBAAAABABBBBA

Then the contents of types.txt should be something like

SUBJECT’S PERCENT ‘A’ RESPONSES PERSONALITY
Name E/I S/N T/F J/P TYPE

Mickey Mouse 40.0 70.0 26.3 31.6 ISFP
Minnie Mouse 33.3 35.0 65.0 42.1 INTP
Donald Duck 30.0 38.9 47.4 55.0 INFJ
Last edited on
Is this a million dollar game? The best coder gets it?
I'm starting to feel that way! It has me completely confused. Any help would be great. This is what I have so far, and it isn't much.

// Project 2, Erin McDermott, purpose is to take in information from a file about various students
// who took an introvert/extrovert survey and import results to the program and output a file with percentage of responses
// for each type.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main()

{
ifstream infile("responses.txt");

fstream outfile("types.txt");


cout <<"SUBJECTS" << " " << "PERCENT A RESPONSES" << " " << "PERSONALITY" << endl;
cout << " "<< "NAME" << " " << "E/I" << " " << "S/N" << " " << "T/F" << " " << "J/P" << " " << "TYPE" << endl;

for ( int a = 3; a < 3; a = a + 7 )

{
getline(infile,responses.txt);

cout <<

}

outfile.close("types.txt");
system("pause");
return 0;
}
Topic archived. No new replies allowed.