CIS071
Lab14 - Grade Conversion with Structs
Due: (Fri Dec 8, 2006)
Objectives: Arrays; Arrays of Structs;
Lookup (Search) Tables
Lab14: Modify your completed assignment for Lab05 by changing
the implementation of the function
char convertGrade
(int numScore);
You
need to remove the old code you wrote and replace it with code that uses a
lookup (search) table to convert a numeric score to a letter grade. The interface for your function and the rest
of your program should all remain the same.
The specification for the function remains the same, including the
return value of ‘Z’ if the score is out of range.
Instructions:
You
need to first declare a struct range entry containing
three elements:
typedef struct
{ // declares a new data type
int minScore; //
minimum score for a grade range
int maxScore; //
maximum score for a grade range
char grade; // grade for the current grade range
} table_type;
then define the array of these structs as
#define TABLE_SIZE 5
table_type table[TABLE_SIZE];22
and
then populate the table such that the resulting table looks like this :
minScore maxScore grade
|
90 |
100 |
A |
|
80 |
89 |
B |
|
70 |
79 |
C |
|
60 |
69 |
D |
|
0 |
59 |
F |
[0]
[1]
[2]
[3]
[4]
Accessing
any element in the array can be done by writing
table[i] where 0 <= i < 5
Accessing
a particular component of the struct at element in
the array is accomplished by writing (for example)
table[i].grade. If i is
3,
the value of table[i].grade is ‘D’.
Hint:
You can check if the letter grade is ‘A’ by writing:
if (numScore <= table[1].maxScore
&& numScore > table[1].minScore)
Deliverables:Submit your program; show a few sample runs of the program.