CIS071
Lab12 - Grade Conversion with Structs Due: (Fri Apr 21, 2006)
Objectives: Arrays; Arrays of Structs;
Lookup (Search) Tables
Lab12: Modify your completed assignment for Lab04 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.
1.
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;
and then define the array of these structs as
#define TABLE_SIZE 5
table_type
table[TABLE_SIZE];
Conceptually, the resulting table looks like this (and
you have to fill the table with the proper values).
minScore maxScore grade
|
90 |
100 |
A |
|
80 |
89 |
B |
|
70 |
79 |
C |
|
60 |
69 |
D |
|
0 |
59 |
F |
[0]
[1]
[2]
[3]
[4]
2.
Accessing any
element (a struct) 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’.
Deliverables:Submit your program; show a few sample runs of the program.