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

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...
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...
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...
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...
In C# Create classes: Person, Student, Employee, Professor, Staff and Address ☐ Address class must have...
In C# Create classes: Person, Student, Employee, Professor, Staff and Address ☐ Address class must have suitable auto-implemented properties for Address 1, Address 2 and City. ☐ Person class must have suitable auto-implemented properties for Name, Residence (type Address) and email. ☐ Student and Employee must be subclasses of Person. ☐ Employee must be a super class for Professor and Staff. ☐ Employee class must have suitable auto-implemented properties for salary (between 2000 to 8000), and hire date. ☐ Professor...
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...
Part 1 Create a class named Room which has two private data members which are doubles...
Part 1 Create a class named Room which has two private data members which are doubles named length and width. The class has five functions: a constructor which sets the length and width, a default constructor which sets the length to 12 and the width to 14, an output function, a function to calculate the area of the room and a function to calculate the parameter. Also include a friend function which adds two objects of the room class. Part...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT