fork download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. void init();
  7.  
  8. struct Profile
  9. {
  10. float *score;
  11. string fname, lname, resp, scaleA, scaleB;
  12.  
  13. public:
  14. Profile()
  15. :score(new float[4])
  16. {
  17. fill(score, score + 4, 0.0);
  18. scaleA = "ESTJ";
  19. scaleB = "INFP";
  20. cin >> fname >> lname >> resp;
  21. }
  22.  
  23. void Assess(int);
  24. void Eval();
  25. ~Profile();
  26. };
  27.  
  28. int main()
  29. {
  30. init();
  31. int num, w;
  32. Profile* P;
  33. string::iterator k;
  34.  
  35. for(scanf("%d", &num) ; num-- ;)
  36. {
  37. P = new Profile;
  38. for( w = 1, k = P->resp.begin(); k != P->resp.end(); ++k, ++w)
  39. if (*k == 'A')
  40. P->Assess(w);
  41.  
  42. P->Eval();
  43. P->~Profile();
  44. }
  45.  
  46.  
  47. return 0;
  48. }
  49.  
  50. void init()
  51. {
  52. freopen("responses.txt","r",stdin);//redirects standard input
  53. freopen("types.txt","w+",stdout);//redirects standard output
  54. cout << "\t\t\tSUBJECT'S PERCENT 'A' RESPONSES PERSONALITY\n"
  55. << "\t\t\t_______________________________________________\n\n"
  56. << "|\t NAME\t\t | \tE/I\t | \tS/N\t | \tT/F\t | \tJ/P\t | \tTYPE\t |\n\n";
  57. }
  58.  
  59. void Profile::Assess(int k)
  60. {
  61. if ( (k-1) % 7 == 0 )
  62. ++score[0];
  63. else if ( (k+4) % 7 == 0 || (k+5) % 7 == 0 )
  64. ++score[1];
  65. else if ( (k+2) % 7 == 0 || (k+3) % 7 == 0 )
  66. ++score[2];
  67. else if ( k % 7 == 0 || (k + 1) % 7 == 0 )
  68. ++score[3];
  69. }
  70.  
  71. void Profile::Eval()
  72. {
  73. for (unsigned w = 0; w < scaleA.length(); ++w)
  74. {
  75. if (w < 1)
  76. {
  77. (int)score[w] < 5 ? scaleA[w] = scaleB[w] : (int)score[w] == 5 ? scaleA[w] = '-' : 0;
  78. score[w] *= 10;
  79. }
  80. else
  81. {
  82. (int)score[w] < 10 ? scaleA[w] = scaleB[w] : (int)score[w] == 10 ? scaleA[w] = '-' : 0;
  83. score[w] *= 5;
  84. }
  85.  
  86. }
  87. }
  88.  
  89. Profile::~Profile()
  90. {
  91. printf("|\t%s %s\t |", fname.c_str(), lname.c_str());
  92.  
  93. for (unsigned w = 0; w < scaleA.length(); ++w)
  94. printf("\t%.1lf\t |", score[w]);
  95. printf("\t%s\t |\n", scaleA.c_str() );
  96. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty