Q-1. Design and implement a class named Employee to compute the net salary of an employee using the basic salary, medical allowance, and house rent (45% of basic salary).
The design of Employee class should include:
- Three private members basic_sal, med_allow, and h_rent, which present basic salary, medical allowance and house rent of an employee.
- One private member net_sal to preserve the computed net salary of an employee.
- A default constructor (i.e., Employee()) to initialize the basic_sal, med_allow, and h_rent as 3000, 500, and 1350 (as 45% of 3000).
- A parameter constructor (i.e., Employee(int, int)) to initialize the values of basic_sal and med_allow of an employee.
- A set method (i.e., set(int, int)) to enter the new basic salary and medical allowance of an employee.
- A method (i.e., computeNetSalary()) to compute the net salary of an employee. The net salary of an employee should be computed through the following formula: net salary = basic salary + medical allowance + house rent, where house rent = 45% of basic salary.
- A get method (i.e., get()) to display the net salary of an employee.
According to the requirements above, write a program to compute the net salary of two employees:
- Create first Employee object (i.e., Emp1) with default constructor.
- Enter the value of basic salary and medical allowance of second employee (i.e., Emp2) and create it with parameter constructor.
- Compute the net salary of both employees (Emp1 and Emp2) by calling computeNetSalary()
- Display the net salary of both employees (Emp1 and Emp2) by calling get()
- Enter new basic salary and medical allowance of Emp1 by calling set() method.
- Compute and display the net salary of Emp1.
Expected Outputs:
Enter basic salary for Emp2: 4000
Enter medical allowance for Emp2: 600
The net salary for Emp1 is 4850
The net salary for Emp2 is 6400 Enter basic salary for Emp1:
5000
Enter medical allowance for Emp1:
1000
The net salary for Emp1 is 8250
Q-2. Design and implement a class to compute the area of a triangle using the values of their sides. The design of class (named Triangle) should include:
- Three private members side1, side2, and side3, which present sides of a triangle.
- One private member area to preserve the computed area of triangle.
- A default constructor (i.e., Traingle()) to initialize sides of triangle and area of triangle as zero.
- A parameter constructor (i.e., Traingle(double, double, double)) to initialize the values of sides for corresponding triangle and initialize area of triangle as zero.
- A set method (i.e. setSides(double, double, double)) to enter the new values for the sides.
- A method (i.e. computeArea()) to compute the area of triangle.
- A get method (i.e. getArea()) to display the area.
Hint-1. Area of Tringle can be computed through the following Herons Formula:
Area = sqrt(s*(s-a)*(s-b)*(s-c)), where s=(a+b+c)/2.
Hint-2. You need to include <cmath> library to use the sqrt() function and include <iomanip> library to use setprecision and fixed manipulators to change the precision value and printing format.
According to the requirements above, write a program which defines an array of triangles
Triangle arr[10].
The program should let the user input the sides of n triangles (where n is an integer input by the user and 1n10) and store them in the array. The program should print the area of all triangles and also print the name of the triangle with the largest area (if there are two or more triangles with the same maximum area, only print the first one in the original order that they are defined).
Assume that all inputs are valid, i.e., n is within the range specified, and those three sides can form a triangle.
Expected Outputs:
Example 1. |
Enter a number between 1 and 10: 4 Enter the sides of triangle 1:3 3 3Enter the sides of triangle 2:3 4 5Enter the sides of triangle 3:3 4 5Enter the sides of triangle 4:3 2 3Area of triangle 1: 3.90Area of triangle 2: 6.00Area of triangle 3: 6.00Area of triangle 4: 2.83Triangle 2 has the largest area: 6.00 |
Example 2. |
Enter a number between 1 and 10: 5 Enter the sides of triangle 1:6 6 6Enter the sides of triangle 2: 4 5 6 Enter the sides of triangle 3:7 8 9Enter the sides of triangle 4:3 4 5Enter the sides of triangle 5:5 7 5Area of triangle 1: 15.59Area of triangle 2: 9.92Area of triangle 3: 26.83Area of triangle 4: 6.00Area of triangle 5: 12.50Triangle 3 has the largest area: 26.83 |
Reviews
There are no reviews yet.