Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I cant run this coding ( cant insert data) Please fix the errors. Employee.cpp #

ID: 3838800 • Letter: I

Question

I cant run this coding ( cant insert data)
Please fix the errors.

Employee.cpp

#include <iostream>
#include<string>
#include<iomanip>
#include"Employee.h"
using namespace std;

Employee::Employee(){}
Employee::~Employee() {}
void Employee::login()
{
   string pd, password = "1";
   string un, username = "q";
   bool loginSuccess = false;
   int att = 0;
       while(att<3)
       {
               cout << "Username : ";
               cin >> un;
               cout << "Password : ";
               cin >> pd;
              
               if (username == un && password == pd)
               {
                   cout << " -------------------- ";
                   cout << "Login Successful" << endl;
                   cout << "-------------------- ";
                   loginSuccess = true;
                   break;
               }
               else
                   {
                   cout << " ------------------------ ";
                   cout << "Invalid ID or PASSWORD !" << endl;
                   cout <<" Please try again you have maximum 3 attempt only " << endl;
                   att++;
                   }
               if (att == 3)
               {
                   cout << "You have reach the limit attempt " << endl;
                   exit(-99);
               }
       }
}
void Employee::menu()
{
   system("cls");
   cout << " ";
   cout<<(" ***** Employees Management System 1.0 ***** ");
   cout << endl;
   cout << " ";
   cout << " Press 1---->Built The Employee Table ";
   cout << " ";
   cout << " Press 2---->Display The Employee Table ";
   cout << " ";
   cout << " Press 3---->Add New Entry ";
   cout << " ";
   cout << " Press 4---->Delete An Entry ";
   cout << " ";
   cout << " Press 5---->Search Arecord ";
   cout << " ";
   cout << " Press 6---->Sort The Table ";
   cout << " ";
   cout << " Press 8---------->Quit Program ";
   cout << " ";
}

void Employee::build()
{
   int num;
   Employee emp[max];
   cout<< " Build The Table"<<endl;
   cout << "Maximum number of entries ----- > 20" << endl;
   cout << "How many do you want ----->";
   cin >> num;
   cout << "Enter The Following Items" << endl;
   for (int i = 0; i <= num-1; i++)
   {
       cout << "Name ";
       cin >> emp[i].name;
       cout << "Code ";
       cin >> emp[i].code;
       cout << "Designation ";
       cin >> emp[i].designation;
       cout << "Years of Experience ";
       cin >> emp[i].exp;
       cout << "Age ";
       cin >> emp[i].age;
   }
   cout << "Going to main menu"<<endl;
   system("pause");
}

void Employee::display()
{
   system("cls");
   Employee emp[max];
   cout<<(" ********Display The Table********")<<endl;
   cout << " Name Code Designation Years(EXP) Age " << endl;
   cout << " ------------------------------------------------------" << endl;
   for (int i = 0; i <= num - 1; i++)
   {
       cout << setw(13) << emp[i].name;

       cout << setw(6) << emp[i].code;

       cout << setw(15) << emp[i].designation;

       cout << setw(10) << emp[i].exp;

       cout << setw(15) << emp[i].age;
   }
   cout << "going to main menu"<<endl;
   system("pause");
}

void Employee::add()
{
   system("cls");
   Employee emp[max];
   int i = num;

   cout<<("Insert New Record");
   cout << endl;
   cout << "Enter The Following Items" << endl;
   cout << "Name ";
   cin >> emp[i].name;
   cout << "Code ";
   cin >> emp[i].code;
   cout << "Designation ";
   cin >> emp[i].designation;
   cout << "Years of Experience ";
   cin >> emp[i].exp;
   cout << "Age ";
   cin >> emp[i].age;
   cout << endl << endl;
   cout << "going to main menu";
  
}

void Employee::deletes()
{
   system("cls");
   Employee emp[max], tempemp[max], sortemp[max], sortemp1[max];
   int code;
   int check;
   cout<<("Delete An Entry");
   cout << endl;
   cout << "Enter An JobCode To Delete That Entry ";
   cin >> code;
   int i;
   for (i = 0; i <= num - 1; i++)
   {
       if (emp[i].code == code)
       {
           check = i;
       }
   }
   for (i = 0; i <= num - 1; i++)
   {
       if (i == check)
       {
           continue;
       }
       else
       {
           if (i>check)
           {
               tempemp[i - 1] = emp[i];
           }
           else
           {
               tempemp[i] = emp[i];
           }
       }
   }
   num--;
   for (i = 0; i <= num - 1; i++)
   {
       emp[i] = tempemp[i];
   }
   system("pause");
}

