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

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...
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...
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...
C++ Create a class for working with fractions. Only 2 private data members are needed: the...
C++ Create a class for working with fractions. Only 2 private data members are needed: the int numerator of the fraction, and the positive int denominator of the fraction. For example, the fraction 3/7 will have the two private data member values of 3 and 7. The following methods should be in your class: a. A default constructor that should use default arguments in case no initializers are included in the main. The fraction needs to be stored in reduced...
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++ Please create the class named BankAccount with the following properties below: // The BankAccount...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (using name & id), and - keeps track of a user's available balance. - how many transactions (deposits and/or withdrawals) are made. public class BankAccount { private int id; private String name private double balance; private int numTransactions; // ** Please define method definitions for Accessors and Mutators functions below for the class private member variables string getName();...
Create a C# Application. Create a class object called “Employee” which includes the following private variables:...
Create a C# Application. Create a class object called “Employee” which includes the following private variables: firstN lastN idNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods: constructor properties CalcPay(): Calculate the regular pay and overtime pay. Create...
Create a class named Horse that contains the following data fields: name - of type String...
Create a class named Horse that contains the following data fields: name - of type String color - of type String birthYear - of type int Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field, races (of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field. ------------------------------------ DemoHorses.java public class DemoHorses {     public static void...
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...
Create a class named RemoveDuplicates and write code: a. for a method that returns a new...
Create a class named RemoveDuplicates and write code: a. for a method that returns a new ArrayList, which contains the nonduplicate elements from the original list public static ArrayList removeDuplicates(ArrayList list) b. for a sentinel-controlled loop to input a varying amount of integers into the original array (input ends when user enters 0) c. to output the original array that displays all integers entered d. to output the new array that displays the list with duplicates removed Use this TEST...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT