Dana Vrajitoru
C201/I211 Computer Programming II

Homework 6

Due Date: Wednesday, October 18, 2006.

Ex. 1 Download the following files:
student_rec.h
student_rec.cpp
main.cpp

Create a project just like for the previous homework and include these three files.

Ex. 1. Add the following data members in the class Student_rec, all of them declared as private:

Modify the existing functions (constructors, input, output) to take into account this new information.

Ex. 2. Add the following functions to the class Student_rec:

a. A function comparing two student record objects. The function should return true if the two objects represent the same person, meaning if they have the same name and the same birthday. Here is a prototype for this function:

bool Same_person(Student_rec &data);
To compare the names of the two records you'll have to use the function
strcmp
. This function takes two strings as parameters and return 0 if they are identical.

b. A function computing the age of the person based on the current date. Here is a prototype for this function:

int Age(int month, int day, int year);
To compute the age, first you must compare the month/day with the student's birthday. If the current month is larger than the birth month, or if they are equal and the current day is greater or equal than the birth day, then the age is equal to current year minus birth year. Otherwise it is equal to the current year minus the birth year minus 1.

If you named the data members month, day, year, name the parameters for this function differently (like, m, d, y).

Default values. Give a default value to each of the parameters of this function. Make them represent the due date for the homework (10/18/2006).

c. A function displaying the student's phone number. This function should take one parameter that represents the area code. If the student's phone number has the same area code, don't display it. For example, if the phone number is 5745205545, and the area code is 574, then your function should display 520-5545. Otherwise display the entire phone number, (574) 520-5545. A prototype for this parameter:

void Output_phone(int area_code);
Note that you will need to make a transformation to the number to display it in a nice format as above.

Default value. Add the value 574 as the default value for this parameter.

Ex. 3. In the main function, declare a second object of this class, let's call it mike. Input and output its content just as for the object john.

After that call the function Age for each of these objects using the default values (meaning with no parameters). Output the age of each of them (in the main, not in the function Age), then output which of them is older.

Then call the function Output_phone for each of them, using the default value for this function.

Finally, call the function Same_person on the two records and output a message from the main (not from the function Same_person) to communicate the result.

Show an example of the execution by embedding it in the program as a comment, as usual. Send the three files you modified by email. Do not change the file names for this homework.