1.
Program for Shape Area Based on User Input
using System;
class Program
{
static void Main(string[] args)
{
[Link]("Enter shape type (circle, rectangle, triangle):
");
string shape = [Link]().ToLower();
switch (shape)
{
case "circle":
[Link]("Enter radius: ");
double radius = [Link]([Link]());
[Link]("Area of Circle: " + ([Link] * radius *
radius));
break;
case "rectangle":
[Link]("Enter length: ");
double length = [Link]([Link]());
[Link]("Enter width: ");
double width = [Link]([Link]());
[Link]("Area of Rectangle: " + (length * width));
break;
case "triangle":
[Link]("Enter base: ");
double b = [Link]([Link]());
[Link]("Enter height: ");
double height = [Link]([Link]());
[Link]("Area of Triangle: " + (0.5 * b * height));
break;
default:
[Link]("Invalid shape!");
break;
}
}
}
2. Vehicle Class Hierarchy
using System;
class Vehicle
{
public string Model;
public int Year;
public string FuelType;
public virtual void FuelEfficiency()
{
[Link]("Fuel efficiency: Default value");
}
public virtual void DistanceTravelled()
{
[Link]("Distance travelled: Default value");
}
public virtual void MaxSpeed()
{
[Link]("Max speed: Default value");
}
}
class Truck : Vehicle
{
public override void FuelEfficiency()
{
[Link]("Truck fuel efficiency: 8 km/l");
}
public override void DistanceTravelled()
{
[Link]("Truck distance travelled: 500 km");
}
public override void MaxSpeed()
{
[Link]("Truck max speed: 120 km/h");
}
}
class Car : Vehicle
{
public override void FuelEfficiency()
{
[Link]("Car fuel efficiency: 15 km/l");
}
public override void DistanceTravelled()
{
[Link]("Car distance travelled: 600 km");
}
public override void MaxSpeed()
{
[Link]("Car max speed: 180 km/h");
}
}
class Motorcycle : Vehicle
{
public override void FuelEfficiency()
{
[Link]("Motorcycle fuel efficiency: 35 km/l");
}
public override void DistanceTravelled()
{
[Link]("Motorcycle distance travelled: 300 km");
}
public override void MaxSpeed()
{
[Link]("Motorcycle max speed: 160 km/h");
}
}
3. Shape Base Class with Derived Shapes
using System;
abstract class Shape
{
public abstract double Area();
}
class Circle : Shape
{
public double Radius;
public Circle(double radius)
{
Radius = radius;
}
public override double Area()
{
return [Link] * Radius * Radius;
}
}
class Rectangle : Shape
{
public double Length, Width;
public Rectangle(double length, double width)
{
Length = length;
Width = width;
}
public override double Area()
{
return Length * Width;
}
}
class Triangle : Shape
{
public double Base, Height;
public Triangle(double b, double height)
{
Base = b;
Height = height;
}
public override double Area()
{
return 0.5 * Base * Height;
}
}
4. Class Inheritance with Inherit, InheritChild, Child
using System;
class Inherit
{
public string str = "Base class string";
public void InheritMethod()
{
[Link]("Method in Inherit: " + str);
}
}
class InheritChild : Inherit
{
public void InheritChildMethod()
{
[Link]("Method in InheritChild: " + str);
}
}
class Child : InheritChild
{
public void ChildMethod()
{
[Link]("Method in Child: " + str);
}
}
5. Animal Class with Dog and Bird
using System;
class Animal
{
public void Walk()
{
[Link]("Animal is walking...");
}
public void Eat()
{
[Link]("Animal is eating...");
}
}
class Dog : Animal
{
public int NoOfLegs = 4;
public void Bark()
{
[Link]("Dog is barking...");
}
}
class Bird : Animal
{
public int NoOfWings = 2;
public void Fly()
{
[Link]("Bird is flying...");
}