迫切需要帮助 [英] desperately need help

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

问题描述

就我的学习而言,这绝对不是明智的事情,

但绝望的情况需要绝望的措施。


最后的实验室因为我对C编程课程的介绍明天就要到了。

当我们去看看如何阅读文件的时候我正在度假,所以基本上我的

只有资源是书,课程笔记,以及例子。

不幸的是,对我来说,它们都没有用,所以我几乎不知道我是什么意思应该这样做。


我在这些论坛上没有读过一个主题,所以我不知道

社区如何在这里工作。如果你想让我成为一个白痴,

我支持你100%。但是,如果你想帮助我,那么你基本上已经保证了我的成绩,希望能让你感觉良好,因为它会让我觉得很好。 100x更好。


这就是我要做的事情:


使用输入文件,该文件有几行部门编号,项目

每件商品的数量,数量和成本。假设输入文件已按部门编号排序,并且所有输入值都有效。

编写程序一次读取一行输入文件,并打印到

输出文件的摘要报告,显示部门编号,项目

编号,数量,成本/项目,价值(数量*成本),每个

部门,项目数量(假设每行有一个唯一的项目编号)

和总计(所有值的总和)。摘要报告(输出文件)

应该类似于:

部门项目数量成本/项目总值

15 1389 4 3.20 12.80

15 3821 2 7.00 14.00

26.80

16 0122 8 2.50 20.00

20.00

19 1244 100 0.03 3.00

19 1245 20 4.00 80.00

19 2469 4 16.00 64.00

147.00

项目:6总计193.80

主要应该只打开文件,如果它们都打开,请调用一个函数

(你写的)打印汇总报告到输出文件,然后

关闭main中的文件。 (如果任一文件未打开,则打印错误

消息并退出程序。)

摘要报告功能必须将标题打印到输出文件。此报告函数中还有
,调用从

输入文件中读取一行的函数(见下文),进行所有计算(你可以在

另一个函数),打印到输出文件(一次一行),计算#

行(项)并累计总数(全部在for循环中)。输入文件的

结束后(打印最后一行项目),打印最后的

部门总数,项目数和带标签的总计。提示:

你需要一个计数器和2个总计(一个用于部门,另一个用于

总计),以及一个变量来存储以前读过的部门

数字(为了知道何时读取新的部门编号)。

不要使用任何外部变量!!!

包括在内你的节目:

?打印摘要报告的功能(如上所述)

?如果检测到文件末尾

,则读取返回0的输入行的函数(从摘要报告函数中调用此函数)

? for循环(使用expr1& expr3计算行数)

?两个文本文件(一个用于输入,另一个用于输出)

解决方案

哎呀,我忘了;这里是输入:

100 2398 45 67.89

108 3278 88 70.75

108 3421 123 8.99

108 4032 17 30.82

108 4360 56 18.78

121 5084 27 121.21

133 6599 5 204.08

133 6787 33 82.01

133 7121 12 73.35


EkteGjetost写道:

这个就我的学习而言,绝对不是聪明的事情,但绝望的情况需要采取绝望的措施。

我将在C编程课程的最后一个实验室明天到期。当我们去了解如何阅读文件时,我正在度假,所以基本上我的唯一资源是书籍,课程笔记和示例。


这应该足够了。

不幸的是,对我来说,它们都没有用,所以我几乎没有关于我应该做什么的线索。

我没有在这些论坛上看过一个主题,所以我不知道
社区如何在这里工作。如果你想让我成为一个白痴,我会支持你100%。但如果你想帮助我,那么你基本上已经保存了我的成绩,希望能让你感觉良好,因为它会使我感觉好100倍。

这就是我要做的事情:

