Results 1 to 3 of 3

Thread: C++ problems....

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    39

    C++ problems....

    Hi,

    I am writing a C++ progrma using th following classes

    class CHRAdministrator
    calss Cemployee
    calss CManager
    class CScientist
    class CForeman
    class CLaborer

    I am using these classes to create a Human Resource database of employees. Four types of employees are available: Manager; Scientist; Foreman; Laborer.

    I need teh program to create one CHRAdministrator object that will contain the main menu plus any other submenus that may be required. The four employee type classes need to be derived from CEmployee. CEmployee will be an abstract class. The program also needs to use an array of pointers to CEmployee (the array is a member of CHRadministrator) each pointer will be used to refer to a dynamically created object of one of the employee-derived classes. Additionaly, the employee names and the employee title will be member variables of the abstract class CEmployee and will be dynamically allocated upon construction of an employee-derived object. Upon creating a new employee-derived object, the program will invoke the non-default constructor of both the base class (CEmployee) and the derived class. All program input and output should be performed from the CHRAdministrator object. Between program runs it should save the program data to a file and retrive that data on program startup.

    I also need to add the following main menu in the program.

    1) Add a New Employee
    2)Delete an Employee
    3)Show listing of all employees
    4)Show listing of managers with details
    5)Show listing of scientist with details
    6)Show listing of foremen with details
    7)Show listing of laboreres with details
    8)Show number of employees


    So far have have worked on

    For Forman.cpp

    Code:
    // Foreman.cpp: implementation of the Foreman class.
    //
    //////////////////////////////////////////////////////////////////////
    
    #include "Foreman.h"
    
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////
    
    
    Foreman::Foreman(char* fname, char* mname, char* lname, int ID, char* title) :
    	Employee(fname, mname, lname, ID, title)
    {
    
    }
    
    Foreman::~Foreman()
    {
    
    }
    
    double Foreman::GetSalaryWR()
    {
    	double salary = 0;
    	salary = 55;
    	return salary;
    }
    
    int Foreman::GetSpecialData()
    {
    	return 0;
    }


    For Main.cpp I have this:

    Code:
    #include <iostream>
    #include "HRAdministrator.h"
    using namespace std;
    
    void main()
    {
    	HRAdministrator Me;
    	Me.Administer();
    }
    For Employee.cpp I have this

    Code:
    // Employee.cpp: implementation of the Employee class.
    //
    //////////////////////////////////////////////////////////////////////
    
    #include "Employee.h"
    #include "HRAdministrator.h"
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////
    
    //Employee::Employee()
    //{
    
    	//Employee::GetName();
    //}
    
    Employee::~Employee()
    {
    
    }
    
    Employee::Employee(char* fname, char* mname, char* lname, int ID, char* title)
    {
    	//Creating memory
    	//Must do: Delete memory in destructor
    	m_fname = new char[50];
    	m_mname = new char[50];
    	m_lname = new char[50];
    	m_title = new char[50];
    	strcpy(m_fname, fname);
    	strcpy(m_mname, mname);
    	strcpy(m_lname, lname);
    	strcpy(m_title, title);
    	ID = m_ID;
    	cout << m_fname << '\n';
    	ofstream fout("A:\\CurrentEmployees.txt", ios::app);
    		if (!fout)
    		{
    			cout << "Can not open file.";
    			exit(1);
    		}
    	fout << "Here I am again & again" << '\n';
    	fout.close();
    }
    
    double Employee::GetSalaryWR()
    {
    	return 0;
    }
    
    int Employee::GetSpecialData()
    {
    	return 0;
    }
    
    char* Employee::GetName()
    {
    	//m_lname = "Now I am here";
    	//cout << m_lname;
    	return 0;
    }
    
    char* Employee::GetTitle()
    {
    	return 0;
    }


    For Laborer.cpp I have this

    Code:
    // Laborer.cpp: implementation of the Laborer class.
    //
    //////////////////////////////////////////////////////////////////////
    
    #include "Laborer.h"
    #include <iostream>
    using namespace std;
    
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////
    
    
    Laborer::Laborer(char* fname, char* mname, char* lname, int ID, char* title):
    	Employee(fname, mname, lname, ID, title)
    {
    
    }
    
    Laborer::~Laborer()
    {
    
    }
    
    double Laborer::GetSalaryWR()
    {
    	double salary;
    	double wage = 10;
    	double hours = 40;
    	salary = wage * hours;
    	return salary;
    }
    
    int Laborer::GetSpecialData()
    {
    	return 0;
    }
    For Manager.cpp I have this:

    Code:
    // Manager.cpp: implementation of the Manager class.
    //
    //////////////////////////////////////////////////////////////////////
    
    #include "Manager.h"
    
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////
    
    
    Manager::Manager(char* fname, char* mname, char* lname, int ID, char* title) :
    	Employee(fname, mname, lname, ID, title)
    {
    
    }
    
    Manager::~Manager()
    {
    
    }
    
    double Manager::GetSalary()
    {
    	double salary = 0;
    	salary =100;
    	return salary;
    }
    
    int Manager::GetSpecialData()
    {
    	return 0;
    }
    For Scientist I have this:

    Code:
    // Scientist.cpp: implementation of the Scientist class.
    //
    //////////////////////////////////////////////////////////////////////
    
    #include "Scientist.h"
    
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////
    
    
    Scientist::Scientist(char* fname, char* mname, char* lname, int ID, char* title) :
    	Employee(fname, mname, lname, ID, title)
    {
    
    }
    
    Scientist::~Scientist()
    {
    
    }
    
    double Scientist::GetSalary()
    {
    	double salary = 0;
    	salary = 200;
    	return salary;
    }
    
    int Scientist::GetSpecialData()
    {
    	return 0;
    }




    For HRAdministrator.cpp I have this:

    Code:
    // HRAdministrator.cpp: implementation of the HRAdministrator class.
    //
    //////////////////////////////////////////////////////////////////////
    
    #include "HRAdministrator.h"
    #include "Employee.h"
    #include "Laborer.h"
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////
    
    HRAdministrator::HRAdministrator()
    {
    
    }
    
    HRAdministrator::~HRAdministrator()
    {
    
    }
    
    void HRAdministrator::Menu()
    {
    	Employee *emp = 0;
    	int choice;
    	system("cls");
    
    	//Main Menu
    	cout << "Please select an option:\n"<<
    		"<1> - Add a New Employee\n"<<
    		"<2> - Delete an Employee\n"<<
    		"<3> - Show Listing of all Employees\n"<<
    		"<4> - Show Listing of Managers with Details\n"<<
    		"<5> - Show Listing of Scientists with Details\n"<<
    		"<6> - Show Listing of Foremen with Details\n"<<
    		"<7> - Show Listing of Laborers with Details\n"<<
    		"<8> - Show number of Employees\n"<<
    		"<9> - Exit\n";
    		
    	cin >> choice;
    	while (choice != 0)
    	{
    		
    		int num_employees = 0;
    		//Employee *emp = new Employee();
    		switch (choice)
    		{
    		case 1: //Add Employee
    			system("cls");
    			AddEmployee();
    			system ("pause");
    			break;
    		case 2: //Delete Employee
    			system("cls");
    			DeleteEmployee();
    			system ("pause");
    			break;
    		case 3: //Show All Employees
    			system("cls");
    			ShowAllEmployees();
    			system ("pause");
    			break;
    		case 4: //Show Managers
    			system("cls");
    			ShowManagers();
    			system ("pause");
    			break;
    		case 5: //Show Scientists
    			system("cls");
    			ShowScientists();
    			system ("pause");
    			break;
    		case 6: //Show Foremen
    			system("cls");
    			ShowForemen();
    			system ("pause");
    			break;
    		case 7: //Show Laborers
    			system("cls");
    			//emp = new Laborer(emp);
    			cout<<emp->GetSalaryWR();
    			system ("pause");
    			break;
    		case 8: //Show Number Of Employees
    			system("cls");
    			ShowNumberOfEmployees();
    			system ("pause");
    			break;
    		case 9: //Quit Program
    			system("cls");
    			cout<<"Have A Good Day"<<"\n\n";
    			exit(-1);
    			break;
    		default: //Menu Choice Error
    			system("cls");
    			cout << "INVALID ENTRY\n";
    			system ("pause");
    			Menu();
    			break;
    		}
    		Menu();
    		cin >> choice;
    	}
    }
    
    void HRAdministrator::AddEmployee()
    {
    	char fname[50];
    	char mname[50];
    	char lname[50];
    	int ID;
    	char title[50];
    	
    	cout << "Enter Employee's First Name: ";
    	cin >> fname;
    	cout << '\n' << "Enter Employee's Middle Name: ";
    	cin >> mname;
    	cout << '\n' << "Enter Employee's Last Name: ";
    	cin >> lname;
    	cout << '\n' << "Enter Employee's ID Number: ";
    	cin >> ID;
    	cout << '\n' << "Enter Employee's Title: ";
    	cin >> title;
    	cout << "\n\n" << fname << " " << mname << " " << lname << " "
    		<< ID << " " << title << "\n\n";
    	
    	emp = new Employee(fname, mname, lname, ID, title);
    }
    
    void HRAdministrator::DeleteEmployee()
    {
    
    }
    
    void HRAdministrator::ShowAllEmployees()
    {
    	//Employee *q;
    	//q = new Employee();
    	//cout << q->GetName() << "\n\n";
    }
    
    void HRAdministrator::ShowManagers()
    {
    
    }
    
    void HRAdministrator::ShowScientists()
    {
    
    }
    
    void HRAdministrator::ShowForemen()
    {
    
    }
    
    void HRAdministrator::ShowLaborers()
    {
    	//Laborer *lab;
    	//lab = new Laborer();
    	//cout << lab;
    }
    
    void HRAdministrator::ShowNumberOfEmployees()
    {
    
    }
    
    void HRAdministrator::Administer()
    {
    	ifstream fin("A:\\CurrentEmployees.txt");
    		if (!fin)
    		{
    			cout << "Can not open file.";
    			exit(1);
    		}
    	fin.close();
    	Menu();
    }


    This program is not functioning like it is suposed to. Please any help would be appreciated alot , if need to see the .h file let me know

  2. #2
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Do you have a specific problem?

    I don't think you are going to find anyone to just write your homework here.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    39
    The worst problem I was having was the private constructors in the derived classes. They are commented out for now so I could run the program and work on other parts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width