EXTRA CREDIT HOMEWORK (20 points)

The Purpose

This extra credit homework allows you to earn 20 extra credit homework points. To do so, you must demonstrate a proficiency in classes, file input and output, pointers, and dynamically allocating memory and arrays.

The Person Class

Write a Person class in C++, with separate person.h and person.cpp files. Your Person class should have the following private data members:

In addition, your Person class should have the following member functions: NOTE: you can assume the file you are reading in is correct, e.g., only 'M' or 'F' is given for gender.

You may want to consider NotePad or WordPad on your computer to write your code for your Person class. Once you feel good about what you've written, copy the code into Visual Studio. Doing this will help you see where you might make mistakes on upcoming exams. (No, pointers and dynamic memory will not be on any exam, but classes will!)

Your main() Requirements:

Before we allocate space for our persons, we need to find out how many we need. First, we'll read through the file, counting how many valid persons there are. Then, we'll iterate through the file again, this time reading the valid persons into a dynamically allocated array.

As usual, we recommend you use the " Incremental Build" software development model. To encourage this use, we break down your main() requirements into steps. We suggest you throughly test each step before moving to the next step.

Step 1: How many valid people are in the file?

Step 2: Add valid people to your new people array.

There are exactly 19 invalid people in the data file. At this point you will know by the program output whether you have found them all.

Step 3: Sorting your people array.

We now want to sort your valid people array. Lecture 33 discussed the SelectionSort() algorithm (a simple sorting algorithm), and provided brief pseudocode for implementing it. A few more details are provided here. Put the function prototypes above your main() and function implementations below. Create these prototypes and function headers so that they operate on your People array, with the end goal of sorting your valid People array by each person's height. For full credit, you should pass a pointer to the array to your SelectionSort() function, and use this pointer within the function to access array elements. However, we suggest you first implement the sorting feature using the [ ] notation that you are familiar with, and then (if desired) modify the function to use pointers (not [ ]). NOTE: getting the function to work with [ ] is worth one point; getting the function to work with * is worth two points.

Step 4: Print a few valid people.

Using your Person's output() function, print the following three valid people:

Step 5: Good practice.

There are two things you should do to end the program. First, close your file input stream. Second, free the memory allocated by your program to hold the valid people. Be sure to use the delete[] operation, not delete without [].

Submission

You need to submit your solution to this homework assignment, as well as your solution to Lab EC. In submitting your homework assignment (due May 6th), follow these steps: