Answer to Question #240039 in C# for Gayatri

Question #240039

Create an abstract class shape in which area abstract function is there so two classes triangle and rectangle can override the functionality of area in shape class .Then a change of request has come as per new requirement a we have to find the area of square and area of circle also but they don’t want to override the functionality of abstract class shape but they want to implement their code?And area of circle is Pi r2 and area of square is (side)2.Q3) Write overloaded methods to find total salary of employees. Create a class Employee and write an overloaded method to find total salary of employee.Total salary=salary + Bonus+ incentives (data types use it decimal,int,int) Total salary=salary +HRA + PF (data types use it double,float,int)Total salary=salary + perks +travelling_allowences (data types use it is float,int,short)Create another subclass as EmployeeJunior and there also write one overloaded method and call al the methods as per the parameters passed in the main method in console application.


1
Expert's answer
2021-09-21T11:02:21-0400
Q2


using System;
using System.Collections.Generic;
namespace App
{
    class Shape
    {


        public virtual double area()
        {
            return 0;
        }
    }


    class Circle : Shape
    {
        public double radius { get; set; }
        public override double area()
        {
            return Math.PI * radius * radius;
        }
    }


    class Rectangle : Shape
    {
        public double side { get; set; }
        public override double area()
        {
            return side * side;
        }
    }




    class Program
    {
        static void Main(string[] args)
        {


            Circle circle = new Circle();
            circle.radius = 4;
            Console.WriteLine("Circle radius: {0}", circle.radius);
            Console.WriteLine("Circle area: {0}", circle.area());


            Rectangle rectangle = new Rectangle();
            rectangle.side = 5;
            Console.WriteLine("Rectangle side: {0}", rectangle.side);
            Console.WriteLine("Rectangle area: {0}", rectangle.area());




            Console.ReadLine();
        }
    }
}




Q3


using System;
using System.Collections.Generic;
namespace App
{
    class Employee
    {
        public decimal findTotalSalary(decimal salary, int Bonus,int incentives)
        {
            return salary + Bonus + incentives;
        }
        public double findTotalSalary(double salary, float HRA, int PF)
        {
            return salary + HRA + PF;
        }
        public double findTotalSalary(float salary, int perks, short travelling_allowences)
        {
            return salary + perks + travelling_allowences;
        }




    }


    class EmployeeJunior: Employee 
    {


        public double findTotalSalary(double salary, int HRA, int PF)
        {
            return salary + HRA + PF;
        }
    }


    




    class Program
    {
        static void Main(string[] args)
        {
            Employee employee = new Employee();
            Console.WriteLine("Employee.findTotalSalary(decimal salary, int Bonus,int incentives): {0}", employee.findTotalSalary(5000.0M, 100, 50));
            Console.WriteLine("Employee.findTotalSalary(double salary, float HRA, int PF): {0}", employee.findTotalSalary(4000.0, 100.0f, 10));
            short travelling_allowences = 60;
            Console.WriteLine("Employee.findTotalSalary(float salary, int perks, short travelling_allowences): {0}", employee.findTotalSalary(3000.0f, 500, travelling_allowences));


            EmployeeJunior employeeJunior = new EmployeeJunior();
            Console.WriteLine("EmployeeJunior.findTotalSalary(double salary, int HRA, int PF): {0}", employeeJunior.findTotalSalary(4000.0d, 100, 10));


            Console.ReadLine();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS