You are on page 1of 5

Assignment 4

1. Create a class Employee that has a field for storing the complete name of employee
(first and last name), a field for storing the IDentification number of employee, and
another field for storing his salary.
Provide
a) a no-argument constructor for initializing the fields to default values
#include <iostream>

using namespace std;


class Employee{
public:
string name, id;
int salary;

void setvalues(){
cout<<"Enter full name"<<endl;
cin>>name;
cout<<"Enter id"<<endl;
cin>>id;
cout<<"Enter salary amount"<<endl;
cin>>salary;
}
};
class D:public Employee{
public:
void display(){
cout<<"Name is "<<name<<"ID No "<<id<<"Salary "<<salary<<endl;
}
};
int main()
{

D E;
E.setvalues();
E.display();
return 0;
}

b) a 3-argument constructor for initializing the fields to values sent from outside.

c) a setter function (mutator) that sets the values of these fields by getting input from
user.

d) an accessor(getter) function to display the values of the fields.

Derive three classes from this employee class: Manager, Scientist, and Laborer.
Manager class has an additional data member of # of subordinates. Scientist class
contains additional information about # of publications. Laborer class is just similar to
the employee class. It has no additional capabilities. Derive a class foreman from the
Laborer class that has an additional data member for storing the percentage of quotas
met by a foreman. Provide appropriate no-argument and n-argument constructors for
all the classes. Provide the overridden getter and setter functions here too to input and
output all the fields. Determine whether public, private, or protected inheritance should
be used (10)

2. Write code examples that demonstrate the following types of inheritance

a.) multilevel (3)

b) hybrid (3)

c.) multiple (3)

3a.) Distinguish between runtime polymorphism and dynamic polymorphism (2)


b.) Write a C++ program to compute area of right angle triangle, equilateral triangle
,scalene triangle using function overloading concept. (5)

c.) A company pays its employees on a weekly basis. The employees are of
four types: Salaried employees are paid a fixed weekly salary regardless of
the number of hours worked, hourly employees are paid by the hour and
receive overtime pay (i.e., 1.5 times their hourly salary rate) for all hours
worked in excess of 40 hours, commission employees are paid a percentage
of their sales and base-salaried commission employees receive a base
salary plus a percentage of their sales. For the current pay period, the
company has decided to reward salaried-commission employees by adding
10% to their base salaries. The company wants to write an application that
performs its payroll calculations polymorphically (8)

#include <iostream>

using namespace std;

class Employee{

public:
double wage(double a){

return a;

double wage(int a){

double intrest;

cout<<"Enter the interest on Sales of Commissioned Employees "<<endl;

cin>>intrest;

return a*intrest+a;

double wage(int a, double b){

//base-salaried

double interest;

cout<<"enter interest on Sales Base salaried commissioned employees "<<endl;

cin>>interest;

return (a+0.1*a+b*interest);

double wage(float a){

int h;

cout<<"\nEnter hours worked by Hourly employee"<<endl;

cin>>h;

if(h>40){
int h1=h-40;

return (a+h1*1.5);

else{

return a;}

};

int main()

Employee E;

cout<<"Salaried Employee's salary is "<<E.wage(20.0)<<endl;

cout<<"Commissioned Employees payout is "<<E.wage(300)<<endl;

cout<<"Base class Salaried Total payout is "<<E.wage(20,10.0);

cout<<"Hourly Salaried total payout is "<<E.wage(10.0f);

return 0;

4. Create a base class called shape. Use this class to store two double type values
that could be used to compute the area of figures. Derive two specific classes called
triangle and rectangle from the base shape. Add to the base class, a member function
get_data () to initialize base class data members and another member function
display_area () to compute and display the area of figures. Make display_area ( ) as a
pure virtual function and implement this method in the derived classes to suit their
requirements. Using these three classes, design a program that will accept dimensions
of a triangle or a rectangle interactively and display the area.
Remember the two values given as input will be treated as lengths of two sides in the
case of rectangles and as base and height in the case of triangles and used as follows:
Area of rectangle = x * y
Area of triangle = ½ * x * y (6 )

You might also like