木其工作室:QQ928900200
Computing I
Program 3 – Treat this like a take home exam. You may not work together.
Write a program to compute average grades for a course. The course records are in a single file and are organized according to the following format: Each line contains a student’s first name, then one space, then the student’s last name, then one space, then some number of quiz scores that, if they exist, are separated by one space. Each student will have zero to ten scores, and each score is an integer not greater than 100. Your program will read data from this file and write its output to a second file. The data in the output file will be nearly the same as the data in the input file except that you will print the names as last_name, first_name and there will be one additional number at the end of each line: the average of the student’s ten quiz scores.
The output file must be formatted such that first and last names appear together in a left justified column that is 20 characters wide where the last name comes first, then a comma and a space and then the first name. Use your read string function to read each name separately and then put them together into a larger correctly formatted string before trying to output them. Each quiz score should be listed in a right justified column that is 4 characters wide, and the average should appear in its own right justified column that is 10 characters wide.
Note that if a student has fewer than 10 scores, the average is still the sum of the quiz scores divided by 10; these students are assumed to have missed one or more of the quizzes. The output file should contain a line (or lines) at the beginning of the file providing appropriate column headings. Use formatting statements to make the layout clean and easy to read.
After writing the required data to an output file, your program will close all files and then copy the contents of the “output” file to the “input” file by reopening the input file for writing and opening the output file for reading. Thus, the net effect of the program is to change the contents of the input file. Do not attempt to copy the output file to the input file until you have thoroughly tested and debugged the rest of your program to ensure that it operates correctly.
You should use at least two functions that include FILE pointers in their parameter lists. (These functions may have other parameters as well.) The input file should be called quiz.txt and the output file should be called average.txt.
Some test cases you may want to consider are the following:
• What if the input file is empty?
• What if a student does not have any quiz grades at all?
• What if multiple students in a row don’t have any quiz grades?
• What if there are extra new lines at the end of the file?
• What if the last record in the file does not have a new line after it but rather ends with end of file?
Name your source code file program3.c.
One very useful strategy is to write a function that, given a FILE pointer, will extract out exactly one person’s full name and write it to the output file. Write another function that given a FILE pointer will extract out one person’s quiz scores and list them in the output file along with the average score. Then use these two functions in a loop that will keep doing this until there is no more data in the input file.
Submit your assignment through the blackboard system.
In addition, you must include a comments section at the beginning of each of your files that provides information about the file and its intended purpose. For example,
/*
Author: David B. Adams
Course: CS 91.101, Computing I
Date: Today’s Date
Description: This file implements the
functionality required by
Program 5A.
*/
The following criteria will be used to grade your submission:
• Does the code compile?
• Does the code function according to the problem specification?
• Is there an appropriate comments section at the beginning of each file (similar to the one shown above)?
• Is the code readable and well-formatted? Is it well-documented and clear?
• Do you have pre and post conditions for each of your functions?
The available points are distributed according to the following weights:
Correctness: 85%
Comments: 5%
Organization: 10%
A program that does not compile or link will not be graded.
相关推荐
c语言求平均值.exe
C语言求平均值问题
c语言求数组平均值
本话题涉及到的是一个简单的C语言程序,旨在实现求和与求平均数的功能。这通常是编程初学者在学习控制流、变量和基本算术运算时会遇到的基础练习。 在C语言中,求和和求平均数的操作是通过循环结构和数学运算来完成...
C语言程序设计-求一批数中小于平均值的数的个数;.c
3. 计算:对数组中的256个采样点求平方,然后求和,得到的总和除以采样点数,得到平均平方值。 4. RMS:将平均平方值开方,得到的就是当前时刻的有效值。 5. 循环:不断重复以上步骤,随着新的采样点到来,持续更新...
"防脉冲干扰移动平均值法数字滤波器的C语言算法及其实现" 防脉冲干扰移动平均值法数字滤波器是指一种数字滤波方法,用于对脉冲干扰信号进行处理。这种方法的基本原理是将被认为是受干扰的信号数据去掉,然后对剩余...
PTA 多文件编程题-求平均值(c语言版)
可以根据自己定义的 数组大小 进行输入 求平均数
十个分数,去掉一个最高分一个最低分,求平均值,保留一位小数,并以十进制形式输出,初学者编
总的来说,C语言数组参数最大值最小值的程序是理解和实践数组操作的一个好例子,它涉及到基本的循环、条件判断以及指针的使用,这些都是C语言编程的基础技能。对于初学者来说,不断编写这样的小程序并分享给他人可以...
主要涉及创建队列存储对象、往队列填充资料、排除最大和最小元素以及得出其余七个数字平均值的具体步骤。此外提供了完整的C语言程式代码实例供参考,并对程序内部运作机制加以解释。 适用人群:具有一定计算机编程...
每次新的采样值到来时,移除最旧的值并添加最新的值,然后计算当前缓冲区内的所有值的平均值。 以下是一个简单的C语言程序示例,演示了如何实现这种滑动平均滤波方法: 要实现滑动取平均的方式对单片机采集的温度值...
c语言求数组平均值
其中,数据的输入和平均结果的显示将使用汇编语言实现,而平均值的计算将使用C语言实现。 在程序设计中,我们首先编写了一个C语言函数getavg,该函数用于计算平均值。然后,我们编写了一个汇编语言程序,用于输入...
3. **计算平均值**:对于图像中的每一个像素,计算其邻域内所有像素的灰度值(或RGB分量)的平均值。 4. **替换像素值**:将该像素的原始值替换为计算出的平均值。 5. **处理边界**:在处理图像边缘时,可能需要...
标准差则需要计算每个分数与平均值的差的平方,然后求平均,再开方得到。 考虑到这是课程的随堂作业,代码可能相对简单,适合初学者。开发环境选择的是Dev-C++,这是一个集成开发环境,内含GCC编译器,适用于初学者...