与数据文件处理有关的问题 [英] a problem related to data file handling

查看:70
本文介绍了与数据文件处理有关的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我有一个问题.我制作了一个"dataele"文件,其中存储了所有原子序数及其各自的原子数,名称,符号.但是我只想根据用户选择打开一个特定的元素.用户将输入原子序号,程序将从计算机文件数据元中搜索其详细信息. ...

谢谢:-}

Hello,


i am having a problem. i have made a file "dataele" where i have stored all the atomic number and their respective atomic mass, name, symbol. but i want to open only a particular element according to user choice. The user will input the atomic number and the program will search for its details form the computer file dataele...am unable to do it....plz help me out.................

THANKS :-}

推荐答案

让我们记住元素周期表中有多少个元素:只有118个.非常小的数目,什么也没有.因此,您所需要做的就是:一次读取元素数组中的整个文件,每个元素都是结构,元素周期表的一个单元.

当数组由索引索引时,将每个元素置于等于其原子序数的索引处.无需再读取数据,无需搜索.您需要输入中的原子质量,该结构是通过其索引找到的.就这样.

-SA
Let''s remember how many elements are there is the periodic table: just 118. Very small number, just nothing. So, all you need is this: read the whole file at once in the array of elements, each element being a structure, a cell of the periodic table.

As the array is indexed by the index, put each element at the index equal to its atomic number. No more reading data, no search needed. You need atomic mass in input, the structure is found by its index. That''s it.

—SA


因此,首先为每个元素定义一个struct ,然后对这些结构进行一个 array.

然后从存储文件中获取load 数据,并在程序启动时填充该数组.

之后,让用户input 其所需的原子序数.

根据输入的数字search 该数组和找到的数组元素的 show the details.

编写项目的步骤几乎占了工作量的80%;甚至更多;)

希望对您有所帮助.
So start by defining a struct for each element then make an array of those structs.

Then load data from the storage file and fill that array at program startup.

After that let user input their desired atomic number.

According to the input number search that array and show the details of the found array element.

Writing the steps of a project is almost 80% (or even more) of the job ;)

Hope it helps.


这闻起来很累,所以没有代码!

如何执行将取决于您如何存储数据:
如果它是文本文件,并且每一行代表一个元素,并且用逗号分隔值,则它相对简单:
1)获取用户输入,将其转换为数字.
2)设置循环以读取文件的每一行.
3)对于每一行,将第一个字段(最大为逗号)转换为数字.
4)将此数字与用户输入的数字进行比较.
5)如果不相同,请返回步骤(3)
6)现在,您有了所需的详细信息,并可以将其显示给您的用户.

如果您尚未像这样存储它,则访问每一行数据可能会更复杂,但是原理仍然相同.
This smells heavily of homework, so no code!

How you do it will depend on how you have stored your data:
If it is as a text file, with each line representing a single element, and comma delimited values, it is relatively simple:
1) Get the user input, convert it to a number.
2) Set up a loop to read each line of the file.
3) For each line, convert the first field (up to a comma) to a number.
4) Compare this number against the user entered number.
5) If they are not the same, go back to step (3)
6) You now have the details you need and can present them to your user.

If you haven''t stored it like this, then it may be more complex to access each row of data, but the principle is still the same.


这篇关于与数据文件处理有关的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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