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

Program Metrics

Uploaded by

Minahil Ismail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Program Metrics

Uploaded by

Minahil Ismail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

using System;

class Circle
{
private double radius;

public Circle(double radius)


{
this.radius = radius;
}
public double Area()
{
return 3.14 * radius * radius;
}
public double Circumference()
{
return 2 * 3.14 * radius;
}
}

class Program
{
static void Main(string[] args)
{
Circle c = new Circle(4.0);
Console.WriteLine("Circle Area: " + c.Area());
Console.WriteLine("Circle Circumference: " + c.Circumference());
}
}

using System;
class Shape
{
public virtual void Draw()
{
Console.WriteLine("Drawing a shape.");
}

public void Move()


{
Console.WriteLine("Moving a shape.");
}
}

class Rectangle : Shape


{
private double width;
private double height;

public Rectangle(double width, double height)


{
this.width = width;
this.height = height;
}

public override void Draw()


{
Console.WriteLine("Drawing a rectangle.");
}
public double Area()
{
return width * height;
}
}

class Program
{
static void Main(string[] args)
{
Rectangle rect = new Rectangle(5.0, 3.0);
rect.Draw();
rect.Move();
Console.WriteLine("Area: " + rect.Area());
}
}

using System;

class Rectangle
{
private double width;
private double height;
public Rectangle(double width, double height)
{
this.width = width;
this.height = height;
}

public double Area()


{
return width * height;
}

public double Perimeter()


{
return 2 * (height + height);
}

public void SetWidth(double width)


{
this.width = width;
}

public void SetHeight(double height)


{
this.height = height;
}
}

using System;

class Engine
{
public void Start()
{
Console.WriteLine("Engine started.");
}
public void Stop()
{
Console.WriteLine("Engine stopped.");
}
}

class FuelTank
{
private double fuelLevel;

public FuelTank(double initialFuel)


{
fuelLevel = initialFuel;
}

public void ConsumeFuel(double amount)


{
fuelLevel -= amount;
Console.WriteLine($"Fuel consumed: {amount}. Remaining fuel:
{fuelLevel}");
}

public double GetFuelLevel()


{
return fuelLevel;
}
}

Class Car
{
private Engine engine;
private FuelTank fuelTank;

public Car(double fuelLevel)


{
engine = new Engine();
fuelTank = new FuelTank(fuelLevel);
}

public void StartCar()


{
if (fuelTank.GetFuelLevel() > 0)
{
engine.Start();
fuelTank.ConsumeFuel(1.0);
}
else
{
Console.WriteLine("Not enough fuel to start the car.");
}
}

public void StopCar()


{
engine.Stop();
}
}

class Program
{
static void Main(string[] args)
{
Car myCar = new Car(5.0);
myCar.StartCar();
myCar.StopCar();
}
}

You might also like