如何使用C#控制台应用程序创建菜单驱动程序 [英] How do I create a menu driven program using C# console application
问题描述
如何创建菜单驱动的C#控制台应用程序,该应用程序将模拟和分析来自评估自助餐厅食物的学生群体的回复。每个学生将食物评定为从1(差)到10(例外)的整数值。有100名学生对食物进行评级。
该程序是一个模拟,因此您无法输入100个整数值,而是让计算机随机生成它您。因此,该计划的主要目的是:
1.生成100个整数并将其存储在一个数组中
2.显示以表格形式生成的数字
3.计算并显示评级的频率直方图
我尝试过:
我已完成菜单驱动..但生成数字和计算频率会导致我死亡
生成100个随机数:
1)设置一个数组(或其他集合)来保存值。
2)使用循环设置每个值。 />
3)在循环内部,使用Random类的实例生成随机值,并将其存储在您的集合中。
请注意Random实例应该在循环外声明,而不是在内部。
计算频率:
1)设置一个数组(或其他集合) )保持频率。由于您只有十个值(1 - 10),因此可以使用固定大小的数组。
2)将数组初始化为零。
3)循环遍历随机数集合中的每个元素,将每个不同的值计入频率数组。
但是......这是你的作业,所以我不给你任何代码!
引用:1。生成100个整数并将其存储在数组中为了对范围内的整数进行生成,
Random
类的文档会轻轻提供代码示例:< a href =https://msdn.microsoft.com/en-us/library/2dx6wyd4(v=vs.110).aspx> Random.Next方法(Int32,Int32)(系统) [< a href =https://msdn.microsoft.com/en-us/library/2dx6wyd4(v=vs.110).aspx\"target =_ blanktitle =New Window> ^ ]。
我假设您能够将生成的数字存储到数组中。
引用:2。以表格形式显示生成的数字这看起来并不是一项艰巨的任务。
引用:3。计算并显示评级的频率直方图您知道,特定评级的频率是其出现次数除以评级事件的总数。
因此,如果评级2
发生五次,然后其频率为5/100
。显示直方图,例如*
的行应该不那么困难。
how do I Create a menu driven C# Console application that would simulate and analyse responses from a group of students that rated the food in the cafeteria. Each student rated the food as an integer value from 1 (bad) to 10 (exceptional). There are 100 students that rated the food.
the program is however a simulation and therefore you can not enter the 100 integer values but rather let the computer generate it randomly for you. The main purpose of the program therefore would be to:
1. Generate 100 integer numbers and store it in an array
2. Display the generated numbers in a tabular form
3. Calculate and display a frequency histogram of ratings
What I have tried:
Ive done the menu driven..but generating numbers and calculating frequency kills me
Generating 100 random numbers:
1) Set up an array (or other collection) to hold the values.
2) Use a loop to set each value.
3) inside the loop, use an instance of the Random class to generate your random values, and store it in your collection.
Note that the Random instance should be declared outside the loop, not inside.
Calculating frequency:
1) Set up an array (or other collection) to hold the frequencies. Since you only have ten values (1 - 10) you can use a fixed size array.
2) Initialise the array to zeros.
3) Loop through each element in the random number collection, counting each different value into the frequency array.
But ... this is your homework, so I'll give you no code!
Quote:1. Generate 100 integer numbers and store it in an array
In order to geenrate an integer in a range, the documentation of the
Random
class gently provides a code sample: Random.Next Method (Int32, Int32) (System)[^].
I assume you are able to store the generated numbers into an array.
Quote:2. Display the generated numbers in a tabular form
This doesn't look a daunting task.
Quote:3. Calculate and display a frequency histogram of ratings
You know, the frequency of a particular rating is the count of its occurrences divided by the total number of ratings occurrences.
So, if the rating2
happens five times, then its frequncy is5/100
. Displaying the histograms, for instance as rows of*
shouldn't be that difficult.
这篇关于如何使用C#控制台应用程序创建菜单驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!