Help me with a class assignment

O

osmium

I need help with an assignment in my C programming class. My teacher
sucks and basically has told me that anything i need to know is in the
book, which is fine but she hasn't taught us much of anything and i've
been having a lot of problems with this program, so i scrapped it and
hopefully can get some help on here. any help would be great.

This is the assignment


Emphasis of this program is on arrays.

Write a program that will read in grades, calculates the average grade
and shows how much each score differs from the average.

Input: Prompt the user for input grades. Your program should read in
all the grades supplied by the user, but retain only those grades that
are in the range 0 to 100 (both values inclusive).

Your program should keep reading the grades from the keyboard until it
encounters EOF. You may store the grades as integers. You may assume
that no more than 80 grades will be supplied at any given time. Thus,
you may set the array size to 80. Use a macro for this purpose.


Output: Print the grades in a neatly formatted fashion as displayed
below (see 'Sample Runs' below)

Your program should terminate only when the user supplies EOF ( Ctrl D
- on UNIX)
Your program should be split into component functions.
Ensure that you have your Name, Class (Ex. cs211 - Day), Assignment
number, Description at the beginning of your program. Also, include
comments at appropriate positions in the program.
Your program should be indented neatly. DO NOT USE tabs (3 spaces
would be ideal)
Variable names should be descriptive.
Your program should be split up into several files as explained below:
o prog4.c : This will hold the main function
o prog4Fns.c: This file will consist of the component functions
o prog4.h: Header file for your program
You will need to #include your header file in both the source (.c)
files
DO NOT #include ONE SOURCE FILE INSIDE ANOTHER.
Compile your program with the -Wall option as follows:
o gcc -Wall prog4.c prog4Fns.c -o prog4
Hand in the files prog4.c prog4Fns.c electronically. Use the command:

~cs211d/bin/handin 4 prog4.c prog4Fns.c prog4.h

DO NOT e-mail the program to me. It will be deleted.



Some sample runs of the program:
Compile:
bugs> gcc -Wall prog4.c prog4Fns.c -o prog4
NOTE: In the following 'runs' blue font implies the lines are output
by the program, black font implies items typed in by the user.


In Run1, Run2, Run3 - we have no output displayed because the input
supplied does not consist of a single valid grade.

Further, note that the average is printed ONLY ONCE (ON THE FIRST
LINE)


Run1:
kira> prog4
Enter grades separated by spaces (min: 0, max: 100 ):
No grades entered. Exiting program
kira>



Run2:
kira> prog4
Enter grades separated by spaces (min: 0, max: 100 ): -24 -45 -93
-123
No valid grades entered. Exiting program
kira>



Run3:
kira> prog4
Enter grades separated by spaces (min: 0, max: 100 ): a
Invalid input; try again:
b
Invalid input; try again:
c
Invalid input; try again:
No grades entered. Exiting program
kira>




Run4:
kira> prog4
Enter grades separated by spaces (min: 0, max: 100 ): 23 -34 123 0
100
Discarding the 2 invalid grade(s) entered
Grade Average Deviation from Average
===================================================
23 41.00 -18.00
0 -41.00
100 59.00
kira>


Runs 3 and 4 are good illustrations of why specification by example,
instead of text, is bad.

The end result is a nightmare for the end user. How errors are treated
varies: out of range errors are simply counted, bad input such as a letter
asks him to try again. But the example assumes the letter is the first entry
on a line, whcih will not usually be the case since the desired form is
several entries on a line and several lines. If a user types "13 f 82 z 19"
how does the user know what "invalid input" is talking about? Does he have
to read a paragraph of instructions? Furthermore he doesn't know of the out
of range errors until it is much too late to correct them. Since the nature
of the desired input forces the program to analyze each line on a
line-by-line basis, the proper thing to do is to print *all* offending data
input and a message that it was ignored. All of this before asking for the
next line from the user. The user can correct his mistake by his next input
line while it is still fresh in his mind and he has context..
 
P

pete

osmium said:
specification by example, instead of text, is bad.

I completed the assignment
and found that I had to make some decissions,
that really should have been made for me
by a proper specification.
 
D

David Thompson

Data bad.
Yes.

No permission to read stream.

That would usually fail at f[re]open time (at or before startup for
initial standard streams) not at I/O time, although there have been
and may be again systems that propagate 'online' security changes,
particularly revocations, as did Multics and IIRC VMS.
Buffer empty because of EOF.
Stream lost in act of reading.

Assuming 'lost' covers I/O error(s), those would be true for scanf or
fscanf, but not sscanf; that fails for string empty or invalid.
Lots of ways.

For moderately small values of lots. <G>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top