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

Question1: The main purpose of this assignment is to make sure you are familiar

ID: 3691534 • Letter: Q

Question

Question1: The main purpose of this assignment is to make sure you are familiar with C-string, String class, and classes in general. The old C-strings are being used a lot in the existing applications, so it is important to know how it works. Feel free to use c-strings or string class. In addition, it is important that you know how to use functions to structure your program. If you know how to read from a file, you can write our own code to deal with the file. If not, we are providing one for you below.

[2] Description: In this assignment you are going to build a simple computer application for a company to keep track of their employees. This application needs to keep track of all employees the company has. The user of the application should be able to, search by name, search by ID, and print a list of all employees

Define a structure for “employee”, with the following members: Employee first name, array of character of size 30,
Last name, array of character of size 30,
A double for hourly salary rate

An integer for employee ID

Define a class called “company”, with the following members:
An array of all the employees.
An integer for the number of employees;
insert(), takes names and salary and adds the employee into the company search() searches by employee ID and prints out info

search() searches by last name, prints out info print(), prints all employees of the company

Restrictions:

The search function must be overloaded (see company class above).

Must define a structure and a class as specified.

You can choose the type of strings to us.

You can use the readIn() function (below) or not.

You must implement all member fields of the class as "private".

You may assume the maximum number of employees is 100.

Explanation / Answer

#include<iostream .h>
#include<stdio.h>
#include<string.h>

struct Employee
{
    int EmpId;
   char Firstname[30];
   char Lastname[30];
   double salary;
};
class Company
{
private:

   Employee E[100];
   int numemp;
void insert ();
void print();
void search(int empid);
void search(char lastname[30]);
};
void Company :: insert()//storing records
{
   int numemp =0;
for(int i=0;i<100;i++)
   cout<<"enter empid";
   cin>>E[i].empid;
   cout<<"Enter first name";
   cin>>E[i].Firstname;
   cout<<"Enter last name";
   cin>>E[i].Lastname;
   cout<<"enter Salary";
   cin>>E[i].salary;
numemp ++;
}
cout<< " THE NUMBER OF EMPLOYEE RECORDS ARE :"count;
}
void Company:: print()//display records
{
    cout<<" EmpId "<<"Firstname"<<"Lastname"<<"salary"<<" ";
   for(int i=0;i<100;i++)
{
  
     cout<<E[i].Empid<<E[i].Firstname<<E[i].Lastname<<E[i].salary;
}
}  

void Company::search(int empid)//search by empid
{
    int eid=empid;
    for(int i=0i<100;i++)
{
  
      if(E[i].empid==eid)
       {
          cout<<"Found empid";
         cout<<"Employee information";
          cout<<"E[i].Empid<<E[i].Firstname<<E[i].Lastname<<E[i].salary;
  
        }
}
else
{
cout<<"invalid empid";
exit(0);
}

}

void Company:: search(char Lastname[30]) // search by lastname
{
    char L[30]=Lastname;
    for(int i=0;i<100;i++)
{
    if(E[i].Lastname==L)
     {
       cout<<"employee information";
       cout<<E[i].Empid<<E[i].Firstname <<E[i].Lastname<<E[i].salary;
     }
}
else
{
cout<<"invaild lastname";
exit(0);
}

}       

void main()
{

Company obj= new obj1;
int opt,x;
char xyz[30];
cout<<"enter details to store:";
cout<<"choose
       1. To insert 2.Display 3.Search by id 4. search by name 5. Exit";
cin>>opt;
switch(opt)
{
   case 1:
        cout<<"to read ";
              obj.insert();
           break;
case 2:
   cout<<"to display";
       obj.print();
        break;
case 3:
   cout<<"to search by id";
         cin>>x;
         obj.search(x);
          break;
case 4:
   cout<<"to search by name";
   cin>>xyz;
      obj.search(xyz);
   break;
case 5:
       exit(0);
default:
         cout<<"invaild option";
}
}
      

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