Question

Write a program to prepare the ‘payroll’ of an employee by using single inheritance. The base...

Write a program to prepare the ‘payroll’ of an employee by using single inheritance. The base class contains employee Name and Id while the derived class ‘allowance’ has float members for basic_pay, medical_allowance and transport_allowance. It then calculates gross pay of the employee through a member function (for both classes there should be getinput() and getoutput() functions with same name)

use c++

Homework Answers

Answer #1

C++ Program for Employee Payroll(Image and Output Attached Below code):

#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

// as this will be used by other class so we have to declare this as public (public:)
// declaring employee id as integer (int id)
// declaring employee name as character with max length 20 (char name[20])
//declaring member function to get input of name and ID
class payroll
{
public:
int id;
char name[20];
void getfn()
{//getting input of name using gets (gets(name))
//getting input of ID(id)    
cout<<"Enter employee name:";
cin>>gets(name);
cout<<"Enter employee ID:";
cin>>id;

}
};


//using inheritance and taking payroll class as parent class with allowance class
//declaring basic pay,medical allowance,transport allowance and net pay as float (float bp,ma,ta,gp)
//declaring member function to get input of basic pay,medical  allowance,transport allowance (void getfn1())    
class allowance:public payroll
{
float bp,ma,ta,gp;

public:
void getfn1()
{
cout<<"Enter basic pay:";
cin>>bp;
cout<<"Enter Medical Allowance:";
cin>>ma;
cout<<"Enter Transport Allowance :";
cin>>ta;

}
void calc()
{//calculating gross pay
gp=bp+ma+ta;
}
void disp()
{
cout<<endl;
           cout<<"Employee's Name:"<<name<<endl;
cout<<"Employee ID:"<<id<<endl;
           cout<<"Basic Pay:"<<bp<<endl;
           cout<<"House Medical Allowance:"<<ma<<endl;
           cout<<"Transport Allowance:"<<ta<<endl;
           cout<<"Gross Pay:"<<gp<<endl;
           cout<<endl;
}
};

int main()
{
int i,n;


cout<<"################################OFFICE####################################"<<endl;
allowance s[10];
cout<<"Enter employee number:";
cin>>n;
//(below is Optional fn for getting pay of more than 1 employee)
//used to display name and id (s[i].getfn())
//used to display name and id (s[i].getfn1())
//used to display gp (s[i].calc())
for(i=0;i<n;i++)
{
s[i].getfn();
s[i].getfn1();
s[i].calc();
}
//used to display all the values after program ends (s[i].disp())
for(i=0;i<n;i++)
{
s[i].disp();
}
//used to hold screen
_getch();
return 0;


}

Code Image:

Output:

Please give me an upvote if my answer helped :)

Know the answer?
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
Similar Questions
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
Using Inheritance Consider the following (base) class. class Employee(object): def __init__(self, name, salary): self._name = name...
Using Inheritance Consider the following (base) class. class Employee(object): def __init__(self, name, salary): self._name = name self._salary = salary def my_name(self): return self._name def wage(self): return self._salary/26 # fortnight pay Define a new subclass of Employee called Worker. A worker has a manager, who is another employee; their manager is given as an argument to the constructor. You should define a method get_manager that returns the worker’s manager. boss = Employee('Mr. Burns', 1000000) worker = Worker('Waylon Smithers', 2500, boss) Define...
write C++ programs Array of Payroll Objects Design a PayRoll class that has data members for...
write C++ programs Array of Payroll Objects Design a PayRoll class that has data members for an employee’s hourly pay rate and number of hours worked. Write a program with an array of seven PayRoll objects. The program should read the number of hours each employee worked and their hourly pay rate from a file and call class functions to store this information in the appropriate objects. It should then call a class function, once for each object, to return...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an...
Has to be written in C#! Write a program that includes an Employee class that can...
Has to be written in C#! Write a program that includes an Employee class that can be used to calculate and print the take-home pay for a commissioned sales employee. Items to include as data members are employee number, first name, last name, and total sales. All employees receive 9% of the total sales of the month. Federal tax rate is 18%. Retirement contribution is 10%. Social Security tax rate is 6%. Use appropriate constants, design an object-oriented solution, and...
Using C# Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and...
Using C# Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and initSalary. It includes constructor(s) and properties to initialize values for all fields. Create an interface, SalaryCalculate, class that includes two functions: first,CalcYearWorked() function, it takes one parameter (currentyear) and calculates the number of year the worker has been working. The second function, CalcCurSalary() function that calculates the current year salary. Create a Worker classes that is derived from Employee and SalaryCalculate class. In Worker...
1.Write a c++ program to find Maximum out of two numbers using friend function. Here one...
1.Write a c++ program to find Maximum out of two numbers using friend function. Here one member is of one class and second belongs to another class. 2.Write a c++ program to swap the values of private data members of classes names classOne and classTwo using friend keyword.
Write a program in python language that calculates the salary of an employee who works under...
Write a program in python language that calculates the salary of an employee who works under an hourly wage contract in a company. To read his name, the working hours of the month, his hourly wage and whether he is married or unmarried. The reservations made to him depend on the amount of his salary. If the salary is up to € 1000 per month, it has 15% reservations, while otherwise it has 25% reservations. Also, if he is married,...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and...
Java Programming COMP-228 LAB ASSIGNMENT #1 >> Apply the naming conventions for variables, methods, classes, and packages: - variable names start with a lowercase character for the first word and uppercase for every other word - classes start with an uppercase character of every word - packages use only lowercase characters - methods start with a lowercase character for the first word and uppercase for every other word Java Programming COMP-228 Exercise #1: [5 marks] Write a Java application using...
write a c++ program A class called car (as shown in the class diagram) contains: o...
write a c++ program A class called car (as shown in the class diagram) contains: o Four private variables: carId (int), carType (String), carSpeed (int) and numOfCars (int). numOfCars is a static counter that should be  Incremented whenever a new Car object is created.  Decremented whenever a Car object is destructed. o Two constructors (parametrized and copy constructor) and one destructor. o Getters and setters for the Car type, ID, and speed. And static getter function for numOfCars....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT