Homework 1 - Structures and Pointers
Due: Wednesday, April 11, 2012 (email by midnight)
Coding Conventions
The following coding conventions should be used for all assignments.
Assignment
The purpose of this assignment is to create a structure called StudentRecord
to track and calculate student grades in a fictitious course. You will also
be using a pointer to dynamically allocate and delete a StudentRecord object.
Any assignment that does not use new/delete will have points deducted.
The StudentRecord structure must have the following pieces of data:
- A C-style string for the student name (you may choose the length for this string)
- A 10 character C-style string for the student ID
- An interger array with a size of 5 to store the exam scores
- A double for the overall exam average
You will have the following two function to manipulate StudentRecord objects.
You may add additional functions if you wish, but you must have these two
functions to get full points:
- StudentRecord *createStudent() - This function will allocate a single
StudentRecord object and then prompt the user to enter the name, ID and
exam scores. After reading in these variables, the function will compute
the overall exam average and return the address (a pointer) for the
allocated StudentRecord object. If allocation fails, return NULL.
- void printStudent(StudentRecord *) - This function will take a StudentRecord
pointer and print out all of its fields. The overall exam average should be
printed with two decimal places of precision.
Your main function will have the following loop:
do
call createStudent and store the returned address in a StudentRecord pointer
if the pointer is NULL
print an error message
break out of the loop
end-if
call printStudent with the StudentRecord pointer
deallocate the StudentRecord pointer
prompt the user "Do you wish to continue?"
read in their response
convert the response to all lowercase letters
while the user responds "yes" or "y"
Email your source code to me by the due date.