0

Employee.h

// Base class.
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include "stdafx.h"
#include <cstring>

// Constant for the name's default size
const int DEFAULT_SIZE = 51;

class Employee
{
private:
   char *name;				// The name
   double empNum;			// The employee number
   int hireDate;			// Number of hire date on hand
   
   // Private member function.
   void createName(int size, char *value)
      { // Allocate the default amount of memory for name.
        name = new char [size];
        
        // Store a value in the memory.
        strcpy(name, value); }

public:
  // Constructor #1
	  Employee()
      { // Store an empty string in the name
        // attribute.
        createName(DEFAULT_SIZE, "");
        empNum = 0.0;
        hireDate = 0; }

   // Constructor #2
   Employee(char *desc, double n, int h)
      { // Allocate memory and store the name.
        createName(strlen(desc), desc); 

        // Assign values to employee number and hire date.
        empNum = n;
        hireDate = h; }      
        
   // Destructor
   ~Employee()
      { delete [] name; }

   // Mutator functions
   void setName(char *d) 
      { strcpy(name, d); }

   void setEmpNum(double n)
      { empNum = n; }
      
   void setHireDate(int h)
      { hireDate = h; }

   // Accessor functions
   const char *getName() const
      { return name; }
         
   double getEmpNum() const
      { return empNum; }

   int getHireDate() const
      { return hireDate; }
};
#endif

ProductionWorker.h

#ifndef PRODUCTIONWORKER
#define PRODUCTIONWORKER
#include "Employee.h

class ProductionWorker : public Employee
{
private:
	int shift;
	double HourlyPayRate;

public:
	void setShift(int);
	void setHourlyPayRate(double);
	int getShift() const;
	double getHourlyPayRate() const;

	// Default Constructor
	ProductionWorker() : Employee() 
	{ shift = 0; }
	
	// Constructor #2
	ProductionWorker(int shift) : 
	Employee(char *desc, double n, int h)
	{ shift = s; }      


		void setShift(int s)
      { shift = s; }

		int getShift() const
      { return shift; }
	
};
#endif

Project6.cpp

// Project 6
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include "Employee.h"
using namespace std;

int main()
{
   // Create an Employee object and call
   // the default constructor.

/*
		ProductionWorker info;
		double rate;

		cout << "How much does the employee make per hour? ";
		cin >> rate;
*/
		char name[100];
		int num;
		int date;
		int shift;

		cout << "What is the employee's name? ";
		cin.getline(name, 100);
		cout << "What is the employee's number? ";
		cin >> num;
		cout << "\n\nWhat is the employee's hire date?\n";
		cout << "Please use the following format:\n";
		cout << "MMDDYYYY\n";
		cin >> date;
		cout << "Does the employee work shift 1 or shift 2? ";
		cin >> shift;

	
	Employee name1;
   name1.setName(name);				// Set the name
   name1.setEmpNum(num);			// Set the employee number
   name1.setHireDate(date);				// Set the hire date
//	name1.setShift(shift);				// Set the shift

   cout << "The employee's information is listed below:\n";
   
   // Display the data for name1.
   cout << "Name: " << name1.getName() << endl;
   cout << "Employee Number: " << name1.getEmpNum() << endl;
   cout << "Hire Date: " << name1.getHireDate() << endl;
//   cout << "Shift: " << name1.getShift() << endl << endl;

   return 0;
}

I can't pass the shift information into the inherited class. The two calls are remarked out in the paragraph above. Any help as to why I can't call the member functions from the inherited class would be appreciated.

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by abhimanipal
0

If you want to pass the shift information you want to make use of the object of the class ProductionWorker. You are trying to pass shift information in the object of class Employee

Edited by abhimanipal: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.