开发计算机辅助教学程序,教小学生学乘法。程序功能:
(1)程序开始时让用户选择“年级”为1或2。一年级使只用1位数乘法;二年级使用2位数乘法。
(2)用Random对象产生两个1位或2位正整数,然后输入以下问题,例如:How much is 6 times 7?然后学生输入答案,程序检查学生的答案。如果正确,则打印“Very good!”,然后提出另一个乘法问题。如果不正确,则打印“No,Please try again.”,然后让学生重复回答这个问题,直到答对。
(3)答对3道题后程序结束。
(4)使用一个单独方法产生每个新问题, 这个方法在程序开始时和每次用户答对时调用。
分析:
1.让用户输入1或2年级
2.进行3次循环(练习3次全对),循环体内有出题函数,判断输入答案是否正确
3.出题函数设计,三个参数,第一个是输入年级,2、3两个参数是根据年级来随机生成的乘数
C#代码实现:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { public static void GenerateTwoNum(int Level, out int miu1, out int miu2) { Random Rand = new Random(); int min = 0; int max = 0; if (Level == 1) { min = 1; max = 10; } else if (Level == 2) { min = 10; max = 100; } miu1 = Rand.Next(min, max); miu2 = Rand.Next(min, max); } static void Main(string[] args) { Console.WriteLine("请输入年级 1:一年级 2:二年级"); string str = Console.ReadLine(); int level = Convert.ToInt32(str); int Count = 0; while (Count < 3) { int miu1; int miu2; GenerateTwoNum(level, out miu1, out miu2); Console.WriteLine("How much is {0} times {1} ?", miu1, miu2); while (Convert.ToInt32(Console.ReadLine()) != miu1 * miu2) { Console.WriteLine("No,Please try again"); } Console.WriteLine("Very good!"); Count++; } } } } |
测试结果: