Lab 9 - Pointers and Structures

Due: Friday November 12, 2010 at 5:00pm

Note: This lab will be on Wednesday. There will be lecture on Tuesday November 9th about Chapter 13 (classes). You may go to Dr. Thomas' office to ask questions about the lab during class time on Wednesday. You may also opt to complete this lab during class time on Friday, when a tutor is available in the walk-in lab (Sci III 324). I will return on Monday and the normal schedule will resume that week.

You may work in groups of two on this code. Be sure to put both partners' names in the comment section of the code so both of you get credit for the assignment.

The purpose of this lab is to see how pointers can also be used to read data into structures and print data out of structures, instead of the by-reference variables used in Homework 6. Use the structure you have defined for Homework 6 for this lab.

Create a pointer version of the functions getStudent and printStudent for the StudentRecord structure from Homework 6. The getStudent function will take a single StudentRecord pointer as an argument. It will read in the name, ID and exam scores. You do NOT need to do input validation for this lab's version of getStudent (but you will still need to do it for Homework 6). Calculate the overall class grade as the average of the exam scores.

The printStudent function will also take a single StudentRecord pointer as an argument. It will print out the name, ID, exam scores and overall class grade. You do NOT not need to do column or precision formatting for the lab (but you will still need to do it for Homework 6).

Remember to use the arrow operator ( -> ) instead of the dot operator inside the functions. Alternatively, you may dereference the pointer and then use the dot operator.

Use the following function prototypes and main() for your code. Add the StudentRecord structure above the function prototypes:

void getStudent(StudentRecord *);
void printStudent(StudentRecord *);

int main()
{
  StudentRecord stu;

  getStudent(&stu);    // The amperstand gets the address of the stu object
  printStudent(&stu);

  return 0;
}
Email me the completed code.