Mandrew

Mental Mather - problem.cpp

Aug 27th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. // operations to use
  2. #define OPNUM 2
  3.  
  4. char GiveOperation(int);
  5.  
  6. class ProblemSet
  7. {
  8.     private:
  9.         int Size;
  10.     public:
  11.         ProblemSet(int n) : Size(n)
  12.         {
  13.            
  14.         }
  15. };
  16.  
  17. class Problem
  18. {
  19.     private:
  20.         int Term1;
  21.         int Term2;
  22.         char Operator;
  23.     public:
  24.         Problem(int x, int y) : Term1(x), Term2(y)
  25.         {
  26.             Operator = GiveOperation(OPNUM);
  27.         }
  28.  
  29.         int AskTheProblem()
  30.         {
  31.             //Timer.start();
  32.             int UserAnswer;
  33.             printf("%d %c %d = ",Term1,Operator,Term2);
  34.             scanf("%d",&UserAnswer);
  35.             return UserAnswer;
  36.             //Timer.end();
  37.         }
  38.        
  39.         int Calculate()
  40.         {
  41.             switch (Operator)
  42.             {
  43.                 case '+':
  44.                 default:
  45.                     return Term1 + Term2;
  46.                 case '-':
  47.                     return Term1 - Term2;
  48.                 case '*':
  49.                     return Term1 * Term2;
  50.                 case '/':
  51.                     return Term1 / Term2;
  52.             }
  53.         }
  54. };
  55.  
  56. /*
  57. class Timer
  58. {
  59.     private:
  60.         float Time;
  61.     public:
  62.         Timer()
  63.         {
  64.         }
  65.  
  66. };
  67. */
  68.  
  69. char GiveOperation(int OpsToUse)
  70. {
  71.     int OpGranter = rand() % OpsToUse;
  72.     switch (OpGranter)
  73.     {
  74.         case 0:
  75.         default:
  76.             return '+';
  77.             break;
  78.         case 1:
  79.             return '-';
  80.             break;
  81.         case 2:
  82.             return '*';
  83.             break;
  84.         case 3:
  85.             return '/';
  86.             break;
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment