Classes and Operator Overloading

This assignment demonstrates abstraction and organization of related data and methods together into a class. Some operators are overloaded to make usage of the class objects similar to usage of the standard built in types, such as intor double.

Create a simplestudent database application. It must use the followingStudentRecord class. This comprises the contents of the header file StudentRecord.h. For full credit on this assignment you must use this header file (it is OK to use the string type instead of character arrays).

const int ENTRY_SZ = 256;

struct DateType

{

unsigned intyear_;

unsigned int month_;

unsigned int day_;

};

class StudentRecord

{

private:

char firstName_[ENTRY_SZ];

char lastName_[ENTRY_SZ];

int idNum_;

char major_[ENTRY_SZ];

DateTypedob_;

public:

static int entryCnt_;

static char filePath_[ENTRY_SZ];

void SetFirstName(const char fName[]);

void SetLastName(const char lName[]);

void SetIdNum(int id);

void SetIdNum(const char id[]);

void SetMajor(const char major[]);

void SetDOB(const char dob[]);

// Copies some properties into out arguments

void GetFirstName(char name[], int sz) const;

void GetLastName(char name[], int sz) const;

void AddEntryFromConsole();

void PrintToConsole();

void AppendToFile();

StudentRecordoperator=(const StudentRecord& obj);

};

bool operator== (const StudentRecord& obj1, const StudentRecord& obj2);

Note that the overloaded assignment operator ‘=’ is a member function (of the class StudentRecord) and the overloaded “is equal” operator ‘==’ is not a member function. This is done to demonstrate both methods of operator overloading. Also note that they are each binary operators. That means they take two operands, one on each side of the operator.

Remember that the static class data must be initialized in the .cpp file like this:

intStudentRecord::entryCnt_ = 0;

charStudentRecord::filePath_ = "";

This application should display a console menu that looks like this:

a)Open astudent records file

b)Add a new student record

c)Print all student records

d)Quit

The program must use a fixed array of StudentRecord objects and size it to 1000 elements. The code should look like this:

const int STUD_RECORDS_ARR_SZ = 1000;

StudentRecordstudRcds[STUD_RECORDS_ARR_SZ];

Input error handling is not required for this assignment. For example, if the user types an incorrect file path, the behavior may remain undefined (I won’t test this case).

When a) is selected, the program must prompt the user to enter a file path for the student records file. It should open the file, read in the 5 lines of data for each entry into the next element of studRcds array. Reading of the file should continue until there are no more entries left in the file.

When calling this option a second time (or more), the student records data from the previous file read should be deleted. If the input file has 4 records in it, and a) is selected a second time with a different input file that has 2 records, the student records array should only contain the 2 records from the last input file.

The date of birth must be entered in the format: MM/DD/YYYY. If the length of this string is not 10 characters, assume a bad entry and set the date to 00/00/0000.

Make sure to add the following clear statement each time after closing any file (otherwise, some compilers, like mine, will not allow the file to be reopened):
inFile.close();
inFile.clear(std::ios_base::goodbit);

The b) option should prompt the user to enter the 5 lines for a new student record contained within the AddEntryFromConsole() method.This method should first check to see if a student records file has been opened yet through selection a).A function in the main function should also verify that the student record does not already exist, based on the first and last names, by using the overloaded “==” operator. The overloaded “==” should compare the first and last names of the objects only. If it does not already exist, add that entry to the next element in the studRcds array using the overloaded assignment operator, ‘=’, and also append it to the student records file using the AppendToFile() method.

The c) option should print the current contents of the student records array, which should match the contents of the student records file. It should also print the number of entries currently contained.

Usage Examples:

User entries are bolded:

Please make a choice:

a) Open astudent records file

b) Add a new student record

c) Print all student records

d) Quit

a

Enter path to student record file: C:\Miscellaneous\CS162\asgmt01\StudentRecords.txt

4 records read from the student records file.

Please make a choice:

a) Open astudent records file

b) Add a new student record

c) Print all student records

d) Quit

b

Enter the first name: Easter

Enter the last name: Bunny

Enter the ID number: 567890

Enter the major: Computer Science

Enter the date of birth [MM/DD/YYYY]:07/05/1998

Please make a choice:

a) Open astudent records file

b) Add a new student record

c) Print all student records

d) Quit

b

Enter the first name: Easter

Enter the last name: Bunny

Enter the ID number: 246824

Enter the major: Physics

Enter the date of birth [MM/DD/YYYY]:03/18/2000

This is a duplicate entry and will not be added to the student record DB.

Please make a choice:

a) Open astudent records file

b) Add a new student record

c) Print all student records

d) Quit

c

Santa

Claus

1234567

Snow Making

00/00/0000

Herman

Munster

13131313

Haunting

12/13/1013

Ava

Lee

2323654

Marine Biologist

07/23/1985

Mad

Hatter

3335678

Hat Making

11/12/1990

Easter

Bunny

567890

Computer Science

07/05/1998

Please make a choice:

a) Open astudent records file

b) Add a new student record

c) Print all student records

d) Quit

File Organization:

Put the StudentRecord class declaration in a header file called StudentRecord.h. Put the StudentRecord class definition in a source file called StudentRecord.cpp. Put the main program and all non-class functions into a main file called main.cpp.

Deliverables:

Upload the StudentRecord.cpp, StudentRecord.h, and main.cpp files only. Any other files, including zip files, will not be accepted.