Question

This program is in C++: Write a program to allow the user to: 1. Create two...

This program is in C++:

Write a program to allow the user to:

1. Create two classes. Employee and Departments.

The Department class will have: DepartmentID, Departmentname, DepartmentHeadName.

The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID.

Both of the above classes should have appropriate constructors, accessor methods.

2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3.

Your program should display a menu for the user to do the following:

1. Create Department. Collect all information about a department. Make sure the department ID does not already exist in the array containing Department objects. If it does not, then insert the Department object into the array. When the array is full, display the error message to the user "The array is full, you can not add any more departments"

2. Create Employee. Collect all information about an Employee. Make sure the Employee ID does not already exist in the array containing Employee objects. If it does not, then insert the Employee object into the array. Also make sure that the DepartmentID that the employee belongs also exists. If it does not, then display error message.
When the array is full, display the error message to the user "The array is full, you can not add any more Employees"

3. Write the data to the file. When the user selects this option, dump the information in each array into a separate file.

4. Retrieve data from file. When user selects this option, open each file, load the data from the file into the appropriate array.

5. Display Report: When user selects this option, go through arrays and display the total salary paid for each department. The report should display the department name and the total salary of all employees in that department.

Here is the test cases:

TEST CASE1:

1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 1
Please Enter Department Details:
Department ID : 1
Department Name : Sales
Head of Department : Anna
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 1
Please Enter Department Details:
Department ID : 1
Value must be unique!
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 1
Please Enter Department Details:
Department ID : 2
Department Name : Marketing
Head of Department : Mark
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 1
Please Enter Department Details:
Department ID : 3
Department Name : GlobalSales           
Head of Department : Patil
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 1

The array is full, you can not add any more Departments.
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 2
Please Enter Employee Details:
Employee ID : 1
Employee Name :John
Salary: $45000
Age : 25
Department ID : 1
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 2
Please Enter Employee Details:
Employee ID : 1
Value must be unique!
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 1

The array is full, you can not add any more Departments.
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 2
Please Enter Employee Details:
Employee ID : 2
Employee Name :Susan
Salary: $45000
Age : 26
Department ID : 1
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 2
Please Enter Employee Details:
Employee ID : 3
Employee Name :Adam
Salary: $50000
Age : 24
Department ID : 2
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 2
Please Enter Employee Details:
Employee ID : 4
Employee Name :Manny
Salary: $60000
Age : 26
Department ID : 2
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 2
Please Enter Employee Details:
Employee ID : 5
Employee Name :Maria
Salary: $60000
Age : 23
Department ID : 9
Please enter a valid department ID: 3
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 2
The array is full, you can not add any more Employees.
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 5

Salary Report By Department

Dept         : Sales
Total Salary : $90000

Dept         : Marketing
Total Salary : $110000

Dept         : GlobalSales
Total Salary : $60000
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 9
Please enter a valid choice (1 - 6): 3
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 6
Thank you, goodbye.


TEST CASE 2:

1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 1
Please Enter Department Details:
Department ID : 1
Department Name : Sales
Head of Department : Markus
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 1
Please Enter Department Details:
Department ID : 1
Value must be unique!
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 1
Please Enter Department Details:
Department ID : 2
Department Name : Marketing
Head of Department : Anna
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 2
Please Enter Employee Details:
Employee ID : 1
Employee Name :John
Salary: $45000
Age : 23
Department ID : 1
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 2
Please Enter Employee Details:
Employee ID : 2    
Employee Name :Susan
Salary: $40000
Age : 45
Department ID : 1
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 2
Please Enter Employee Details:
Employee ID : 3
Employee Name :many
Salary: $70000
Age : 34
Department ID : 2
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 5

Salary Report By Department

Dept         : Sales
Total Salary : $85000

Dept         : Marketing
Total Salary : $70000
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 3
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 
4
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 5

Salary Report By Department

Dept         : Sales
Total Salary : $85000

Dept         : Marketing
Total Salary : $70000
1. Create Department
2. Create Employee
3. Write Out Data File
4. Read In Data File
5. Display Salary Report
6. -- Quit -- 
Please make a selection : 6
Thank you, goodbye.

Homework Answers

Answer #1

Here is the solution to above problem in C++. PLEASE GIVE A THUMBS UP!!!

Read the code comments for more information

C++ CODE

#include<iostream>
#include<fstream>
#include<string>
using namespace std;

class Employee
{
   //data members
   private:
       int empId;
       string name;
       double salary;
       int age;
       int deptId;
   public:
       Employee(int empId,string name,double salary,int age,int deptId)
       {
           this->empId=empId;
           this->name=name;
           this->salary=salary;
           this->age=age;
           this->deptId=deptId;
       }
       //constructor for class
       Employee()
       {
          
       }
   //accessor method for the class
   //setter and getter
   int getEmpId()
       {
       return empId;  
       }
   string getName()
   {
       return name;
   }
   double getSalary()
   {
       return salary;
   }
   int getAge()
   {
       return age;
   }
   int getDeptId()
   {
       return deptId;
   }
  
   void setEmpId(int id)
   {
       empId=id;  
   }
   void setName(string name)
   {
       this->name=name;
   }
   void setSalary(double sal)
   {
       salary=sal;
   }
   void setAge(int a)
   {
       age=a;
   }
   void setDeptId(int dept)
   {
       deptId = dept;
   }
  
};

class Department
{
   private:
       int deptId;
       string name;
       string headName;
   public:
       //constructor
       Department()
       {
          
       }
       //parameterized constructor
       Department(int deptId, string name,string headName)
       {
           this->deptId= deptId;
           this->name=name;
           this->headName=headName;
       }
      
       //accerssor methods for the class
       //setter and getter
           int getDeptId()
   {
       return deptId;
   }
       void setDeptId(int dept)
   {
       deptId = dept;
   }
       void setName(string name)
   {
       this->name=name;
   }
       string getName()
   {
       return name;
   }
  
   void setHeadName(string name)
   {
       this->headName=name;
   }
       string getHeadName()
   {
       return headName;
   }  
};


int main()
{
   //employee array with size 5
   Employee E[5];
   //department array wiht size 3
   Department D[3];
   int choice=0;
   int indexD=0;
   int indexE=0;
   //display the menu to the user
   while(choice!=6)
   {
       cout<<"1. Create Department\n";
       cout<<"2. Create Employee\n";
       cout<<"3. Write Out Data File\n";
       cout<<"4. Read In Data File\n";
       cout<<"5. Display Salary Report\n";
       cout<<"6. Quit\n";
       cout<<"Please make a selection: ";
       cin>>choice;
      
       switch(choice)
       {
           case 1:
           {
               int id;
               bool flag=false;
               //if array is full
               if(indexD==3)
               {
                   cout<<"The array is full you cannot add more entry\n";
                   break;
               }
               string name;
               string headName;
               cout<<"Enter the Department ID: ";
               cin>>id;
                   //check if the department already exists
               for(int i=0;i<indexD;++i)
               {
                   if(id == D[i].getDeptId())
                   flag=true;
               }
              
               //if dept does exists
               if(flag==true)
               {
                   cout<<"Value must be Unique!\n";
                   break;
               }
               cout<<"Enter the Department Name: ";
               cin>>name;
               cout<<"Enter the Department Head Name: ";
               cin>>headName;
          
                   //if dept does not exists
               if(flag==false)
               {
                       Department temp(id,name,headName);
                       D[indexD++]=temp;  
               }
              
           }
           break;
          
           case 2:
           {
               int id;
               string name;
               double salary ;
               int age;
               int deptId;
               bool flag=false;
               //if array is full
               if(indexE==5)
               {
                   cout<<"The array is full, you cannot add more entry\n";
                   break;
               }
          
               cout<<"Enter the Employee ID: ";
               cin>>id;
                   //check if the employee already exists
               for(int i=0;i<indexE;++i)
               {
                   if(id == E[i].getEmpId())
                   flag=true;
               }
              
               //if emp does exists
               if(flag==true)
               {
                   cout<<"Value must be Unique!\n";
                   break;
               }
               cout<<"Enter the Employee Name: ";
               cin>>name;
               cout<<"Enter the Employee age: ";
               cin>>age;
               cout<<"Enter the Employee Salary: $";
               cin>>salary;
               cout<<"Enter the Employee Department Id: ";
               cin>>deptId;
              
          
                   //if dept does not exists
               if(flag==false)
               {
                   bool flagForDept=false;
                   //check if dept exists
                   for(int i=0;i<indexD;++i)
                   {
                       if(deptId==D[i].getDeptId())
                           flagForDept=true;
                   }
                   if(flagForDept==true)
                   {
                       Employee temp(id,name,salary,age,deptId);
                       E[indexE++]=temp;
                   }
                   else
                   {
                   cout<<"Please enter a valid department Id: ";
                   cin>>deptId;
                   Employee temp(id,name,salary,age,deptId);
                   E[indexE++]=temp;
                  
                   }
               }
           }
           break;
           case 3:
               {
                   ofstream foutE("employee.txt");
                   ofstream foutD("department.txt");
                  
                   //wriete employee data
                   for(int i=0;i<indexE;++i)
                   {
                       foutE<<E[i].getEmpId()<<endl;
                       foutE<<E[i].getName()<<endl;
                       foutE<<E[i].getSalary()<<endl;
                       foutE<<E[i].getAge()<<endl;
                       foutE<<E[i].getDeptId()<<endl;
                   }
                   foutE.close();
                   //write department data
                   for(int i=0;i<indexD;++i)
                   {
                       foutD<<D[i].getDeptId()<<endl;
                       foutD<<D[i].getName()<<endl;
                       foutD<<D[i].getHeadName()<<endl;
                   }
                   foutD.close();
               }
               break;
           case 4:
               {
                   ifstream fine("employee.txt");
                   ifstream find("department.txt");
                   int ie=0;
                   int ide=0;      
               int id;
               string name;
               double salary ;
               string headName;
               int age;
               int deptId;
                   while(fine>>id)
                   {
                       fine>>name;
                       fine>>salary;
                       fine>>age;
                       fine>>deptId;
                       Employee temp(id,name,salary,age,deptId);
                       E[ie++]=temp;
                   }
                   fine.close();
                  
                   while(find>>id)
                   {
                       find>>name;
                       find>>headName;
                       Department temp(id,name,headName);
                       D[ide++]=temp;
                   }  
                   find.close();
                  
                   indexE=ie;
                   indexD=ide;
               }
               break;
           case 5:
               {
               cout<<"Salary Report by Department\n";
               for(int i=0;i<indexD;++i)
               {
                   cout<<"Dept: "<<D[i].getName()<<endl;
                   double sum=0;
                   for(int j=0;j<indexE;++j)
                   {
                       if(E[j].getDeptId()==D[i].getDeptId())
                           sum+=E[j].getSalary();
                   }
                   cout<<"Total Salary: $"<<sum<<endl;
               }
               }
               break;
               case 6:
                   {
                       cout<<"Thank you, goodbye\n";
                   }
                   break;
               default:
                   {
                       cout<<"Please enter a valid choice(1-6):\n";
                   }
       }
   }
      
   return 0;
}


SCREENSHOT OF OUTPUT

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
Lab 6    -   Program #2   -   Write one number to a text file. Use the write()...
Lab 6    -   Program #2   -   Write one number to a text file. Use the write() and read() functions with binary                                                        data, where the data is not char type.              (Typecasting is required) Fill in the blanks, then enter the code and run the program. Note:   The data is int type, so typecasting is            required in the write() and read() functions. #include <iostream> #include <fstream> using namespace std; int main() {    const int SIZE = 10;   ...
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter...
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter 10 numbers. 2. save those numbers in a 32-bit integer array. 3. Print the array with the same order it was entered. 3. Calculate the sum of the numbers and display it. 4. Calculate the mean of the array and display it. 5. Rotate the members in the array forward one position for 9 times. so the last rotation will display the array in...
Write a program which: Write a program which uses the following arrays: empID: An array of...
Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to hold each employee’s gross salary....
write C++ programs Array of Payroll Objects Design a PayRoll class that has data members for...
write C++ programs Array of Payroll Objects Design a PayRoll class that has data members for an employee’s hourly pay rate and number of hours worked. Write a program with an array of seven PayRoll objects. The program should read the number of hours each employee worked and their hourly pay rate from a file and call class functions to store this information in the appropriate objects. It should then call a class function, once for each object, to return...
Could you script in Matlab : Script Name General Algorithm AddNewEmployee Display all of the ID...
Could you script in Matlab : Script Name General Algorithm AddNewEmployee Display all of the ID numbers currently in use Read in a new ID number If the ID number read in is already in use Report this fact End this script Else (this is a new ID number) Read in: Years with the company Salary Vacation days Sick days Add this new employee to the database (by appending a new row to the end of the EmployeeData matrix) Note...
create a complete C++ program that will read from a file, "studentInfo.txt", the user ID for...
create a complete C++ program that will read from a file, "studentInfo.txt", the user ID for a student (first letter of their first name connected to their last name i.e. jSmith). Next it will need to read three integer values that will represent the 3 e xam scores the student got for the semester. Once the values are read and stored in descriptive variables it will then need to calculate a weighted course average for that student. Below is an...
Write a Java program that reads employee information from the file “employee.txt” then the program will...
Write a Java program that reads employee information from the file “employee.txt” then the program will display his/her information on the screen. The file contains the Employee’s Name, age,join date, quit date, and salary. • For each year the employee is in the company,10 days of sick leave are allowed. So, if an employee is in the company for two years, 20 days of sick leave are allowed. • For each year the employee is in the company, one-month salary...
C++ create a program that: in main: -opens the file provided for input (this file is...
C++ create a program that: in main: -opens the file provided for input (this file is titled 'Lab_HW10_Input.txt' and simply has 1-10, with each number on a new line for 10 lines total) -calls a function to determine how many lines are in the file -creates an array of the proper size -calls a function to read the file and populate the array -calls a function to write out the contents of the array in reverse order *output file should...
Write program in C#. WAP on Encapsulation to hide the type members with private access and...
Write program in C#. WAP on Encapsulation to hide the type members with private access and display employee details. • Create a new project, select console application from the template and name the project as “EmployeeDetails.cs”. • Here type members are nothing but properties. • Create another class as Employee and write the properties for EmpId, EmpName and Salary. • Now, create an instance of the Employee class in the “EmployeeDetails” class and assign the values for EmpId,EmpName and Salary...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT