有人可以告诉我如何编写这个程序 [英] Can someone show me how to write this program

查看:90
本文介绍了有人可以告诉我如何编写这个程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用类似下面的输入文件,编写程序以确定记录的最高浓度和光化学氧化剂浓度超过标准的天数;显示天数和百分比(基于每月的天数)。使用至少两个程序员定义的函数。







示例输入文件:



80 83 79 180 190 200 220 220 200 200 198 225 199 183 160 119



162 180 122 121 121 119 80 83 79 119 121 121 122 119



执行:





数量根据输入文件确定当月的天数。输入文件的大小可能因月份而异。



一旦填充了数组,就无法更改数组的内容。



至少一个函数必须有一个数组作为参数。

Using an input file similar to the one below, write a program to determine the highest concentration recorded and the number of days the photochemical oxidant concentration exceeded the standard; display number of days and percentage (based on the number of days per month). Use at least two programmer defined functions.



Sample Input file:

80 83 79 180 190 200 220 220 200 200 198 225 199 183 160 119

162 180 122 121 121 119 80 83 79 119 121 121 122 119

Implementation:


The number of days in the month are determined from input file. The input file can vary in size depending on the month.

Once array is populated, the contents of the array can not be changed.

At least one function must have an array as a parameter.

推荐答案

我们不做你的作业:它是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是就像你想象的那样困难!

(经OriginalGriff许可使用)
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
(Used with permission of OriginalGriff)


几乎所有的编程任务都从审查要求开始,并将问题分解成更小的部分。

还需要确定需求中是否缺少某些内容并询问其他信息,否则您可能会开始解决错误的问题。



在你的情况下,这是解决问题的一种方法:



1.从文本文件中读取数据

阅读文件操作并找到读取文件的最佳方式。



1a。分割输入数据

如果您决定阅读整个字符串,请阅读如何将字符串分成几个部分。



1b 。将数据插入数组

如评论中所述,动态列表可能更喜欢,因为您不知道文件中将包含多少值。



2.计算所需的值

如何遍历数组并找到最大值?

如何遍历数组并找到更大的值比标准?

(在这种情况下你需要另一个阵列)

注意:在这种情况下标准是什么?



3.显示结果

嗯,这可能是最简单的部分。



通过这样做,可以很容易地确定您需要多少功能以及每个功能的输入和输出。



(根据您的实施选择,您当然可以同时执行第1步和第2步,但对于初学者来说,最好将操作分开。)



您还应该为每个操作编写一些实现说明功能。

为此使用输入 - 处理 - 输出模型就足够了。



示例

Almost all programming assignments begins with reviewing the requirements and break down the problem into smaller pieces.
It is also necessary to identify if something is missing in the requirement and ask for additional information, otherwise you might start solving the wrong problem.

In your case this is one way to break down the problem:

1. Read data from a text file
Read up on file operations and find the best way to read the file.

1a. Split input data
If you decide to read the whole string, read up on how to split up a string in several parts.

1b. Insert data into an array
As mentioned in the comments, a dynamic list might be to prefer as you don't know how many values there will be in the file.

2. Calculating the required values
How to traverse an array and find the maximum value?
How to traverse an array and find values larger than the standard?
(In this case you will need another array)
Note: What is standard in this case?

3. Display the result
Well, this is probably the easiest part.

By doing this it is easy to identify how many functions you need and also the input and output from each function.

(Depending on your choice of implementation you can of course do step 1 and 2 at the same time, but for a beginner it might be better to separate the operations.)

You should also write a little implementation description for each function.
It is good enough to use the Input-Process-Output model for this.

Example
Function Name: ReadFileFromFile
Input:         The name of the file to read
Process:       Read the file and store the values in an array
Output:        An array with the the read values as return value



然后从此创建函数原型


From this you then create your function prototypes


这篇关于有人可以告诉我如何编写这个程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