使用一个输入文件,其中有几行部门编号,项目数量,数量和每件物品的成本。假设输入文件已按部门编号排序,并且所有输入值都有效。
编写程序一次读取一行输入文件,然后打印到
输出文件总结报告,显示部门编号,项目数量,数量,成本/项目,价值(数量*成本),每个部门的总数,项目数量(假设一个唯一的项目编号)在每一行)
和总计(所有值的总和)。摘要报告(输出文件)
应如下所示:
部门项目数量成本/项目总值
15 1389 4 3.20 12.80
15 3821 2 7.00 14.00
26.80
16 0122 8 2.50 20.00
20.00
19 1244 100 0.03 3.00
19 1245 20 4.00 80.00
19 2469 4 16.00 64.00
147.00 项目数:6总计193.80
主要应该只打开文件,如果它们都打开,调用一个函数
(你写的)打印摘要报告到输出文件,然后
关闭main中的文件。 (如果任一文件未打开,则输出错误消息并退出程序。)
摘要报告功能必须将标题打印到输出文件。另外在这个报表函数中,调用从
输入文件中读取一行的函数(见下文),做所有的计算(你可以在
另一个函数中执行),打印到输出文件(一次一行),计算行(项目)的#
并累计总数(全部在for循环中)。输入文件结束后(打印最后一行项目),打印最后一个部门总数,项目数和带标签的总计。提示:
你需要一个计数器和2个总计(一个用于部门,另一个用于总计),以及一个变量来存储先前读取的部门
号码(按顺序知道何时读取新的部门编号。
不要使用任何外部变量!!!
包含在您的程序中:
?打印摘要报告的功能(如上所述)
?如果检测到文件末尾,则读取输入行的函数返回0(从摘要报告函数中调用此函数)
? for循环(使用expr1& expr3计算行数#
?两个文本文件(一个用于输入,另一个用于输出)




我们不会为你做功课但是,

if您将尝试编写一些代码并将其发布在此处,

我确信每个人都乐意提供帮助。


< blockquote>你能帮忙开始吗?可能是结构图表还是什么?


感谢您的回复。


This is definitely not the smart thing to do as far as my learning goes,
but desperate situations call for desperate measures.

The final lab for my introduction to C programming class is due tomorrow.
I was on vacation when we went over how to read files, so basically my
only resources are the book, the course notes, and the examples.
Unfortunately for me, none of them are usefull at all, so pretty much i
don''t have a clue as to what i should do.

I haven''t read one topic on these forums, so i have no idea how the
community works around here. If you want to flame me for being an idiot,
i back you up 100%. But if you want to help me out, then you''ve basically
saved my grade and hopefully that makes you feel good, because it''ll make
me feel 100x better.

Here''s what i have to do:

Use an input file which has several lines of department number, item
number, quantity and cost per item. Assume that the input file has been
sorted by department number and that all the input values are valid.
Write a program to read the input file one line at a time, and print to an
output file a Summary Report which shows the department number, item
number, quantity, cost/item, value (quantity*cost), total for each
department, the number of items (assume a unique item number on each line)
and grand total (total of all values). The Summary Report (output file)
should look something like:
Department Item Quantity Cost/Item Value Totals
15 1389 4 3.20 12.80
15 3821 2 7.00 14.00
26.80
16 0122 8 2.50 20.00
20.00
19 1244 100 0.03 3.00
19 1245 20 4.00 80.00
19 2469 4 16.00 64.00
147.00
Number of Items: 6 Grand Total 193.80

Main should only open the files, and if they both open, call a function
(that you write) to print the summary report to the output file, then
close the files in main. (If either file doesn''t open, print an error
message and quit the program.)
The summary report function must print headers to the output file. Also
in this report function, call the function that reads a line from the
input file (see below), do all the calculations (you could do them in
another function), print to the output file (one line at a time), count #
of lines (items) and accumulate the totals (all in a for loop). After the
end of the input file (and last item line printed), print the last
department total, the # of items, and the grand total with labels. Hint:
You''ll need a counter and 2 totals (one for the departments, another for
the grand total), and a variable to store the previously read department
number (in order to know when a new department number was read).
DO NOT USE ANY EXTERNAL VARIABLES!!!
Include in your programs:
? A function to print the summary report (described above)
? A function to read a line of input that returns 0 if end of file
detected (call this from the summary report function)
? A for loop (count the # of lines using expr1 & expr3)
? Two text files (one for input, the other for output)

解决方案

Oops, i forgot; here''s the input:
100 2398 45 67.89
108 3278 88 70.75
108 3421 123 8.99
108 4032 17 30.82
108 4360 56 18.78
121 5084 27 121.21
133 6599 5 204.08
133 6787 33 82.01
133 7121 12 73.35


EkteGjetost wrote:

This is definitely not the smart thing to do as far as my learning goes,
but desperate situations call for desperate measures.

The final lab for my introduction to C programming class is due tomorrow.
I was on vacation when we went over how to read files, so basically my
only resources are the book, the course notes, and the examples.
That should be sufficient.
Unfortunately for me, none of them are usefull at all, so pretty much i
don''t have a clue as to what i should do.

I haven''t read one topic on these forums, so i have no idea how the
community works around here. If you want to flame me for being an idiot,
i back you up 100%. But if you want to help me out, then you''ve basically
saved my grade and hopefully that makes you feel good, because it''ll make
me feel 100x better.

Here''s what i have to do:

Use an input file which has several lines of department number, item
number, quantity and cost per item. Assume that the input file has been
sorted by department number and that all the input values are valid.
Write a program to read the input file one line at a time, and print to an
output file a Summary Report which shows the department number, item
number, quantity, cost/item, value (quantity*cost), total for each
department, the number of items (assume a unique item number on each line)
and grand total (total of all values). The Summary Report (output file)
should look something like:
Department Item Quantity Cost/Item Value Totals
15 1389 4 3.20 12.80
15 3821 2 7.00 14.00
26.80
16 0122 8 2.50 20.00
20.00
19 1244 100 0.03 3.00
19 1245 20 4.00 80.00
19 2469 4 16.00 64.00
147.00
Number of Items: 6 Grand Total 193.80

Main should only open the files, and if they both open, call a function
(that you write) to print the summary report to the output file, then
close the files in main. (If either file doesn''t open, print an error
message and quit the program.)
The summary report function must print headers to the output file. Also
in this report function, call the function that reads a line from the
input file (see below), do all the calculations (you could do them in
another function), print to the output file (one line at a time), count #
of lines (items) and accumulate the totals (all in a for loop). After the
end of the input file (and last item line printed), print the last
department total, the # of items, and the grand total with labels. Hint:
You''ll need a counter and 2 totals (one for the departments, another for
the grand total), and a variable to store the previously read department
number (in order to know when a new department number was read).
DO NOT USE ANY EXTERNAL VARIABLES!!!
Include in your programs:
? A function to print the summary report (described above)
? A function to read a line of input that returns 0 if end of file
detected (call this from the summary report function)
? A for loop (count the # of lines using expr1 & expr3)
? Two text files (one for input, the other for output)



We won''t do your homework for you but,
if you will attempt to write some code and post it here,
I''m sure that everyone would be glad to help.


Could you help get me started? Maybe a structure chart or something?

Thanks for the reply.


这篇关于迫切需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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