Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program needs to read from a file named MB.txt and output to the console, using

ID: 3551540 • Letter: P

Question

Program needs to read from a file named MB.txt and output to the console, using simple arrays.


Write a program MyerBriggs to score users' responses to the classic

Myers-Briggs personality test. Assume that the test has 70 questions that determine a person's personality in four

dimensions. Each question has two answer choices that we'll call the "A" and "B" answers. Questions are organized

into 10 groups of seven questions, with the following repeating pattern in each group:

? The first question in each group (questions 1, 8, 15, 22, etc.) tells whether the person is introverted or

extroverted.

? The next two questions (questions 2 and 3, 9 and 10, 16 and 17, 23 and 24, etc.) test whether the person is

guided by his or her senses or intuition.

? The next two questions (questions 4 and 5, 11 and 12, 18 and 19, 25 and 26, etc.) test whether the person

focuses on thinking or feeling.

? The final two questions in each group (questions 6 and 7, 13 and 14, 20 and 21, 27 and 28, etc.) test whether

the person prefers to judge or be guided by perception.

In other words, if we consider introversion/extroversion (I/E) to be dimension 1, sensing/intuition (S/N) to be

dimension 2, thinking/feeling (T/F) to be dimension 3, and judging/perception (J/P) to be dimension 4, the map of

questions to their respective dimensions would be:

1 2 3 4 5 6 7

Q: 1234567890123456789012345678901234567890123456789012345678901234567890

D: 1223344122334412233441223344122334412233441223344122334412233441223344

If less than 50% of a person's responses are B for a given personality dimension, the person's type for that dimension

should be the first if its two choices. If the person has 50% or more B responses, the person's type for that dimension

is the second choice. Your program should output each person's name, the number of A and B responses for each

dimension, the percentage of Bs in each dimension, and the overall personality type.

The file, MB.txt, contains the following data:

Snoopy

AABAAAAAAAAAAAABAAAABAAAAAAAAAAAABAAAABAAABABABAABAAAAAABAAAAAABAAAAAA

Charlie Brown

AAABBAABBABBBAABAAAABABABBAAAABABBBBABBBABAABABAABABAAABABAAABBAABABBB

Linus

AABBAABBBBBABAABBBBABABBABAAAABABBABABBAABAABABAABABBBBBBBAAAAAAABBBBB

Lucy

BABBAAABBBBAAABAAAAAABBBAABAAAAABBBAAABAAAAABABAAAABAABBBBAAABBAABABBB

Peppermint Patty

BBBBAAABBBBABBBAAAAAABBBAABAAAAABBBAAABAAAAABABAAAABAABBBBAAABBAABABBB

The output should be:

Snoopy:

6A-4B 17A-3B 18A-2B 18A-2B

[40%, 15%, 10%, 10%] = ISTJ

Charlie Brown:

7A-3B 11A-9B 9A-11B 10A-10B

[30%, 45%, 55%, 50%] = ISFP

Linus:

6A-4B 7A-13B 8A-12B 11A-9B

[40%, 65%, 60%, 45%] = INFJ

Lucy:

5A-5B 11A-9B 14A-6B 11A-9B

[50%, 45%, 30%, 45%] = ESTJ

Peppermint Patty:

5A-5B 10A-10B 14A-6B 9A-11B

[50%, 50%, 30%, 55%] = ENTP

Explanation / Answer

The code works perfect. CHeers!!


#include<iostream>

#include <fstream>

#include <string>


using namespace std;

int main()

{

ifstream input("MB.txt"); //your given input file

string line;

while( getline( input, line ) )

{

cout<<line<<endl;

getline( input, line );

int len= 70; // has to be 70, 10 groups of 7 questions

  

//starts from index 0, so 0-6 is first group of questions, 7-13

//I/E => 0,7,14...

//S/N => 1,2,8,9

//T/F => 3,4

//J/P=>5,6

int j=0;

int c1,c2,c3,c4;

c1=c2=c3=c4=0;

for(int i=1;i<=10;i++)

{

if(line[j]=='B') c1++;

if(line[j+1]=='B') c2++;

if(line[j+2]=='B') c2++;

if(line[j+3]=='B') c3++;

if(line[j+4]=='B') c3++;

if(line[j+5]=='B') c4++;

if(line[j+6]=='B') c4++;

j=j+7;   

}

float p1=((float)c1)/10*100;

float p2=((float)c2)/20*100;

float p3=((float)c3)/20*100;

float p4=((float)c4)/20*100;

char ch1,ch2,ch3,ch4;

if(p1<50) ch1='I';

else ch1='E';

if(p2<50) ch2='S';

else ch2='N';

if(p3<50) ch3='T';

else ch3='F';

if(p4<50) ch4='J';

else ch4='P';

cout<<10-c1<<"A"<<"-"<<c1<<"B"<<" ";

cout<<20-c2<<"A"<<"-"<<c2<<"B"<<" ";

cout<<20-c3<<"A"<<"-"<<c3<<"B"<<" ";

cout<<20-c4<<"A"<<"-"<<c4<<"B"<<endl;

cout<<"[ "<<p1<<"%, "<<p2<<"%, "<<p3<<"%, "<<p4<<"%] = "<<ch1<<ch2<<ch3<<ch4<<endl;

}

  

  

return 0;

}