You are on page 1of 6

Lesson03Ex1

Filename: Program.cs
using Lesson03Ex1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lesson03Ex1
{
class Circle
{
private float fltRadius;

public float Area


{
get { return 3.1416f * fltRadius* fltRadius; }
}

public Circle(float r)
{
fltRadius = r;
}

public float Circumference()


{
return 2 * 3.1416f * fltRadius;
}
}

internal class Program


{
static void Main(string[] args)
{
Circle c1;
Circle c2;

Console.WriteLine("Enter radius of circle 1: ");


float radius = float.Parse(Console.ReadLine());

c1 = new Circle(radius);
float fltCircumference1 = c1.Circumference();

Console.WriteLine("Enter radius of circle 2: ");


radius = float.Parse(Console.ReadLine());

c2 = new Circle(radius);

float fltCircumference2 = c2.Circumference();

float TotalArea = c1.Area + c2.Area;


Console.WriteLine("Total area of the circles is {0} cm2.",TotalArea.ToString());

float TotalCircumference = fltCircumference1 + fltCircumference2;


Console.WriteLine("Total circumference of the circles is {0} cm.", TotalCircumference.ToString());

Console.ReadKey();
}
}
}

Lesson03Ex2
Filename: Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Schema;

namespace Lesson03Ex2
{
internal class Rectangle
{
private float fltLength;
private float fltBreadth;

public float Area


{
get { return fltLength * fltBreadth; }
}

public Rectangle(float l, float b)


{
fltLength = l;
fltBreadth = b;
}

public string GetSize()


{
return "The length and breadth of the rectangle are " + fltLength.ToString() + " cm and " +
fltBreadth.ToString() + " cm respectively.";
}
}

internal class Program


{
static void Main(string[] args)
{
Rectangle r1;
Rectangle r2;

Console.WriteLine("Enter the length of rectangle 1: ");


float Length = float.Parse(Console.ReadLine());
Console.WriteLine("Enter the breadth of rectangle 1: ");
float Breadth = float.Parse(Console.ReadLine());

r1 = new Rectangle(Length, Breadth);

Console.WriteLine(r1.GetSize());

Console.WriteLine("Enter the length of rectangle 2: ");


Length = float.Parse(Console.ReadLine());

Console.WriteLine("Enter the breadth of rectangle 2: ");


Breadth = float.Parse(Console.ReadLine());

r2 = new Rectangle(Length, Breadth);

Console.WriteLine(r2.GetSize());

float TotalArea = r1.Area + r2.Area;


Console.WriteLine("The total area of the two rectangles is {0} cm2.", TotalArea.ToString());

Console.ReadKey();
}
}
}
Lesson03Ex3

Filename: Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lesson03Ex3
{
class Account
{
private string strType;
private string strName;
private float fltBalance;

public string Type


{
get { return strType; }
}
public string Name
{
get { return strName; }
}
public float Balance
{
get { return fltBalance; }
}

public Account(string t, string n, float b)


{
strType = t;
strName = n;
fltBalance = b;
}

public float CallInterest()


{
return fltBalance * 0.018f;
}
}

internal class Program


{
static void Main(string[] args)
{
Account accObj;

Console.WriteLine("Enter the type of account: ");


string Type = Console.ReadLine();
Console.WriteLine("Enter the name of account: ");
string Name = Console.ReadLine();
Console.WriteLine("Enter the balance of account: ");
float Balance = float.Parse(Console.ReadLine());

accObj = new Account(Type,Name,Balance);

float AccInterest = accObj.CallInterest();

Console.WriteLine("Type = {0}, Name = {1}, Balance = ${2}, Interest = ${3}",accObj.Type, accObj.Name,


accObj.Balance.ToString(), AccInterest.ToString());

Console.ReadKey();
}
}
}

You might also like