« April 2024 »
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
You are not logged in. Log in
Entries by Topic
All topics  «
Blog Tools
Edit your Blog
Build a Blog
RSS Feed
View Profile
Employee and production Worker Classes
Thursday, 17 April 2008
Employee and Production WOrker Classes

#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <fstream>
using namespace std;

class Employee
{
private:
   char *name;
   int empNo;
   char date[11];
public:
   Employee(){}
   ~Employee(){}
   void printEmp()
   {
      cout << "   Employee's Name      : " << name;
      cout << "\n   Employee's Number    : " << empNo;
      cout << "\n   Employee's Hire Date : " << date;
   }
   void setName()
   {
      char temp[50];
      cout << "   Please enter employee name: ";
      cin.getline(temp, 99);
      int size = strlen(temp);
      name = new char[size];
      strncpy(name, temp, strlen(temp));
      name[size] = '\0';
   }
  
   void setEmpNo()
   {
      int temp;
      bool flag;
      cout << "   Please enter employee number in format XXXXX: ";
      cin >> temp;
      empNo = temp;
   } 
  
   void setDate()
   {
      char temp[11];
      bool flag;
   cout << "   Please enter the date you were hired in format mm/dd/yyyy: ";
      do
      {
         flag = true;
         cin.getline(temp, 11);
         for (int i = 0; i < 11; i++)
         {
            if (i == 2 || i == 5)
            {
               i++;
               break;
            }
            if (!isdigit(temp[i]))
               flag = false;
         }
         if (strlen(temp) != 10)
            flag = false;
            int i = 0;
         }
      while (flag == false);
            for( int i =0; i < 12; i++)
            {
               date[i] = temp[i];
            }
   }  
};

class ProductionWorker : public Employee
{
private:
   double hourlyPay;
   string shift;
public:
   ProductionWorker() {}
   ~ProductionWorker(){}
   void printPay()
   {
      cout << "\n   Employee's Shift  : " << shift;
      cout << "\n   Employee's Hourly Pay  : $" << hourlyPay;
   }
   void setShift()
   {
      int temp;
      do
      {
          cout << "   Please enter your shift, 1 for day and 2 for night: ";
          cin >> temp;
      } while (temp != 1 && temp !=2 );
      if (temp == 1)
      {
               shift = " day";
      }
      else
      {
               shift = " night";
      }
   }
  
   void setPay()
   {
      double temp = 0;
      do
      {
         cout << "   Please enter your hourly pay: ";
         cin >> temp;
         if (hourlyPay < 0)
         {
            cout << "   Invalid data, try again";
         }
      }
      while (temp < 0);
      hourlyPay = temp;
   }


};


void Clear_Screen(void);
void Flush(void);

int main()
{
   ProductionWorker person;
   person.setName();
   person.setEmpNo();
   person.setDate();
   person.setPay();
   person.setShift();
   Clear_Screen();
   person.printEmp();
   person.printPay();

   cout << "\n\n   Thank you for using the program!" << endl;
   Flush();
   cout << "\n\n   Press any key to terminate . . ." << endl;
   getchar();
   return 0;
}


void Clear_Screen(void)
{
   #ifdef _WIN32
      system("cls");
   #else
      system("clear");
   #endif
}


void Flush(void)
{
   int ch;
   do
   {
      ch = getchar();
   }
   while (ch != EOF && ch != '\n');
   clearerr(stdin);
}


Posted by veronicak5678 at 7:29 PM EDT

Newer | Latest | Older