Question

In C++ please! Thanks! Define a class Employee with data members as int employee_id – To...

In C++ please! Thanks!

Define a class Employee with data members as

  • int employee_id – To store employee ID.
  • String employee_name – To store the name of the employee.

Define class Salary which inherits Employee class and has the following characteristics

  • Data members
    • String designation – To store employee designation.
    • double monthly_salary – To store salary of the employee.
  • Methods
    • constructor Salary(int employee_id, String employee_name, String designation, double monthly_salary) – Invokes a superclass constructor and initialize data members.
    • void display() – To display details of employees whose earning is more than 20,000. Details of an employee should be separated by spaces.


Input
   3
   123
   John
   engineer
   40000
   124
   Emma
   Testing
   33000
   125
   White
   Trainee Engineer
   20000

   where,

  • First line represents the number of employees whose details are provided.
  • Second line represents employee ID.
  • Third line represents employee name.
  • Fourth line represents designation of the employee.
  • Fifth line represents employee salary per month.
  • The remaining lines represent the details of the remaining employees in the same format as given above.

Output
   123 John engineer 40000.0
   124 Emma Testing 33000.0

The output displayed details of employees who earn more than 20,000.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code-

#include<bits/stdc++.h>
using namespace std;
class Employee{ //super class Employee
   public: //public data members and methods
       int employee_id;
       string employee_name;
       //constructor
       Employee(int employee_id,string employee_name){
       this->employee_id=employee_id;
       this->employee_name=employee_name;
       }
};
class Salary :public Employee { //inherits Employee class publically
   public:
   //Salary class data members
   string designation;
   double monthly_salary;
   //constructor of Salary class and calling constructor of parent class
   Salary(int employee_id, string employee_name, string designation, double monthly_salary):Employee(employee_id,employee_name){
   this->designation=designation;
   this->monthly_salary=monthly_salary;
   }
   //display function
   void display(){
   if(monthly_salary>20000){//if salary greather than 20000 then only display
   cout<<"Output is "<<employee_id<<" "<<employee_name<<" "<<designation<<" "<<monthly_salary<<endl;
   }
   }
};
int main(){
   int number_of_employees;
   cout<<"enter the number of employees";
   cin>>number_of_employees;
  
   int empid;
   string empname;
   string desig;
   double income;
  
   for(int i=0;i<number_of_employees;i++){
       cin>>empid>>empname>>desig>>income;
       Salary s(empid,empname,desig,income);// salary class object
       s.display();
   }
}

//note-i have removed space between Trainee and Engineer so that it can go to same data variable

Add a comment
Know the answer?
Add Answer to:
In C++ please! Thanks! Define a class Employee with data members as int employee_id – To...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ please need help with this question Consider a class Employee with data members: age(an integer),...

    c++ please need help with this question Consider a class Employee with data members: age(an integer), id (an integer) and salary (a float), and their corresponding member functions as follows: class Employee {        private:             int age;             int id;             float salary;        public:             Employee( ); // default constructor: age=0, id=0, and salary=0             Employee(Employee &x);   // copy constructor           Employee& operator = (Employee &x); // equal sign operator             void setAge(int x);    // let age = x...

  • Using C++, Write a class named Employee that has the following member variables: name. A string...

    Using C++, Write a class named Employee that has the following member variables: name. A string that holds the employee's name. idNumber. An int variable that holds the employee's ID number. department. A string that holds the name of the department where the employee works. position. A string that holds the employee's job title. The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee's name,...

  • Define a class named Employee . Derive this class from the class Person. An employee record...

    Define a class named Employee . Derive this class from the class Person. An employee record inherits an employee's name from the class Person. In addition, an employee record contains an annual salary (represented by a single value of type double), a hire date that gives the year hired (as a single value of type int), an identification number of type int, and a department of type String. Give your class a reasonable complement of constructors, accessors, mutators, an equals...

  • C++ Program 2 Consider a class Employee with data members: age (an integer), id (an integer)...

    C++ Program 2 Consider a class Employee with data members: age (an integer), id (an integer) and salary (a float), and their corresponding member functions as follows: class Employee { private: int age; int id; float salary: public: Employee; // default constructor: age=0, id=0, and salary=0 void setAge(int x); // let age = x void setId(int x); // let id = x void setSalary(float x); // salary = x int getAge(); // return age int getId; // return id float...

  • c++ only Design a class representing an Employee. The employee would have at least these private...

    c++ only Design a class representing an Employee. The employee would have at least these private fields (Variables): name: string (char array) ID: string (char array) salary: float Type: string (char array) All the variables except for the salary should have their respective setters and getters, and the class should have two constructors, one is the default constructor and the other constructor initializes the name,ID and type of employee with valid user input. The class should have the following additional...

  • Java Do 68a, 68b, 68c, 68d. Show code & output. public class Employee { private int...

    Java Do 68a, 68b, 68c, 68d. Show code & output. public class Employee { private int id; private String name; private int sal; public Employee(int id, String name, int sal) { super(); this.id = id; this.name = name; this.sal = sal; } public int getid) { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; public void setName(String name) { this.name = name; } public int get Sall) { return sal;...

  • in c++ Define and implement the class Employee with the following requirements: private data members string...

    in c++ Define and implement the class Employee with the following requirements: private data members string type name a. b. double type hourlyRate 2. public member functions a. default constructor that sets the data member name to blank"and hourlyRate to zero b. A constructor with parameters to initialize the private data members c. Set and get methods for all private data members d. A constant method weeklyPay() that receives a parameter representing the number of hours the employee worked per...

  • It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming...

    It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming Challenge 2 Employee Class.pdf Program Template: // Chapter 13, Programming Challenge 2: Employee Class #include <iostream> #include <string> using namespace std; // Employee Class Declaration class Employee { private: string name; // Employee's name int idNumber; // ID number string department; // Department name string position; // Employee's position public: // TODO: Constructors // TODO: Accessors // TODO: Mutators }; // Constructor #1 Employee::Employee(string...

  • Write a C++ program Write a class named Employee that has the following member variables: name...

    Write a C++ program Write a class named Employee that has the following member variables: name A string that holds the employee name idNumber An int to hold employee id number department A string to hold the name of the department position A string to hold the job position The class will have three constructors: 1. A constructor that accepts all the internal data such as: Employee susan("Susan Meyers", 47899, "Accounting", "Vice President"); 2. A constructor that accepts some of...

  • Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type...

    Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type int Name of type String Balance of type float Public members void Init) method to enter the values of data members void Show) method to display the values of data members void Deposit(int Amt) method to increase Balance by Amt void Withdraw(int Amt) method to reduce Balance by Amt (only if required balance exists in account) float RBalance() member function that returns the value...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT