Project 3, COMP1571, Fall 2009
Problem description:
In this project, you will read data from a file called “grading_info.txt”. There are unknown number of lines in this file. Each line is consisted of 2 pieces of data separated by a single space. The first data item is student’s name (for simplicity, only use student’s first name), and the second data item is her/his numerical grade. Below is a sample file.
Grading_info.txt
Mary 92
Jack 81
Brian 76
Melody 85
Seif 62
:
:
This program would read each line (student’s name and the numerical grade) and will determine her/his letter grade. The letter grades are assigned as follows:
91 -100 A
81 – 90 B
71 – 80 C
61 – 70 D
60 and below F
Therefore, given the sample input file above, the output should look like:
Students’ grades
------
Mary 92 A
Jack 81 B
Brian 96 A
Melody 65 B
Seif 62 D
:
Here is the challenging part! Having calculated the letter grades, you need to create a histogram.
Histogram is a graphical chart that represents numerical values in a graphical format. Below is a sample histogram:
* *
* *
* * **
* * **
* * **
* * **
* * * * *
* * * * *
* * * * *
* * * * *
Mary Jack Brian Melody Seif……
Letter grade A equates to 10 asterisks.
Letter grade B equates to 8 asterisks.
Letter grade C equates to 6 asterisks.
Letter grade D equates to 4 asterisks.
Letter grade F equates to 2 asterisks.
You are free to create your own input file. Below is a suggested input file.
Hillary,92
Duff,81
Hannah,96
Montana,62
Brittney,74
Spears,89
Jessica,56
Simpson,76
Kid,55
:
:
:
:
The final output should look something like this:
Students final grades
------
Hillary 92 A
Duff 81 B
Hannah 96 A
Montana62 D
Brittney74C
Spears89B
Jessica56F
Simpson76C
Kid55F
….....
….....
….....
* *
* *
* * *
* * *
* * *
* * *
* * * *
* * * *
* * * *
* * * *
Hillary Duff Hannah Montana ……
Technical requirements for this program
- ABSOLUTELY NO global variables: otherwise you will lose 50 percent of the grade for this
project AUTOMATICALLY!!!
-No hard coding when/if applicable.
-You must use the following prototypes and write the functions’ definitions along with calls to them to make your program to compile and run correctly:
Use the following ADT to create your array.
typedef struct
{
char name[20];
int numerical_grade;
char letter_grade;
} stu_type;
- The student array must be declared/defined in the main() routine.
- The histogram array must be declared/defined in the main() routine.
- void read_and_populate(stu_type[]);// Reads the file and populates the array.
- void compute_letter_grades(stu_type[]);// Compute and populate letter grades.
- void display_stu_grades(stu_type[]);// Displays student name; numerical, and letter grades.
- void populate_hist_array(stu_type[],char[][]); // Populate histogram with asterisks given letter grades
- void display_histogram(char[][]);// Display histogram.
Extra Credit (15 %):
You could receive extra credit if you could display the names in the histogram vertically. Here is an example:
* *
* *
* * *
* * *
* * *
* * *
* * * *
* * * *
* * * *
* * * * ……
H D H M ……
i u a o
l f n n
l f n t
a a a
r h n
y a
ASSUME that the longest name does not exceed 10 characters.
Hint: You could use the same technique as used for histogram.