Due: 2018-Oct-31 🎃 (Wed)29 (Mon) 15:00, D2L and hardcopy
Updates:ignoring formatting and minor phrasing changes
Oct.30 11:40 Clarify as mentioned in class not
to have four loops in a row for reading
a student's scores; at least call four helpers, if not just a single helper four times.
Oct.30 11:40 Warn not to attempt the challenge-task
before completing regular assignment.
Write a program that reads student scores from standard input
and prints certain specified information based on those scores.
The input file will begin with four lines that give the number and weight
for four types of grades: programs, quizzes, tests, and final exam,
respectively.
After these four initial lines, there will be five lines of data per student:
Name
Program scores (missing program scores will receive a grade of 0)
Quiz scores (missing quiz scores will receive a grade of 0)
Test scores (missing test scores will be replaced with the final exam score)
Final exam score (missing final exam will receive a grade of 0)
In the following example input file,
there are
two programs worth a total of 40%,
four quizzes are worth a total of 10%,
two tests are worth a total of 30%,
and the single final exam is worth 20%.
Name: Adam
Overall Average: 87.0
Letter Grade: B
Category Weight Average Points Grades ...
Programs 40 100.0 40.0 100 100
Quizzes 10 90.0 9.0 90 90 90 90
Tests 30 80.0 24.0 80 80
Final Exam 20 70.0 14.0 70
Name: Jill
Overall Average: 71.5
Letter Grade: C
Category Weight Average Points Grades ...
Programs 40 75.0 30.0 100 50
Quizzes 10 10.0 1.0 40 0' 0' 0'
Tests 30 75.0 22.5 60 90'
Final Exam 20 90.0 18.0 90
Name: Bob
Overall Average: 32.0
Letter Grade: F
Category Weight Average Points Grades ...
Programs 40 20.0 8.0 40 0'
Quizzes 10 40.0 4.0 40 40 40 40
Tests 30 40.0 12.0 40 40
Final Exam 20 40.0 8.0 40
Name: Bill
Overall Average: 50.0
Letter Grade: F
Category Weight Average Points Grades ...
Programs 40 50.0 20.0 50 50
Quizzes 10 50.0 5.0 50 50 50 50
Tests 30 50.0 15.0 50 50
Final Exam 20 50.0 10.0 50
Data:
All data will be reasonable (i.e. numbers will fit in 32-bit values).
The number of items in each category is positive, and less than 77.
The number of Final Exams will always be 1.
All scores are based on a maximum of 100 points.
All scores in a given category are equally weighted.
Input:
Input is to come from standard input.
All input values will be integers.
All weights will sum to 100%.
All data for a given category will be on a single line.
There will be at least one space between any pair of values on a line of input.
There will be between 0 and 100 students.
When reading values on a line,
use the boolean function end_of_line
to determine if there are any more values remaining.
There is no any trailing whitespace on any input line.
This allows end_of_line to work nicely.
Output:
Replacement values should have a “'” beside them, as shown.
Your program is to have no prompts.
Students are to be printed in descending order of letter grade and
in the same order as they were in the input within a given letter grade
(i.e., use a stable sort).
Print all numeric values with one place to the right of the decimal point.
Use a 10 point scale: 90.0 and above is a grade of A, less than 60 is a grade of F, and so on.
Other points:
Your program should be called missing_scores.adb
You should write your own (stable) sort routine. I advise insertion-sort.
The built-in sort uses an implementation
of quicksort which is not stable.
Your main routine is to have only two statements.
Each procedure is to have exactly one parameter.
The main procedure may also have an exception-handler, if you like.
Make good use procedures, functions, records, new numeric types/subtypes, and (perhaps) unconstrained types.
In particular, do not have four repeated, nearly-identical loops in a row
when reading a student's scores; at least call four helpers, if not just a single helper four times.
Do not use any global variables in your program!
All communication with procedures and functions must be via parameters and return values.
Numbers such as the maximum number of grades should only appear once in the program
(i.e. they should appear as a named-constant or as a limit of a type or subtype.)
You may read the name into an Unbounded_String,
but in your array of students you must store the name in a String
of fixed maximum length
(and keep track of the actual length).
Recall get_line(String,int), which returns
how many characters were successfully read.
Be sure to test your program on rucs.
Hints
If you have read the last number off a line, you can use skip_line to
advance to the start of the next line.
Normally declare all types within the main program. However, in this
program you may want to declare some types within specific routines.
Challenge/extra credit
Slight extra-credit: If the weights don't add up to 100%,
your first line of output should be something like:
WARNING: scores combine to 120%!!! Normalizing them..
And as indicated, you should normalize them.
If they are all zero (and hence can't be normalized), it's okay for your program to crash
after printing that line.
Slight extra-credit: If a name is too long, write a warning message like:
WARNING: Truncating name to 100 characters..
Include the original name in the warning.
Challenge: Dynamically allocate the grade category arrays with the sizes specified needed
rather than using arrays bounded to size 77.
This can be achieved by reading the first four values and then
calling a procedure which contains the array types, or with the help of declare blocks.
Style:
In coming up with your Ada solution to the following problem, please follow
my style guide.
In particular, please note the use of consistent indentation, named constants,
and descriptive constant and variable names. Please remember that the first
thing in any program file should be a comment that gives a brief overview
of what the file contains (and should do). Also remember to keep
your lines less than 80 characters long. Not only does this mean that printouts
won't run off the side of the page, but it also makes your programs look neater
on an 80 column wide xterm window (a popular size).
If you are unsure of an element of programming style, please
ask, as I would be more than happy to show you what I want.