void Employee::search()
{
   system("cls");
   Employee emp[max], tempemp[max], sortemp[max], sortemp1[max];
   cout<<("Welcome To Search Of Employee Database ");
   cout << endl;
   cout << endl;
   int jobcode;
   cout << "You Can Search Only By Jobcode Of An Employee";
   cout << "Enter Code Of An Employee ";
   cin >> jobcode;
   for (int i = 0; i <= num - 1; i++)
   {
       if (emp[i].code == jobcode)
       {
           cout << " Name Code Designation Years(EXP) Age ";
           cout << " ------------------------------------------------------ ";
           cout << setw(13) << emp[i].name;
           cout << setw(6) << emp[i].code;
           cout << setw(15) << emp[i].designation;
           cout << setw(10) << emp[i].exp;
           cout << setw(15) << emp[i].age;
           cout << endl;
       }
   }
   cout << "going to main menu";
   system("pause");
}

Employee.h

#ifndef EMPLOYEE_H
#define EMPLOYEE_H

const int max = 20;

class Employee
{
public:
   Employee();
   ~Employee();
   void login();
   void menu();
   void build();
   void add();
   void deletes();
   void search();
   void display();
  
private:
   char name[20];

   long int code;

   char designation[20];

   int exp;

   int age;
  
   int num;
  
};
#endif

Source.cpp

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

void main()
{
  
   int option;
   Employee m;
  
   m.login();
   m.menu();

   cout << " Select Your Option Please ====> ";
   cin >> option;

   while (option != 8)
   {
       switch (option)

       {
       case 1:
           m.build();
           break;

       case 2:
           m.display();
           break;
  
       case 3:
           m.add();
           break;

       case 4:
           m.deletes();
           break;

       case 5:
           m.search();
           break;

       case 7:
           m.display();
           break;
       default:

           cout << "invalid selection" << endl;
       }
       m.menu();
       cout << " Select Your Option Please ====> ";
       cin >> option;
   }
  
}

Explanation / Answer

#include <iostream>
#include<string>
#include<iomanip>
//#include"Employee.h"
using namespace std;

//
//#ifndef EMPLOYEE_H
//#define EMPLOYEE_H
const int max = 20;

class Employee
{
public:
Employee();
~Employee();
void login();
void menu();
void build();
void add();
void deletes();
void search();
void display();
  
private:
char name[20];
long int code;
char designation[20];
int exp;
int age;
  
int num;
  
};

