Question

In: Computer Science

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 object of both of these classes and print the same.

Solutions

Expert Solution

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
** NOTE: I WAS NOT CLEAR WITH THE PART OF SALARY SO I PROVIDED BOTH CODES

IF YOU STILL HAVE ANY PROBLEM PLEASE COMMENT BELOW I WILL DEFINELTY HELP YOU REGARDING THE SOLUTION**

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

1. THIS CODE HAS AN ATTRIBUTE SALARY , AND THE FUNCTION PRINTS THE SALARY ASSIGNED

CODE TO COPY

#include<iostream>
#include<string>

using namespace std;

class Staff
{
   public:
       int Id;
       string Name;
       string Phonenumber;
       string Address;
       int Age;
       double salary;
       void printSalary()
       {
           cout<<"Salary:"<<salary<<endl;
       }
};

class Employee:public Staff
{
   public:
       string Top_Skill;
};

class Officer:public Staff
{
   public:
       string department;
};

int main()
{
   Employee emp1;
   emp1.Id = 10;
   emp1.Name = "empName";
   emp1.Address = "London";
   emp1.Age= 25;
   emp1.Phonenumber = "04012310";
   emp1.salary =1000;

   cout<<"Employee Name: "<<emp1.Name<<endl;
   cout<<"Employee id: "<<emp1.Id<<endl;
   cout<<"Employee Age: "<<emp1.Age<<endl;
   cout<<"Employee Address: "<<emp1.Address<<endl;
   cout<<"Employee PhoneNum: "<<emp1.Phonenumber<<endl;
   cout<<"Employee Salary using printSalary method: "<<endl;
   emp1.printSalary();

   cout<<endl<<"**********************"<<endl<<endl;

   Officer off1;
   off1.Id = 12;
   off1.Name= "offName";
   off1.Address = "Bankok";
   off1.Age = 27;
   off1.Phonenumber = "0400000";
   off1.salary = 5000;

   cout<<"Officer Name: "<<off1.Name<<endl;
   cout<<"Officer id: "<<off1.Id<<endl;
   cout<<"Officer Age: "<<off1.Age<<endl;
   cout<<"Officer Address: "<<off1.Address<<endl;
   cout<<"Officer PhoneNum: "<<off1.Phonenumber<<endl;
   cout<<"Officer Salary using printSalary method: "<<endl;
   off1.printSalary();

   return 0;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

EXPLANATION

#include<iostream> // for taking input output
#include<string> // for string operation

using namespace std; // for cout cin

class Staff //creating a class Staff
{
   public: // to access all these fields they must be public
       int Id; // creating a id member
       string Name; //creating a Name of type string
       string Phonenumber; // creating a phonenumber of type string
       string Address; // creating a address field
       int Age; //creating age fiels
       double salary; //creating salary of type double
       void printSalary() // creating a function printSalary
       {
           cout<<"Salary:"<<salary<<endl; // printing salary
       }
};

class Employee:public Staff //inheriting Staff class
{
   public:
       string Top_Skill; // creating a Top_Skill field of type string
};

class Officer:public Staff //inheriting Staff class
{
   public:
       string department; // creating a department field of type string
};

int main()
{
   Employee emp1; //creating a object of employee class
   emp1.Id = 10; //assigning id as 10
   emp1.Name = "empName"; //assigning Name as empName
   emp1.Address = "London"; //assigning address as London
   emp1.Age= 25; //assigning age as 25
   emp1.Phonenumber = 0401231230; //assigning PhoneNumber
   emp1.salary =1000; //assigning salary

//printing all details of emp
   cout<<"Employee Name: "<<emp1.Name<<endl;
   cout<<"Employee id: "<<emp1.Id<<endl;
   cout<<"Employee Age: "<<emp1.Age<<endl;
   cout<<"Employee Address: "<<emp1.Address<<endl;
   cout<<"Employee PhoneNum: "<<emp1.Phonenumber<<endl;
   cout<<"Employee Salary using printSalary method: "<<endl;
   emp1.printSalary(); //printing salary using the function

   cout<<endl<<"**********************"<<endl<<endl;
   //printing line

   Officer off1; //creating a object of officer class
   off1.Id = 12; //assigning id as 12
   off1.Name= "offName"; //assigning Name offName
   off1.Address = "Bankok"; //assigning address as Bankok
   off1.Age = 27; //assigning age as 27
   off1.Phonenumber = 0400000000; // assigning PhoneNumber
   off1.salary = 5000; //assigning salary

//printing all details of officer
   cout<<"Officer Name: "<<off1.Name<<endl;
   cout<<"Officer id: "<<off1.Id<<endl;
   cout<<"Officer Age: "<<off1.Age<<endl;
   cout<<"Officer Address: "<<off1.Address<<endl;
   cout<<"Officer PhoneNum: "<<off1.Phonenumber<<endl;
   cout<<"Officer Salary using printSalary method: "<<endl;
   off1.printSalary(); //printing salary using the function

   return 0;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

2.THIS CODE ASSIGNS SALARY BASED ON THE TOPSKILL AND DEPARTMENT OF STAFF AND OFFICER RESPECTIVELY GIVEN

#include<iostream>
#include<string>

using namespace std;

class Staff
{
   public:
       int Id;
       string Name;
       string Phonenumber;
       string Address;
       int Age;
       void printSalary()
       {
           cout<<"Salary:"<<endl;
       }
};

class Employee:public Staff
{
   public:
       string Top_Skill;
       void printSalary()
       {
           if(Top_Skill=="coder"){
               cout<<"Salary:"<<10000<<endl;
           }
       }
};

class Officer:public Staff
{
   public:
       string department;
       void printSalary()
       {
           if(department=="headOffice"){
           cout<<"Salary:"<<5000<<endl;
       }
       }
};

int main()
{
   Employee emp1;
   emp1.Id = 10;
   emp1.Name = "empName";
   emp1.Address = "London";
   emp1.Age= 25;
   emp1.Phonenumber = "0401231230";
   emp1.Top_Skill = "coder";

   cout<<"Employee Name: "<<emp1.Name<<endl;
   cout<<"Employee id: "<<emp1.Id<<endl;
   cout<<"Employee Age: "<<emp1.Age<<endl;
   cout<<"Employee Address: "<<emp1.Address<<endl;
   cout<<"Employee PhoneNum: "<<emp1.Phonenumber<<endl;
   cout<<"Employee Salary using printSalary method: "<<endl;
   emp1.printSalary();

   cout<<endl<<"**********************"<<endl<<endl;

   Officer off1;
   off1.Id = 12;
   off1.Name= "offName";
   off1.Address = "Bankok";
   off1.Age = 27;
   off1.Phonenumber = "0400000000";
   off1.department = "headOffice";

   cout<<"Officer Name: "<<off1.Name<<endl;
   cout<<"Officer id: "<<off1.Id<<endl;
   cout<<"Officer Age: "<<off1.Age<<endl;
   cout<<"Officer Address: "<<off1.Address<<endl;
   cout<<"Officer PhoneNum: "<<off1.Phonenumber<<endl;
   cout<<"Officer Salary using printSalary method: "<<endl;
   off1.printSalary();

   return 0;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include<iostream> // for taking input output
#include<string> // for string operation

using namespace std; // for cout cin

class Staff //creating a class Staff
{
   public: // to access all these fields they must be public
       int Id; // creating a id member
       string Name; //creating a Name of type string
       string Phonenumber; // creating a phonenumber of type string
       string Address; // creating a address field
       int Age; //creating age fiels
       double salary; //creating salary of type double
       void printSalary() // creating a function printSalary
       {
           cout<<"Salary:"<<salary<<endl; // printing salary
       }
};

class Employee:public Staff //inheriting Staff class
{
   public:
       string Top_Skill; // creating a Top_Skill field of type string
       void printSalary()
       {
           if(Top_Skill=="coder"){
           //IF THE Top_Skill IS CODER THEN SALARY IS 5000
               cout<<"Salary:"<<10000<<endl;
           }
       }
};

class Officer:public Staff //inheriting Staff class
{
   public:
       string department; // creating a department field of type string
       void printSalary()
       {
           if(department=="headOffice"){
           //IF THE DEPARTMENT IS HEADOFFICE THEN SALARY IS 5000
           cout<<"Salary:"<<5000<<endl;
       }
       }
};


int main()
{
   Employee emp1; //creating a object of employee class
   emp1.Id = 10; //assigning id as 10
   emp1.Name = "empName"; //assigning Name as empName
   emp1.Address = "London"; //assigning address as London
   emp1.Age= 25; //assigning age as 25
   emp1.Phonenumber = "0401231230"; //assigning PhoneNumber
   emp1.Top_Skill = "coder";

//printing all details of emp
   cout<<"Employee Name: "<<emp1.Name<<endl;
   cout<<"Employee id: "<<emp1.Id<<endl;
   cout<<"Employee Age: "<<emp1.Age<<endl;
   cout<<"Employee Address: "<<emp1.Address<<endl;
   cout<<"Employee PhoneNum: "<<emp1.Phonenumber<<endl;
   cout<<"Employee Salary using printSalary method: "<<endl;
   emp1.printSalary();

    cout<<endl<<"**********************"<<endl<<endl;
   //printing line

   Officer off1; //creating a object of officer class
   off1.Id = 12; //assigning id as 12
   off1.Name= "offName"; //assigning Name offName
   off1.Address = "Bankok"; //assigning address as Bankok
   off1.Age = 27; //assigning age as 27
   off1.Phonenumber = "0400000000"; // assigning PhoneNumber
   off1.department = "headOffice";

//printing all details of officer
   cout<<"Officer Name: "<<off1.Name<<endl;
   cout<<"Officer id: "<<off1.Id<<endl;
   cout<<"Officer Age: "<<off1.Age<<endl;
   cout<<"Officer Address: "<<off1.Address<<endl;
   cout<<"Officer PhoneNum: "<<off1.Phonenumber<<endl;
   cout<<"Officer Salary using printSalary method: "<<endl;
   off1.printSalary(); //printing salary using the function

   return 0;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

IF YOU STILL HAVE ANY DOUBTS OR PROBLEM WITH THE SOLUTION PLEASE PLEASE COMMENT BELOW I WILL DEFINETLY HELP YOU

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Related Solutions

WRITE IN C++ Create a class named Coord in C++ Class has 3 private data items...
WRITE IN C++ Create a class named Coord in C++ Class has 3 private data items               int xCoord;               int yCoord;               int zCoord; write the setters and getters. They should be inline functions               void setXCoord(int)             void setYCoord(int)            void setZCoord(int)               int getXCoord()                     int getYCoord()                   int getZCoord() write a member function named void display() that displays the data items in the following format      blank line      xCoord is                          ????????      yCoord is                          ????????      zCoord...
Create an Employee class having the following functions and print the final salary in c++ program....
Create an Employee class having the following functions and print the final salary in c++ program. - getInfo; which takes the salary, number of hours of work per day of employee as parameters - AddSal; which adds $10 to the salary of the employee if it is less than $500. - AddWork; which adds $5 to the salary of the employee if the number of hours of work per day is more than 6 hours.
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...
create a class in C++ having the following 4 private members: one double variable representing the...
create a class in C++ having the following 4 private members: one double variable representing the balance of a bank account on string variable representing the bank account number a function to deposit money from the bank account a function to withdraw money from the bank account the following 2 public members: -two wrapper functions. - one parameterless constructor - one constructor initializing the account balance and account number - sample: #include <iostream> using namespace std; class account { public:...
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++. Create a class named employee and have the data members of: Name ID Salary Create a class named manager that inherits the employee class and adds the data members: Managed_Employees (Array of up to 3 employees) Department Create methods to update each data member in the employee class. Create a method to print out the managed employees sorted by their salary in the manager class. (You can use one of...
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...
Rectangle Class in C++ Create a Rectangle class that has two data members: length_ and width_....
Rectangle Class in C++ Create a Rectangle class that has two data members: length_ and width_. Create the corresponding accessor and mutator functions to access and change both data members. Create a member function area that returns the area of the Rectangle object. Finally, create a function longest_rectangle that accepts two Rectangle objects as parameters and returns the Rectangle object with the longer length. Write the Rectangle class and the longest_rectangle function prototype in rectangle.hpp. Take note that longest_rectangle is...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance:...
In c++, define a class with the name BankAccount and the following members: Data Members: accountBalance: balance held in the account interestRate: annual interest rate. accountID: unique 3 digit account number assigned to each BankAccount object. Use a static data member to generate this unique account number for each BankAccount count: A static data member to track the count of the number of BankAccount objects created. Member Functions void withdraw(double amount): function which withdraws an amount from accountBalance void deposit(double...
In the C# programming language... Write a program to perform student record manage for class IST311....
In the C# programming language... Write a program to perform student record manage for class IST311. Create student record class (Student.cs) and it should get the student information from the user and set up student record class. The program will perform recording student’s grade information and compute final grade, and then print out the student’s class information. Student class definitions: It should contain attributes as following: first name, last name, 5 labs grade, 3 grade, final grade. Its member functions...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT