0% found this document useful (0 votes)
5 views

Lab_Sheet_4_Method Overloading N Inheritance

The document contains C# programming exercises focusing on method overloading and inheritance. It includes a program to calculate the area of various shapes using method overloading and a class structure for a Rectangle and its subclass Tabletop to calculate area and painting costs. Additionally, it outlines an assignment to create an Employee class inheriting from a Human class, including attributes and a display method.

Uploaded by

Chinmayi D
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lab_Sheet_4_Method Overloading N Inheritance

The document contains C# programming exercises focusing on method overloading and inheritance. It includes a program to calculate the area of various shapes using method overloading and a class structure for a Rectangle and its subclass Tabletop to calculate area and painting costs. Additionally, it outlines an assignment to create an Employee class inheriting from a Human class, including attributes and a display method.

Uploaded by

Chinmayi D
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab Sheet 4

Method Overloading and Inheritance


1. Write a C# Program to find out the area of the triangle, square, and rectangle
using method overloading.

namespace myfirstproject
{
internal class overloading
{
static void area(int a, int b)
{
Console.WriteLine("area of triangle is=" + ((a * b) / 2));
}
static void area(int a)
{
Console.WriteLine("area of square is=" + (a * a));
}
static void area(int a, double b)
{
Console.WriteLine("area of rectangle is=" + (a * b));
}
static void Main(string[] args)
{
overloading.area(8, 5);
overloading.area(5);
overloading.area(6, 8.7);
Console.ReadKey();
}
}

Assessment 4a:

Write a C# Program to find out the multiplication of two, three and four operands using
method overloading.
2. Create a Class called Rectangle and store length, width using constructor.
Calculate the area using that. Create tabletop using rectangle class and calculate
the cost of painting that table top. (Use single inheritance)

namespace myfirstproject
{
class Rectangle
{
protected double length, width;
protected double calcarea;
protected Rectangle()
{
length = 0;
width = 0;
}

public void Area()


{
calcarea = length * width;
Console.WriteLine(" Area is "+ calcarea);
}
}
class tabletop : Rectangle
{
double cost;
public tabletop()
{
cost = 0;
}
internal tabletop(double length, double width)
{
this.length = length;
this.width = width;
}
public void calcost()
{
Area(); //Method from the base class
cost = 1000;
double totalcost = calcarea * cost;
Console.WriteLine("Total cost is " + totalcost);
}
}
internal class Inheritance1
{
static void Main()
{
Console.WriteLine(" Enter length and Width");
double l = Convert.ToDouble(Console.ReadLine());
double w = Convert.ToDouble(Console.ReadLine());
tabletop obj = new tabletop(l, w);
obj.calcost();
}
}
}
Assessment 4b:

Create a class called Employee with id and salary. Employee class is inheriting from
Human class. Name and age should be defined in Human class. Include display method
in Employee class to display all details.

You might also like