Don't like ads? PRO users don't see any ads ;-)
Guest

What I managed

By: a guest on Aug 8th, 2012  |  syntax: C++  |  size: 3.59 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //CONTESTANT.H
  2.  
  3. #ifndef CONTESTANT_H
  4. #define CONTESTANT_H
  5. #endif
  6. #include <iostream>
  7. #include <string>
  8. #include <math.h>
  9. #include<time.h>
  10. #include<vector>
  11. #define CONT 12
  12. #define EP 10
  13.  
  14. using namespace std;
  15. class Contestant
  16. {
  17. private:
  18.         string name;
  19.         int charisma;
  20.         int personality;
  21.         int passion;
  22.         int techSkill;
  23.         int stam;
  24.         int randomStat;
  25.         int total;
  26.         bool competing;
  27. public:
  28.         Contestant();
  29.         void prompt();
  30.         void randomGen();
  31.         int getStat();
  32. };
  33.  
  34. //CONTESTANT.CPP
  35. #include "contestant.h"
  36. //synopsis - Contestant(), constructor for Contestant class.
  37. Contestant::Contestant()
  38. {
  39.         name = "NUL";
  40.         charisma = 0;
  41.         personality = 0;
  42.         passion = 0;
  43.         techSkill = 0;
  44.         stam = 0;
  45.         randomStat = 0;
  46.         total = 0;
  47.         competing = NULL;
  48.  
  49. }
  50.  
  51. void Contestant::prompt()
  52. {
  53.         //None of this checks for errors
  54.         cout << "Please insert contestant's name\n";
  55.         cin >> name;
  56.         cout << "Please insert contestant's charisma (number between 0 - 10, where 0 is the lowest and 10 the highest)\n";
  57.         cin >> charisma;
  58.         total = total + charisma;
  59.         cout << "Please insert contestant's personality (integer number between 0 - 10, where 0 is the lowest and 10 the highest)\n";
  60.         cin >> personality;
  61.         total = total + personality;
  62.         cout << "Please insert contestant's passion (number between 0 - 10, where 0 is the lowest and 10 the highest)\n";
  63.         cin >> passion;
  64.         total = total + passion;
  65.         cout << "Please insert contestant's technical skill (number between 0 - 10, where 0 is the lowest and 10 the highest)\n";
  66.         cin >> techSkill;
  67.         total = total + techSkill;
  68.         cout << "Please insert contestant's stamina (number between 0 - 10, where 0 is the lowest and 10 the highest)\n";
  69.         cin >> stam;
  70.         total = total + stam;
  71.         randomGen();
  72.         total = total + randomStat;
  73.  
  74. }
  75.  
  76. void Contestant::randomGen()
  77. {
  78.         srand(time(NULL));
  79.         randomStat = rand()%10;
  80. }
  81.  
  82. int Contestant::getStat()
  83. {
  84.         return total;
  85. }
  86. //RESULT.H
  87. #include "Contestant.h"
  88. #ifndef RESULT_H
  89. #define RESULT_H
  90. #endif
  91.  
  92. using namespace std;
  93. class Result
  94. {
  95. private:
  96.         vector<vector <int>> judgeScore; // A vector of a vector 2D array basically
  97.         vector<vector <int>> audienceVote;
  98.         vector<vector <int>> luck; //Random factor
  99.         vector<vector <int>> total;
  100.         vector<Contestant> contestList;
  101. public:
  102.         Result();
  103.         void display();
  104.         void calculateScore();
  105.         void genLuck();
  106.         void getContestants();
  107. };
  108. //RESULT.CPP
  109. #include "result.h"
  110. //synopsis - Result(), constructor for Result class.
  111. Result::Result()
  112. {
  113.         judgeScore.resize(EP);//10 episodes
  114.         for(int i = 0; i < EP; i++)
  115.                 {
  116.                         judgeScore[i].resize(CONT);
  117.                 }
  118.  
  119.         audienceVote.resize(EP);//10 episodes
  120.         for(int i = 0; i < EP; i++)
  121.                 {
  122.                         audienceVote[i].resize(CONT);
  123.                 }
  124.  
  125.         luck.resize(EP);//10 episodes
  126.         for(int i = 0; i < EP; i++)
  127.                 {
  128.                         luck[i].resize(CONT);
  129.                 }
  130.  
  131.         contestList.resize(CONT);
  132.        
  133.  
  134.  
  135. }
  136.  
  137. void Result::getContestants()
  138. {
  139.         for(int i = 0; i < CONT; i++)
  140.                 {
  141.                         cout << "Please enter contestant number ";
  142.                         cout << i + 1;
  143.                         cout << "\n";
  144.                         contestList[i].prompt();
  145.                 }
  146.  
  147. }
  148.  
  149.  
  150. void Result::calculateScore()
  151. {
  152.         for(int j = 0; j < EP; j++)
  153.                 {
  154.                         for(int i = 0; i < CONT; i++)
  155.                                         {
  156.                                                 ((contestList[i].getStat()) + luck[j][i])/2 = judgeScore[j][i] ; //intentional cutting of integer to increase random aspect
  157.  
  158.                                         }
  159.                 }
  160.        
  161. }
  162. //MAIN.CPP
  163. //Always 12 contestants, always 10 episodes.
  164. #include "Result.h"
  165. using namespace std;
  166.  
  167. int main()
  168. {
  169.         Result theShow;
  170.         cout << "Welcome to the XFactor. 12 contestants compete.\n Only one person may win.\n Over ten episodes.\nThe judges and our studio audience determines who wins\nEnjoy the show!";
  171.         theShow.getContestants();
  172.  
  173. }