subjects.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. /**
  8. * Description of subjects
  9. *
  10. * @author gregory
  11. */
  12. class subjects {
  13. public $state = "error";
  14. private $debug = false;
  15. private $major;
  16. private $minor;
  17. private $returnQuestionData = [];
  18. /**
  19. * Setup new question engine
  20. *
  21. * @param integer $major Max subject limit or debug selection.
  22. * @param integer $minor Max sub subject limit or debug selection.
  23. * @param bool $test Enable debug mode.
  24. */
  25. public function __construct($major, $minor, $test = false) {
  26. // some minor protection for this class
  27. if (!is_numeric($major) || !is_numeric($minor)) {
  28. $this->state = "error, Incorrect init values.";
  29. return;
  30. }
  31. // set diagnostics flag or init values.
  32. if ($test) {
  33. $this->debug = true;
  34. $this->major = $major;
  35. $this->minor = $minor;
  36. } else {
  37. $this->major = mt_rand(0, $major);
  38. $this->minor = mt_rand(0, $this->subjectLimiter($this->major, $minor));
  39. }
  40. $this->state = "ready";
  41. //print_a(['thisMa'=>$this->major,'thisMi'=>$this->minor,'Ma'=>$major,'Mi'=>$minor,'limitMi'=> $this->subjectLimiter($major, $minor)]);
  42. }
  43. /**
  44. * Return question data for the template engine.
  45. *
  46. * @return string Question ready to be passed to the template engine.
  47. */
  48. public function getQuestion() {
  49. // return the error message if the engine is not ready
  50. if (!$this->state == "ready") {
  51. return $this->state;
  52. }
  53. // debug output
  54. if ($this->debug) {
  55. $this->returnQuestionData['DebugSubjects'] = [];
  56. $this->returnQuestionData['DebugSubjects']['majorSubject'] = $this->major;
  57. $this->returnQuestionData['DebugSubjects']['minorSubject'] = $this->minor;
  58. }
  59. $this->selectSubject();
  60. return $this->returnQuestionData;
  61. }
  62. private function selectSubject() {
  63. switch ($this->major) {
  64. case 0: // Math
  65. $this->selectMinorMath();
  66. break;
  67. case 1: // English
  68. $this->selectMinorEnglish();
  69. break;
  70. case 2: // Science
  71. $this->selectMinorScience();
  72. break;
  73. case 3: // Geography
  74. $this->a(3);
  75. case 4: // History
  76. $this->a(4);
  77. case 5: // Art
  78. $this->a(5);
  79. case 6: // Technology
  80. $this->a(6);
  81. case 7: // language
  82. $this->a(7);
  83. case 8: // Health - Health and Physical Education
  84. $this->a(8);
  85. }
  86. }
  87. private function a($int)
  88. {
  89. print_a("Case $int not implemented yet!");
  90. }
  91. private function subjectLimiter($majorSubject,$requestedMinor) {
  92. $limits = [
  93. '0'=>2,// Math
  94. '1'=>0,// English
  95. '2'=>0,// Science
  96. '3'=>0,// Geography
  97. '4'=>0,// History
  98. '5'=>0,// Art
  99. '6'=>0,// Technology
  100. '7'=>0,// language
  101. '8'=>0,// Health
  102. ];
  103. if($limits[$majorSubject]<=$requestedMinor) {
  104. return $limits[$majorSubject];
  105. }else{
  106. return $requestedMinor;
  107. }
  108. }
  109. private function selectMinorMath() {
  110. switch ($this->minor) {
  111. case 0: // Numbers
  112. include 'questionGenerators/math/numbers.php';
  113. $mathNum = new numbers($this->debug);
  114. $this->returnQuestionData['numbers'] = $mathNum->getNumbers();
  115. break;
  116. case 1: // Numeracy
  117. include 'questionGenerators/math/numeracy.php';
  118. $mathNum = new numeracy($this->debug);
  119. $this->returnQuestionData['numeracy'] = $mathNum->getNumeracy();
  120. break;
  121. case 2: // Math_word_Problems
  122. include 'questionGenerators/math/math_word_problems.php';
  123. $mathNum = new math_word_problems($this->debug);
  124. $this->returnQuestionData['math_word_problems'] = $mathNum->getProblem();
  125. break;
  126. case 3: // money////////////////////////////////////////////////////
  127. include 'questionGenerators/math/numeracy.php';
  128. $mathNum = new numeracy($this->debug);
  129. $this->returnQuestionData['numeracy'] = $mathNum->getNumeracy();
  130. break;
  131. case 4: // time/////////////////////////////////////////////////////
  132. include 'questionGenerators/math/numeracy.php';
  133. $mathNum = new numeracy($this->debug);
  134. $this->returnQuestionData['numeracy'] = $mathNum->getNumeracy();
  135. break;
  136. case 5: // geometry////////////////////////////////////////////////
  137. include 'questionGenerators/math/numeracy.php';
  138. $mathNum = new numeracy($this->debug);
  139. $this->returnQuestionData['numeracy'] = $mathNum->getNumeracy();
  140. break;
  141. }
  142. }
  143. private function selectMinorEnglish() {
  144. switch ($this->minor) {
  145. case 0: // spelling
  146. include 'questionGenerators/english/spelling.php';
  147. $engSpell = new spelling($this->debug);
  148. $this->returnQuestionData['spelling'] = $engSpell->getSpellingWord("");
  149. break;
  150. case 1: // English
  151. //$this->selectMinorEnglish();
  152. break;
  153. }
  154. }
  155. private function selectMinorScience() {
  156. switch ($this->minor) {
  157. case 0: // Periodic Table of Elements
  158. include 'questionGenerators/science/elements.php';
  159. $scienceElements = new elements($this->debug);
  160. $this->returnQuestionData['elements'] = $scienceElements->getElements();
  161. break;
  162. case 1: // English
  163. //$this->selectMinorEnglish();
  164. break;
  165. }
  166. }
  167. }
  168. ////////////////////////
  169. // Worded questions
  170. ///////////////////////
  171. $geometry = [
  172. 'The perimeter of a square is 48 cm. What is the area of 2 such squares?',
  173. 'The area of 2 squares is 32 cm². What is the area of 3 such squares?',
  174. 'The perimeter of a rectangle is 24 cm. If the length is 9 cm, what is the width?',
  175. 'The perimeter of a rectangle is 52 cm. If the length is 15 cm, what is the width?',
  176. 'The width of a rectangle is 5 cm and the length is twice the width. What is the area of 10 such rectangles?',
  177. 'The area of square A is 49 cm². The area of square B is 144 cm². What is the difference in the perimeters of both squares?',
  178. 'The area of a square is 64 cm². What is the perimeter of 5 such squares?',
  179. 'The length of a rectangle is 11 cm. The perimeter of the rectangle is 34 cm. What is the width of the rectangle?',
  180. 'A square room has a side measurement of 16 m. Find the area of carpet needed to cover half the room?',
  181. 'An area of a square room is 400 m². A rectangle carpet measures 18 m by 10 m. Find the area of the room not covered in carpet?',
  182. 'A side of a square is 16 cm. What is the area of 5 similar squares?',
  183. 'The area of 2 similar squares is 128 cm². What is the side of each square?',
  184. 'The perimeter of a rectangle is 42 cm. The length is twice as long as the width. What is the width of the rectangle?',
  185. 'The perimeter of square A is 40 cm. The perimeter of square B is double of square A. What is 1 side of square B?',
  186. 'In a picture there are 4 squares drawn next to each other. How many right angles can you find?',
  187. 'The area of a room is 500m². A rug has an area of 5m². How many rugs are needed to cover half the floor of the room?',
  188. 'The perimeter of carpet A is 18m. The area of carpet B is twice the perimeter of carpet A. Find out what each side of carpet B measures?',
  189. 'The perimeter of a rectangle is 44 cm. The width of the rectangle is 9 cm. What is the length?',
  190. 'The perimeter of square A is 48 cm. The perimeter of square B is half of square A. What is the area of square B?',
  191. 'The combined height of 2 buildings is 390m. The height of building A is twice the height of building B. What are the heights of Building A? Building B?'
  192. ];
  193. $money = [
  194. 'Elliot has $27.10 and Silas has three times more than Elliot. How much money do they have altogether?',
  195. 'A coffee costs $2.50. Greg spent $17.50. How many coffees did he buy?',
  196. 'An adult bus ticket costs $6.50 and a child ticket costs $4. How much would 2 adults and 5 children cost to take the bus?',
  197. 'Wayne has $54. He bought 3 books that cost $16 each. How much money does he have left?',
  198. 'Sammy has $31, Ella has $18 more than Sammy and Molly has $20 more than Ella. How much does Molly have?',
  199. '1 meter of cloth costs $7. How much would six and a half meters of cloth cost?',
  200. '12 eggs cost $6. How much would 18 eggs cost?',
  201. 'Bekka had $250 and she spent a quarter of her money. How much does she have left?',
  202. 'Kelly has $170. Kate has twice the amount of Kelly. Kitty has $65 more than Kate. How much does Kitty have?',
  203. '1 meter of rope costs $21. Rope fence A uses 15 meters. Rope fence B uses four times more rope than fence A. How much did fence B cost to make?',
  204. 'Francis has $55 and his brother has 1 fifth less than him. How much do they have in total?',
  205. 'A sandwich costs $2.20. Silas has $18. How many sandwiches can he buy? How much change will he have left?',
  206. 'Louis had $96. He spent $24.50 on Tuesday and $39.70 on Wednesday. How much does he have left?',
  207. 'Farmer Ben had 320 pigs. 1 eighth of the pigs were eaten by wolves. He sold the remaining pigs at $90 each. How much money did he make?',
  208. '100 grams of flour costs 50 cents. How much does 3 kilos of flour cost?',
  209. 'A cupcake costs $1.50. Mei Lee made $60. How many cupcakes did she sell?',
  210. 'A toy costs $39.50. David and Dylan split the cost evenly between them. How much did each person pay for the toy?',
  211. '3 girls bought a pizza for $40. Girl A paid double than what Girl B paid. Girl C paid $10. How much did Girl A pay?',
  212. 'Greg bought a pie for $4.90, 2 milkshakes for $6 each and had $2.30 left. How much did he have at first?',
  213. 'Greg used 5000 cm of rope to make a fence. 1 meter of rope costs $3. How much did Greg spend on his rope fence?',
  214. 'A taxi meter starts at $4. Every 30 seconds, the meter jumps by 10 cents. How much would the meter show if a passenger sat in the taxi for 4 minutes?',
  215. '$210.60 has to shared equally between 3 sisters. How much would each sister get?',
  216. 'A meter of steel costs $7.40. Randy spent $44.40 How many meters did he buy?',
  217. 'Farmer Tim sold each 42 pigs at $70 each. He donated half the money to charity and kept the rest. How much did he keep?',
  218. ];
  219. $time = [
  220. 'Rowan’s swim class started at 10.55 am. It went for 2 hours and 10 minutes. What time did it end?',
  221. 'David starts work at 7.45 am. He works for 9 hours and 5 minutes. What time did he finish work?',
  222. 'David starts work at 8.50 am. He works for 9 hours and 30 minutes. What time did he finish work?',
  223. 'Hank takes 4 minutes to cycle to Coles. In total he cycled for 1 hour. How many trips to Coles did he make?',
  224. 'Finn earns $50 a week. How much does he earn in 1 year?',
  225. 'Adam started work at 8.45 am. He worked for nine and a half hours. What time did he finish work?',
  226. 'Rita takes 12 seconds to make a paper boat. How many boats can she make in 6 minutes?',
  227. 'Silas can do 3 twirls in every 20 seconds. How many twirls can he do in 5 minutes?',
  228. 'The restaurant opened at 12.45 pm. Elliot was 35 minutes late for work. What time did Elliot arrive at the restaurant?',
  229. 'Ruby went in for an operation at 4.25 pm. Her operation ended at 6.05 pm. How long was the operation?',
  230. ];