Employee::Employee(){}
Employee::~Employee() {}
void Employee::login()
{
string pd, password = "1";
string un, username = "q";
bool loginSuccess = false;
int att = 0;
while(att<3)
{
cout << "Username : ";
cin >> un;
cout << "Password : ";
cin >> pd;
  
if (username == un && password == pd)
{
cout << " -------------------- ";
cout << "Login Successful" << endl;
cout << "-------------------- ";
loginSuccess = true;
break;
}
else
{
cout << " ------------------------ ";
cout << "Invalid ID or PASSWORD !" << endl;
cout <<" Please try again you have maximum 3 attempt only " << endl;
att++;
}
if (att == 3)
{
cout << "You have reach the limit attempt " << endl;
exit(-99);
}
}
}
void Employee::menu()
{
system("cls");
cout << " ";
cout<<(" ***** Employees Management System 1.0 ***** ");
cout << endl;
cout << " ";
cout << " Press 1---->Built The Employee Table ";
cout << " ";
cout << " Press 2---->Display The Employee Table ";
cout << " ";
cout << " Press 3---->Add New Entry ";
cout << " ";
cout << " Press 4---->Delete An Entry ";
cout << " ";
cout << " Press 5---->Search Arecord ";
cout << " ";
cout << " Press 6---->Sort The Table ";
cout << " ";
cout << " Press 8---------->Quit Program ";
cout << " ";
}
void Employee::build()
{
int num;
Employee emp[20];
cout<< " Build The Table"<<endl;
cout << "Maximum number of entries ----- > 20" << endl;
cout << "How many do you want ----->";
cin >> num;
cout << "Enter The Following Items" << endl;
for (int i = 0; i <= num-1; i++)
{
cout << "Name ";
cin >> emp[i].name;
cout << "Code ";
cin >> emp[i].code;
cout << "Designation ";
cin >> emp[i].designation;
cout << "Years of Experience ";
cin >> emp[i].exp;
cout << "Age ";
cin >> emp[i].age;
}
cout << "Going to main menu"<<endl;
system("pause");
}
void Employee::display()
{
system("cls");
Employee emp[20];
cout<<(" ********Display The Table********")<<endl;
cout << " Name Code Designation Years(EXP) Age " << endl;
cout << " ------------------------------------------------------" << endl;
for (int i = 0; i <= num - 1; i++)
{
cout << setw(13) << emp[i].name;
cout << setw(6) << emp[i].code;
cout << setw(15) << emp[i].designation;
cout << setw(10) << emp[i].exp;
cout << setw(15) << emp[i].age;
}
cout << "going to main menu"<<endl;
system("pause");
}
void Employee::add()
{
system("cls");
Employee emp[20];
int i = num;
cout<<("Insert New Record");
cout << endl;
cout << "Enter The Following Items" << endl;
cout << "Name ";
cin >> emp[i].name;
cout << "Code ";
cin >> emp[i].code;
cout << "Designation ";
cin >> emp[i].designation;
cout << "Years of Experience ";
cin >> emp[i].exp;
cout << "Age ";
cin >> emp[i].age;
cout << endl << endl;
cout << "going to main menu";
  
}
void Employee::deletes()
{
system("cls");
Employee emp[20], tempemp[20], sortemp[20], sortemp1[20];
int code;
int check;
cout<<("Delete An Entry");
cout << endl;
cout << "Enter An JobCode To Delete That Entry ";
cin >> code;
int i;
for (i = 0; i <= num - 1; i++)
{
if (emp[i].code == code)
{
check = i;
}
}
for (i = 0; i <= num - 1; i++)
{
if (i == check)
{
continue;
}
else
{
if (i>check)
{
tempemp[i - 1] = emp[i];
}
else
{
tempemp[i] = emp[i];
}
}
}
num--;
for (i = 0; i <= num - 1; i++)
{
emp[i] = tempemp[i];
}
system("pause");
}
void Employee::search()
{
system("cls");
Employee emp[20], tempemp[20], sortemp[20], sortemp1[20];
cout<<("Welcome To Search Of Employee Database ");
cout << endl;
cout << endl;
int jobcode;
cout << "You Can Search Only By Jobcode Of An Employee";
cout << "Enter Code Of An Employee ";
cin >> jobcode;
for (int i = 0; i <= num - 1; i++)
{
if (emp[i].code == jobcode)
{
cout << " Name Code Designation Years(EXP) Age ";
cout << " ------------------------------------------------------ ";
cout << setw(13) << emp[i].name;
cout << setw(6) << emp[i].code;
cout << setw(15) << emp[i].designation;
cout << setw(10) << emp[i].exp;
cout << setw(15) << emp[i].age;
cout << endl;
}
}
cout << "going to main menu";
system("pause");
}


int main()
{
  
int option;
Employee m;
  
m.login();
m.menu();
cout << " Select Your Option Please ====> ";
cin >> option;
while (option != 8)
{
switch (option)
{
case 1:
m.build();
break;
case 2:
m.display();
break;
  
case 3:
m.add();
break;
case 4:
m.deletes();
break;
case 5:
m.search();
break;
case 7:
m.display();
break;
default:
cout << "invalid selection" << endl;
}
m.menu();
cout << " Select Your Option Please ====> ";
cin >> option;
}
return 0;
  
}


so here i have fixed your code error

the problem with your code is that you have just defined the functions first and class later so it cant find the class Employee in your code.

You have to first define the class then you can declare the methods then defined the main method of class and then give the defination of functions

or

You have to first define the class then you can declare and define the methods then defined the main method of class in c++ programming

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote