Output:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Question_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Question_1.Rectangle R = new Question_1.Rectangle();
MessageBox.Show("Area Of Rectangle Is: "+ R.Area());
}
private void button3_Click(object sender, EventArgs e)
{
Question_1.Triangle T = new Question_1.Triangle();
MessageBox.Show("Area Of Triangle Is: "+ T.Area());
}
private void button2_Click(object sender, EventArgs e)
{
Question_1.Square S = new Question_1.Square();
MessageBox.Show("Area Of Square Is: "+S.Area());
}
}
}
Shape Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Question_1
{
public abstract class Shape
{
public abstract double Area();
}
public class Rectangle : Shape
{
override public double Area()
{
double Length = 15;
double Width = 25;
return (Length*Width);
}
}
public class Triangle : Shape
{
override public double Area()
{
double Length = 18;
double Width = 12;
return ((Length * Width)/2);
}
}
public class Square : Shape
{
public override double Area()
{
int x = 12;
return(x*x);
}
}
}
No comments:
Post a Comment