从文件和输出平均读取成绩的程序 [英] Program to read grades from file and output average

查看:74
本文介绍了从文件和输出平均读取成绩的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的小组需要有关此计划的帮助。我们试图启动它并且没有在哪里。请帮助我们。


编写一个C ++程序,它将从文件中读取数据,对数据执行计算,然后将结果打印到另一个文件。来自该文件的数据将包含100行,其中每行包含三个项目。这三个项是算术运算,后跟两个整数值(非零)。程序应该执行在两个整数上指定的算术运算。然后程序应该打印出另一个文件的第一个数字,算术运算,第二个整数,一个=符号,然后执行刚刚执行的操作的结果。这应该重复100行。程序应首先使用switch语句来识别操作(+, - ,*,/)然后调用相应的函数来执行计算并将结果打印到第二个文件来计算结果。示例输入文件:+ 4,54 - 34 45 * 42 2/325 5示例输出文件:4 + 45 = 50 34-45 = -11 42 * 2 = 84 325/5 = 13程序的一般格式应该如下: - 包含部分... - 声明文件指针ifstream infile; ofstream outfile; - 加法函数 - 减法函数 - 乘法函数 - 除法函数 - 主函数

My group needs help with this program. We attempted to start it and got no where. Please help us.

Write a C++ program that will read data from a file, perform computation on the data, then print the result to another file. The data from the file will contian 100 lines where each line contains three items. The three items are an arithmetic operation followed by two integer values (non zero.) The program should perform the arithmetic operation specified on the two integers. Then the program should print out to another file the first number, the arithmetic operation, the second integer, an = sign, then the result of the operation just performed. This should repeat for the 100 lines. The program should compute the result by first using a switch statement to identify the operation (+, -, *, /) then call the appropriate function to perform the computation and print the result to the second file. A sample input file: + 4, 54 - 34 45 * 42 2 / 325 5 A sample output file: 4+45=50 34-45=-11 42*2=84 325/5=13 The general format of the program should be as follows: - The include section... - Declaring the file pointers ifstream infile; ofstream outfile; - The add function - The subtract function - The multiply function - The divide function - The main function

推荐答案

我们很乐意提供帮助。但是......你需要问一个问题。
We''d love to help. But...you need to ask a question.


好的。我从哪里开始?


将程序分解为组件。例如,似乎有一个组件从文件中读取数据,另一个组件用于计算数据,另一个组件用于打印结果。按逻辑顺序获取每个组件。然后重复,直到你有一个足够小的组件来轻松编码。从数据文件中读取,并打印出结果足够小。计算数据需要分解。


编写代码时,你应该在开始编码之前计算算法。


首先从文件中读取数据。
Break down the program into components. For example, there seems to be a component that reads data from the files, another that computes data, and another that prints out the results. Take each component, in a logical order. And then repeat, until you have a component small enough to easily code. Reading from the data file, and printing out the results are small enough. Computing the data needs to broken down.

When writing the code, you should work out the algorithm, before you even start coding.

Start with reading the data rom the file then.


这篇关于从文件和输出平均读取成绩的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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