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...
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...
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.
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...
Using C#: Write a class named Employee that has the following properties: Name - The Name...
Using C#: Write a class named Employee that has the following properties: Name - The Name property holds the employee's name IdNumber - The IdNumber property holds the employee's ID number Department - The Department property holds the name of the department in which the employee works Position - The Position property holds the employee's job title The class should have the following overloaded constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate...
Here is the assignment description. * Create a class named 'Account' having the following private attributes...
Here is the assignment description. * Create a class named 'Account' having the following private attributes int accountNumber; double balance; * Write a constructor with parameters for each of the attributes. * Write another constructorwith one parameter for the accountNumber. * Write getter and setter methods for each of the private attributes. * Write a method void credit(double amount) which adds the given amount to the balance. * Write a method void debit(double amount) which subtracts the given amount from...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT