|
// Employee.h
///////////////////////////////////////////////////////////
#pragma once
#include <string>
#include <iostream>
using namespace std;
class Employee
{
public:
Employee() {}
Employee(string name, string num);
string getName() const;
string getID() const;
void Display() const;
private:
string m_strName;
string m_strID;
};
Employee::Employee(string name, string num) : m_strName(name), m_strID(num) {}
string Employee::getName() const
{
return m_strName;
}
string Employee::getID() const
{
return m_strID;
}
void Employee::Display() const
{
cout << "Name : " << m_strName << endl;
cout << "ID : " << m_strID << endl;
}
///////////////////////////////////
// Workerman.h
//////////////////////////////////
#pragma once
#include "Employee.h"
class WorkerMan : public Employee
{
public:
WorkerMan(string name, string num, int pay = 0, double bonus = 0.0);
int getBasePay() const;
double getBonus() const;
void setBasePay(int newPay);
void setBonus(double newBonus);
void Display() const;
double Calculate(int m) const;
double Pay() const;
private:
int m_iBasePay;
double m_dBonus;
};
WorkerMan::WorkerMan(string name, string num, int pay, double bonus) : Employee(name,num), m_iBasePay(pay),m_dBonus(bonus) {}
int WorkerMan::getBasePay() const
{
return m_iBasePay;
}
double WorkerMan::getBonus() const
{
return m_dBonus;
}
void WorkerMan::setBasePay(int newPay)
{
m_iBasePay = newPay;
}
void WorkerMan::setBonus(double newBonus)
{
m_dBonus = newBonus;
}
void WorkerMan::Display() const
{
Employee::Display();
cout << "Base Pay : " << m_iBasePay << endl;
cout << "Bonus : " << m_dBonus << endl;
}
double WorkerMan::Calculate(int m) const
{
return m_iBasePay * m * 0.01;
}
double WorkerMan::Pay() const
{
return m_iBasePay + m_dBonus;
}
////////////////////////////////////
// Main.cpp
////////////////////////////////////
#include "stdafx.h"
#include "Employee.h"
#include "WorkerMan.h"
#include <iostream>
#include <string>
using namespace std;
void main()
{
string strName = "Bill";
string strID = "1002";
int iBasePay = 3000;
double dBonus = 500.0;
WorkerMan w1(strName, strID, iBasePay, dBonus);
double dNewBonus = w1.Calculate(50);
w1.Display();
WorkerMan* p = &w1;
p->Display();
} |