Q1
private void button1_Click(object sender, EventArgs e)
{
string a = "Nawroz";
textBox1.Text = a.Clone().ToString();
textBox2.Text = a.EndsWith("o").ToString();
textBox3.Text = a.Contains("w").ToString();
textBox4.Text = a.IndexOf("a").ToString();
}
//////////////////////////////////////
Q2
public int[] arr(int[] x, int[] y){
int[] result = new int[5];
for (int i = 0; i < 5; i++)
result[i] = power(x[i], y[i]);
return result;
}
public int power(int n,int m)
{
int p = 1;
for (int i = 0; i < m; i++)
p *= n;
return p;
}
private void button1_Click(object sender, EventArgs e)
{
int[] a = new int[5] { 1, 2, 3, 4, 5 };
int[] b = new int[5] { 1, 2, 3, 4, 5 };
int[] r = new int[5];
r = arr(a, b);
}
/////////////////////////////////////////
Q3
class base_Class
{
public base_Class()
{
MessageBox.Show("Base_Class");
}
}
class derivet_calss1:base_Class
{
public int squer;
public derivet_calss1(int t=0)
{
squer = t*t;
}
}
class derivet_class2:base_Class
{
public double circle;
public derivet_class2(double r=0)
{
circle = r * r * Math.PI;
}
}
class derivet_class3 : derivet_calss1
{
public int rectangle;
public derivet_class3(int x,int y)
{
rectangle = x * y;
}
}
class derivet_class4:derivet_class2
{
public double triangle;
public derivet_class4(int x,int y)
{
triangle = x * y * 0.5;
}
}
private void button1_Click(object sender, EventArgs e)
{
base_Class b = new base_Class();
derivet_calss1 d1 = new derivet_calss1(3);
derivet_class2 d2 = new derivet_class2(5);
derivet_class3 d3 = new derivet_class3(4, 6);
derivet_class4 d4 = new derivet_class4(9, 5);
textBox1.Text = d1.squer.ToString();
textBox2.Text = d2.circle.ToString();
textBox3.Text = d3.rectangle.ToString();
textBox4.Text = d4.triangle.ToString();
}
/////////////////////////////////////////
Q4
class drawing
{
public virtual void draw()
{
MessageBox.Show("drawing");
}
}
class line : drawing
{
public override void draw()
{
MessageBox.Show("line");
}
}
class circle : drawing
{
public override void draw()
{
MessageBox.Show("circle");
}
}
class square : drawing
{
public override void draw()
{
MessageBox.Show("square");
}
}
public int sum(int x,int y)
{
return x + y;
}
public int sum(int x,int y,int z)
{
return x + y + z;
}
public int sum(int[] x)
{
int sum = 0;
for (int i = 0; i < x.Length; i++)
sum += x[i];
return sum;
}
private void button1_Click(object sender, EventArgs e)
{
//polymorphpesm
drawing[] dobj = new drawing[4];
dobj[0] = new line();
dobj[1] = new circle();
dobj[2] = new square();
dobj[3] = new drawing();
foreach(drawing d in dobj)
{
d.draw();
}
//OverLoad
int x = 4, a = 6, f = 8;
int[] arr = new int[6] { 1, 6, 8, 5, 9, 5 };
textBox1.Text = sum(x,a).ToString();
textBox2.Text = sum(x,a,f).ToString();
textBox3.Text = sum(arr).ToString();
}