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

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...
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...
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.
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...
Create a custom Exception named IllegalTriangleSideException. Create a class named Triangle. The Triangle class should contain...
Create a custom Exception named IllegalTriangleSideException. Create a class named Triangle. The Triangle class should contain 3 double variables containing the length of each of the triangles three sides. Create a constructor with three parameters to initialize the three sides of the triangle. Add an additional method named checkSides with method header - *boolean checkSides() throws IllegalTriangleSideException *. Write code so that checkSides makes sure that the three sides of the triangle meet the proper criteria for a triangle. It...
Create a custom Exception named IllegalTriangleSideException. Create a class named Triangle. The Triangle class should contain...
Create a custom Exception named IllegalTriangleSideException. Create a class named Triangle. The Triangle class should contain 3 double variables containing the length of each of the triangles three sides. Create a constructor with three parameters to initialize the three sides of the triangle. Add an additional method named checkSides with method header - *boolean checkSides() throws IllegalTriangleSideException *. Write code so that checkSides makes sure that the three sides of the triangle meet the proper criteria for a triangle. It...
In java Create a class named CellPhoneCase that extends your Case class – it inherits all...
In java Create a class named CellPhoneCase that extends your Case class – it inherits all the fields and methods from the Case class. It should also contain:  One field for a CellPhone object. Be sure to put in the appropriate access modifier. (private, public)  A constructor with 3 parameters – owner’s name, Case color, the phone number of the cell phone that will be in the Case. This constructor MUST call the super class’s constructor. Then set...
c++ Create a class named EvolutionTree which will hold a list of species and their expected...
c++ Create a class named EvolutionTree which will hold a list of species and their expected age, and allow a user to search for a particular species or an age. EvolutionTree should have private data members: species (a string array of size 400 with all the species) speciesAges (an int array of size 400 for all the species' ages). EvolutionTree should have a default constructor which should initialize the species array to empty strings ("") and initialize the speciesAges array...
In java: -Create a class named Animal
In java: -Create a class named Animal
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT