Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define a class MedicalAidMember as an ADT that uses separate compilation, i.e. separate files for the interface and the implementation. The class represents the medical

Define a class MedicalAidMember as an ADT that uses separate compilation, i.e. separate files for the interface and the implementation. The class represents the medical aid record for a staff member and has five member variables:

name, a string that holds the combined first name and last name of the staff member

number, an integer that indicates the medical aid number of the staff member

nrDependants, an integer that denotes the number of dependants the staff member has

dependants, an array to keep a maximum of six string values, representing the names of the staff member's dependants, and

contribution, a double value that indicates the staff member's medical aid contribution.

In addition, the class should have the following member functions:

A default constructor that initializes all the names to empty strings. All numerical data members should be initialized to 0.

An overloaded constructor that sets name and number to specified values. nrDependants should be set to 0, while all elements in dependants are initialized to empty strings. contribution should be initialized to 1000.

A destructor that does not perform any action.

Accessor functions for member variables name and number.

A member function addDependant() that adds the name of a dependant to dependants; and update the value of nrDependants. Make sure that the number of dependants never exceeds 6. Use the following prototype: void addDependant(const string dependant);

A member function calcContribution() that adds R150.55 to the staff member's medical aid contribution for each dependant, and update member variable contribution accordingly.

An overloaded stream insertion operator << (implemented as a friend function) that outputs all the member variables of a MedicalAidMember object to any file in the following format:

Staff member's name

Staff member's medical aid number

Number of dependants

List of dependants, one name per line

Medical aid contribution in rands and cents.

Demonstrate the class in an application program (main.cpp) that is used to create medical aid records for staff members and then insert these records in a file called MedicalAidData.dat. The program extracts a staff member's first name and last name from a file called Staff.dat, then creates a string representing the staff member's name. It generates a random number to be used as the medical aid number for the staff member. An object member is then instantiated to represent the staff member. The number of dependants the staff member has is obtained from the user and each dependant's name is entered. This is used to update the object member. The staff member's medical aid contribution (based on the number of dependants) is then calculated and updated. Thereafter the object member is inserted into the file MedicalAidData.dat.

Using the input file Staff.dat below and the highlighted input given as shown in the console output below:

Input file Staff.dat:

Peter McConroy

Dumisang Mkhize

Eleanor Esterhuizen

the program produces the following output:

Peter McConroy's medical aid number is 549

How many dependants does this member have? 1

Enter name of dependant: Annie

Dumisang Mkhize's medical aid number is 12100

How many dependants does this member have? 2

Enter name of dependant: Alice

Enter name of dependant: Alex

Eleanor Esterhuizen's medical aid number is 23651

How many dependants does this member have? 0

and should produce the following output file

MedicalAidData.dat:

Peter McConroy

549

1

Annie

R1150.55

Dumisang Mkhize

12100

2

Alice

Alex

R1301.10

Eleanor Esterhuizen

23651

0

R1000.00

Remember that even if you use the same input file, the medical aid number will differ because it is generated as a random number. Submit copies of the input and output files and the console window, as well as all the files in the ADT.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions