Difficult Program using Functions

As part of a project in psychology, 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


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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

void personalityType (int, int, int,int);

int main()

{
  ifstream infile("responses.txt");

     for ( int i = 0; i < 3; i++)
		
   {
      cin >> infile ("responses.txt");

	 }


	system("pause");
	return 0;
}

void personalityType (int, int, int,int);
What website did you get this problem from? Seems interesting enough, but I think you missed the output part of the problem. What does the output look like?

Also in your code, line 18 doesn't look right, you should fix that. (HINT: Where are you getting input from?)
It's not from a website. It's a college C++ class lol I'm not a great programmer but I need to take the class to move onto higher levels for my network and security analyst degree.

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



If you want to use cin/cout have this at the beginning of your code:

1
2
3
4
5
#include <cstdio>

//int main()
freopen("responses.txt","r",stdin);//redirects standard input
freopen("types.txt","w",stdout);//redirects standard output 


No need for ifstream because everytime you use cin, you will read from responses.txt and everytime you use cout, you will write to types.txt

gl
Last edited on
Went ahead and did it, was fun

http://ideone.com/3n2bMT

E: one thing I don't understand in the output you show is the values after the decimal. I see no way that there could be a .9 or .4 unless you have more than 2 options to rate them on.
Last edited on
I don't know how she got those numbers. I sometimes wonder if she makes them up!
Topic archived. No new replies allowed.