Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8812239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:33:38+00:00 2026-06-14T03:33:38+00:00

Im having a issue with my employee class. The program itself has a sample

  • 0

Im having a issue with my employee class. The program itself has a sample employee and allows the user to input more employees to the program. The issue I am having is that I can add in 1 new employee and print the list of both the sample employee and the newly added employee, however when i try to add in a second employee and print, the second one with over write the first added employee.

Im not sure if the issue is with the array im using (which has 4 elements, number, first name, last name and department) or if its with the function thats being called, below the code ive done up.

header file:

#include <iostream>
using namespace std;

class employee
{

public :
    employee();
    employee(int, char*, char*, char*); // employee works number, name, department
    void Set( int, char*, char*, char*); // set the number, name and dept
    void Print();
    void printmenu();
    ~employee(); //destructor

private: 
    int e_num; // employee number
    char e_fname[30];
    char e_lname [30];
    char e_dept[30];

}; 

CPP File:

#include <iostream>
#include "employee.h"
using namespace std;


employee::employee() 
{

}

employee::employee(int num, char* fname, char* lname, char* dept)
{
    Set(num, fname, lname, dept);
}

void employee::Set( int num, char* fname, char* lname, char* dept)
{
    if (num < 0 )
    {
    return ; // add in code here to give error message if works is less than 0
    }
    e_num = num;
    strcpy (e_fname, fname);
    strcpy (e_lname, lname);
    strcpy (e_dept, dept);

}

void employee::Print()
{
        cout << e_num <<" \t " << e_fname <<" "<< e_lname <<" \t " << e_dept << " \n";
}

void employee::printmenu()
{
    cout << "EMPLOYEE MENU\n"
         << "~~~~~~~~~~~~~\n"
         << "1. Add New Employee\n"
         << "2. Edit Employee\n"
         << "3. Delete Employee\n"
         << "4. Print Employee List\n"
         << "5. Exit\n";
}

employee::~employee()
{

}

Main:

#include <iostream>
#include "employee.h"
using namespace std;

void main (void)
{
    char input;
    bool done = false;  

    employee emp1(1, "Joe", "Bloggs", "Customer Service");// sample employee
    int empcount = 1;
    employee empnew[20];

    int num, j=0, k=0; // num is employee number
    char* fname = new char [20]; // employee first name
    char* lname = new char [20];  // employee last name
    char* dept  = new char [30]; // employee department


    while(!done)
    {       
    employee pmenu;
    pmenu.printmenu();

    cout <<"Please make your selection:";
    cin >> input;

    switch (input)
    {
    case '1': // add new employee

        cout<<"\nEnter Employee Number:";   
        cin >> num;
        cout<<"\nEnter first name:";
        cin >> fname;
        cout<<"\nEnter Last name:";
        cin >> lname;
        cout << "\nEnter Department:";
        cin >> dept;
        cout << "\n";

        empnew[j].Set(num, fname, lname, dept);
        empcount++;

        cout << "New employee added:"<< fname <<" "<<lname << "\n";
        cout<< "New Number of Employees:" << empcount<< "\n\n";
        break; 

    case '2': //Edit Employee
    // enter stuff here
        break;

    case '3': //Delete Employee
    // enter stuff here
        break;
    case '4': // print employee list

        cout <<"Total number of Employees:"<<empcount<<endl;
        cout <<"Number \t Employee Name \t Department \n" ;

        if (empcount == 1)
        {
            emp1.Print(); 
        }
        else 
        {
            emp1.Print(); 
            empnew[j].Print();//print input
        }
        cout <<"\n";
        break;
    case '5':
        cout << "Program closing\n";
        done = true;
        break;

    }

    }
    getchar();
    return ;
}

(sorry for posting all the code, didnt want to leave something important out)

Ive tried several different ways to get the 2nd (and subsequent employee) to print but which ever way i try to change the array or the function i get errors and the code wont compile.

I thought when added the new employee to use

empnew[j]= new employee (num ,fname,lname,dept); 

but that gives me “Error: no operator “=” matches these operands”

along with many other variations of that which dont work either.

As you might guess ive just started with c++ so any help would be greatly appricated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:33:39+00:00Added an answer on June 14, 2026 at 3:33 am

    You set employee data into empnew[j] array item, yet j variable never changes. Judging from this snippet:

    empnew[j].Set(num, fname, lname, dept);
    empcount++;
    

    probably you should change into to

    empnew[empcount++].Set(num, fname, lname, dept);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created the output for a program that allows a user to input
Having an issue here that I have tried everything I can think of but
I have an issue in Core java. Consider the Employee class having an attribute
Im having a weird issue. My employee table has id ->int(11) as primary key.
I have inherited work from a previous employee. The issue I'm having is a
I having issue that content assistant / intellisense is working in methods such as
I am having some troubles thinking through a design issue and thought that the
Just starting out to program in python and I'm having the following issue. I
I am having an issue with a query which returns results that are very
Having issue with my navigation. How can I prevent it? My CSS file looks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.