Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help with C++ Programming : Objective: The main goal is to implement a simple in

ID: 3839889 • Letter: H

Question

Help with C++ Programming :

Objective: The main goal is to implement a simple inheritance hierarchy between the Person and Employee class.

Description. Declare and implement the Employee class as a derived class of the Person class, which is already implemented in the demo code posted under this week (week #15). Note that your project doesn't need to include the Student class. Please also feel free to modify the Person class. For instance, you can replace the data type for birthday to string.

Specifically, your project will include Person as the base class, and Employee as the derived class of Person. Your Employee class will include the following data members:

year of employment (e.g., 2012)

base salary

a dynamic array to keep track of the annual salary increase rate since the year of employment. For instance, an employee joined the company in year 2013, his salary increase rates in 2014, 2015, and 2016 were 10%, 7%, and 11%, respectively. This dynamic array will then hold the following three numbers: 0.1, 0.07, and 0.11. Furthermore, let bSal be the base salary, the current salary of the above employee should be equal to: bSal*1.10*1.07*1.11. Note that although the size of this array is derivable from the year of employment, you are recommended to include two additional data members to manage the capacity and size of this array. (This is similar to what you did in the previous homework.)

At the minimum, your Employee class needs to include the following function members:

a default constructor

the big-3: destructor, copy constructor and overloaded assignment operator

an accessor to return the current salary of an employee

an accessor and mutator for each of the above data members. It's sufficient to return the salary increase rate in a specific year.

an overloaded put operator (<<) to print out all the information in an Employee object

override the output() function in the base class, as this function is virtual in Person.   

Please provide a simple character-based interface to allow the graders to test each of the above member functions. Make sure you test the output() function using Person pointers and observe polymorphism in action.

Submission requirements: Please use separate compilation and submit your source code in one zip files. Your project will include two header files (one for the Person class, the other for the Employee class) and three .cpp files.

Explanation / Answer

Answer:


File Name: Person.h
#ifndef _PERSON_H
#define _PERSON_H

#include <iostream>
#include <string>


using namespace std;

class Person{
public:
//equalID() returns true:have the same ID; false: otherwise
friend bool equalID(const Person & person1, const Person &Person2);//
~Person(); //destructor: to release any memory that has been allocated to the object
Person(); //default constructor: id=-1, name="NA", birthday="1/1/2000"
Person( int new_id, string new_name, string date); //constructor that initializes
//id to new_id, name to new_name, and birthday to date
Person(const Person & someone); //copy constructor: construct a new object as a copy of "someone"
void operator= (const Person &rhs); //assign the object on the right-hand-side to the left-hand-side
  
int get_id() const; //return the id of a Person object
string get_name() const; //return the name of a Person object
const string get_birthday() const; //return the birthday of a Person object
  
void set_id(int new_id); //change a person's id to new_id
void set_name(string new_name); // change a person's name to new_name
void set_birthday(string new_Date); //change a person's birthday to new_date
  
protected:
int id;
string name;
string birthday;
  
};

void print( const Person& someone); //print out a person's id and name

#endif


File Name: Person.cpp
#include "Person.h"
Person::~Person()
{
  
}

Person::Person()
{
id = -1;
name ="NA";
birthday = "1/1/2017";   
}

Person::Person(int new_id, string new_name, string date)
{
id = new_id;
name = new_name;
birthday = date;
  
}

/**/
Person::Person(const Person & someone)
{
id = someone.id;
name = someone.name;
birthday = someone.birthday;
  
}
/**/
/**/
void Person::operator =(const Person & rhs)
{
id = rhs.id;
name = rhs.name;
birthday = rhs.birthday;
  
}


int Person::get_id() const
{
return id;
}

string Person::get_name() const
{

return name;
}

const string Person::get_birthday() const
{
return birthday;
}

void Person::set_id(int new_id)
{
id = new_id;
}

void Person::set_name(string new_name)
{
name = new_name;
}

void Person::set_birthday(string date)
{
birthday = date;
}

void print(const Person& someone)
{
   cout << "****"<<someone.get_id() << " " << someone.get_name() <<endl;
   cout<<"someone.get_birthday()<<endl;
}


bool equalID(const Person& person1, const Person& person2)
{
return (person1.id == person2.id);
}


File Name: Employee.h
#ifndef _EMPLOYEE_H
#define _EMPLOYEE_H
#include "Person.h"
#include <iostream>
#include <string>
class Employee:public Person
{
private:
int joinedYear;
double bSal;
double *increaseRate;
int capacity;
int size;

public:
Employee();
Employee(int new_id, string new_name, string date,int jyear,double bsal);
Employee(const Employee & someone);
void operator =(const Employee & rhs);
double getCurrentSalary();
void setJoinedYear(int year);
void addIncreaseRate(double newRate);
int getJoinedYear();
friend ostream &operator <<(ostream &cout, const Employee & rhs);
}
#endif


File Name: Employee.cpp

#include <iostream>
#include "Employee.h"
Employee::Employee():Person()
{
joinedYear=0;
bSal=0;
capacity=100;
increaseRate=new double[capacity];
size=0;
}
Employee::Employee(int new_id, string new_name, string date,int jyear,double bsal):Person(new_id, new_name, date)
{
joinedYear=jyear;
bSal=bsal;
capacity=100;
increaseRate=new double[capacity];
size=0;
}

Employee::Employee(const Employee & someone):Person(someone.get_id(), someone.get_name(), someone.get_birthday())
{
joinedYear=someone.joinedYear;
bSal=someone.bSal;
capacity=someone.capacity;
increaseRate=new double[capacity];
for(int kk=0;kk<someone.size;kk++)
increaseRate[kk]=someone.increaseRate[kk];
size=someone.size;
}
void Employee::operator =(const Employee & someone):Person(someone.get_id(), someone.get_name(), someone.get_birthday())
{
joinedYear=someone.joinedYear;
bSal=someone.bSal;
capacity=someone.capacity;
increaseRate=new double[capacity];
for(int kk=0;kk<someone.size;kk++)
increaseRate[kk]=someone.increaseRate[kk];
size=someone.size;
}
double Employee::getCurrentSalary()
{
double tmp=bSal;
double rate=1;
if(size>0)
{
for(int kk=0;kk<size;kk++)
rate=rate *(1+increaseRate[kk]);
tmp=bSal*rate;
}
return tmp;


}
void Employee::setJoinedYear(int year)
{
joinedYear=year;
}

void Employee::addIncreaseRate(double newRate)
{
if(size<capacity)
{
increaseRate[size]=newRate;
size++;
}
}
int Employee::getJoinedYear()
{
return joinedYear;
}

ostream& operator <<(ostream &cout, const Employee & rhs)
{
cout<<"Id:"<<rhs.get_id()<<endl;
cout<<"Name:"<<rhs.get_name()<<endl;
cout<<"Birthday:"<<rhs.get_birthday()<<endl;
cout<<"Joined Year:"<<rhs.getJoinedYear()<<endl;
cout<<"Base Salary:"<<rhs.bSal()<<endl;'
cout<<"Current Salary:"<<rhs.getCurrentSalary()<<endl;
return cout;
}


File Name: main.cpp

#include <iostream>
#include "Person.h"
#include "Employee.h"
#include <string>
using namespace std;
int main()
{
Employee myEmployee(123, "Tom","1/12/1987",2013,1000);
myEmployee.addIncreaseRate(.10);
myEmployee.addIncreaseRate(.07);
myEmployee.addIncreaseRate(.11);
cout<<myEmployee<<endl;
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote