Question

In: Computer Science

This assignment will test your knowledge and skills in C++. Create a class named employee and...

This assignment will test your knowledge and skills in C++.

  1. Create a class named employee and have the data members of:
    1. Name
    2. ID
    3. Salary
  2. Create a class named manager that inherits the employee class and adds the data members:
    1. Managed_Employees (Array of up to 3 employees)
    2. Department
  3. Create methods to update each data member in the employee class.
  4. Create a method to print out the managed employees sorted by their salary in the manager class. (You can use one of the sorting algorithms we learned)

Solutions

Expert Solution

/* CAN BE IMPLEMENTED IN MULTIPLE WAYS ONE OF THE WAY IS BELOW */

/* NOTE SORTING IS BASED ON ASCENDING OF SALARY FOR DESCENDING CHANGE IT TO > TO < */

#include<iostream>
using namespace std;
class employee{
   private:
       string Name;
       int ID;
       double Salary;
   public:
       // methods to update data member of employee class
       void setName(string name){
           this->Name = name;
       }
       void setID(int ID){
           this->ID = ID;
       }
       void setSalary(double Salary){
           this->Salary = Salary;
       }
       string getName(){
           return Name;
       }
       int getID(){
           return ID;
       }
       double getSalary(){
           return Salary;
       }
};
class manager: public employee{
   private:
       employee Managed_Employees[3]; // CREATE ARRAY
       string Department; // CREATE VARIABLE
   public:
       void getEmployeesInfo();
       void printInfo();
};
void manager::getEmployeesInfo(){ // GET EMPLOYEES INFO
   cout<<"Enter 3 employees info\n";

// DECLARE VARIABLE
   string name;
   int id;
   double salary;
   for(int i = 0; i < 3; i++){
       cout<<"\nEnter data for "<<i+1<<" Employee\n";
       cout<<"Enter Name: ";
       cin >> name;

// SET ARRAY VALUE
       Managed_Employees[i].setName(name);
       cout<<"Enter ID: ";
       cin >> id;
       Managed_Employees[i].setID(id);
      
       cout<<"Enter Salary: ";
       cin >> salary;
       Managed_Employees[i].setSalary(salary);
                  

   }  
}
void manager::printInfo(){
   // bubble sort
   for(int i = 0; i < 3; i++){
       for(int j = 0; j < 3-i-1; j++){
           if(Managed_Employees[j].getSalary() > Managed_Employees[j+1].getSalary()){
               employee obj = Managed_Employees[j];
               Managed_Employees[j] = Managed_Employees[j+1];
               Managed_Employees[j+1] = obj;
           }
       }
   }
   // display Info
   cout<<"Name\tID\t\tSalary\n";
   for(int i = 0 ; i < 3; i++){
       cout<<Managed_Employees[i].getName()<<"\t"<<Managed_Employees[i].getID()
       <<"\t\t"<<Managed_Employees[i].getSalary()<<"\n";
   }
}
int main(){
   manager obj; // CREATE OBJECT
   obj.getEmployeesInfo(); // GET INFO
   obj.printInfo(); // PRINT INFO
}

/* PLEASE UPVOTE */


Related Solutions

Create a class named Employee and its child class named Salesperson. Save each class in its...
Create a class named Employee and its child class named Salesperson. Save each class in its own file. Name your class and source code file containing the main method homework.java. Make sure each class follows these specifications: 1. An employee has a name (String), employee id number (integer), hourly pay rate (double), a timesheet which holds the hours worked for the current week (double array) and email address (String). A salesperson also has a commission rate, which is a percentage...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
Write in C++ language. (Employee Record): Create a class named 'Staff' having the following members: Data...
Write in C++ language. (Employee Record): Create a class named 'Staff' having the following members: Data members - Id – Name - Phone number – Address - AgeIt also has a function named 'printSalary' which prints the salary of the staff.Two classes 'Employee' and 'Officer' inherits the 'Staff' class. The 'Employee' and 'Officer' classes have data members 'Top Skill' and 'department' respectively. Now, assign name, age, phone number, address and salary to an employee and a officer by making an...
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS...
write a C++ program to CREATE A CLASS EMPLOYEE WITH YOUR CHOICE OF ATTRIBUTES AND FUNCTIONS COVERING THE FOLLOWING POINTS: 1) COUNTING NUMBER OF OBJECTS CREATED ( NO OBJECT ARRAY TO BE USED) USING ROLE OF STATIC MEMBER 2) SHOWING THE VALID INVALID STATEMENTS IN CASE OF STATIC MEMBER WITH NON STATIC MEMBER FUNCTION, NON STATIC MEMBERS OF CLASS WITH STATIC MEMBER FUNCTION, BOTH STATIC. SHOW THE ERRORS WHERE STATEMENTS ARE INVALID. 3) CALL OF STATIC MEMBER FUNCTION, DECLARATION OF...
Write a tester program to test the mobile class defined below. Create the class named with...
Write a tester program to test the mobile class defined below. Create the class named with your id (for example: Id12345678) with the main method. Create two mobiles M1 and M2 using the first constructor. Print the characteristics of M1 and M2. Create one mobile M3 using the second constructor. Change the id and brand of the mobile M3. Print the id of M3. Your answer should include a screenshot of the output. Otherwise, you will be marked zero for...
In C++ Write a class named TestScores. The class constructor should accept an array of test...
In C++ Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a member function that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an exception. Demonstrate the class in program.
in c#: Create a class named Square that contains fields for area and the length of...
in c#: Create a class named Square that contains fields for area and the length of a side and whose constructor requires a parameter for the length of one side of a Square. The constructor assigns its parameter to the length of the Square’s side field and calls a private method that computes the area field. Also include read-only properties to get a Square’s side and area. Create a class named DemoSquares that instantiates an array of ten Square objects...
Create a file named StudentArrayList.java,within the file create a class named StudentArrayList. This class is meant...
Create a file named StudentArrayList.java,within the file create a class named StudentArrayList. This class is meant to mimic the ArrayList data structure. It will hold an ordered list of items. This list should have a variable size, meaning an arbitrary number of items may be added to the list. Most importantly this class should implement the interface SimpleArrayList provided. Feel free to add as many other functions and methods as needed to your class to accomplish this task. In other...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT