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,...
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...
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,...
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....
Payroll Management System C++ The project has multiple classes and sub-classes with numerous features within them....
Payroll Management System C++ The project has multiple classes and sub-classes with numerous features within them. Basic operations users can perform via this program project that are based on file handling are adding new employee record, modifying employee record and deleting record, displaying one or all employee’s record. Besides these, payroll management also allows users to print the salary slip for a particular employee. Features: 1. Addition of New Employee: You can find this feature under the public category of...
This program is in C++: Write a program to allow the user to: 1. Create two...
This program is in C++: Write a program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you start doing anything… This project involves implementing a simple university personnel management program. The program contains two different kinds of objects: students and faculty. For each object, the program stores relevant information such as university ID, name, etc. Different information is stored depending on the type of the object. For example, a student has a GPA, while a faculty has a title and department...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
Write a program that sorts the content of a map by Values. Before we start, we...
Write a program that sorts the content of a map by Values. Before we start, we need to check the explanation of Java Map Interface and Java LinkedHashMap. This program can be implemented as follows: 1. Create a LinkedHashMap class <String (Country), String(Capital)> that stores Capitals of FIVE countries. 2. Use sortMap() for receiving content of the created class of LinkedHashMap and reorder it in a sorted Map. (sort in natural order). 3. You need to transfer the map into...