0% found this document useful (0 votes)
38 views63 pages

AWP Final

The document contains code snippets from C# class files that demonstrate various object-oriented programming concepts like inheritance, polymorphism, abstraction, and encapsulation. Some key examples include: 1. Demonstrating single, multi-level, and hierarchical inheritance between classes. 2. Overloading constructors and methods to achieve polymorphism. 3. Defining interfaces for common behaviors that classes can implement. 4. Using delegates and events to define callback functions and event handling patterns. The code provides examples of implementing concepts like inheritance, polymorphism, abstraction and encapsulation through C# class definitions, properties, methods and interfaces. It serves as a reference for learning and applying various OOP principles.

Uploaded by

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

AWP Final

The document contains code snippets from C# class files that demonstrate various object-oriented programming concepts like inheritance, polymorphism, abstraction, and encapsulation. Some key examples include: 1. Demonstrating single, multi-level, and hierarchical inheritance between classes. 2. Overloading constructors and methods to achieve polymorphism. 3. Defining interfaces for common behaviors that classes can implement. 4. Using delegates and events to define callback functions and event handling patterns. The code provides examples of implementing concepts like inheritance, polymorphism, abstraction and encapsulation through C# class definitions, properties, methods and interfaces. It serves as a reference for learning and applying various OOP principles.

Uploaded by

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

Pract_1

1(a)

public partial class WebForm1 : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
int a, b, c, d, sum;
a = Int32.Parse(TextBox1.Text);
b = Int32.Parse(TextBox2.Text);
c = Int32.Parse(TextBox3.Text);
d = Int32.Parse(TextBox4.Text);

sum = a + b + c + d;
TextBox5.Text = sum.ToString();
}
}

Pract_1(b)
Gautam Sakhare
(IF20040)
namespace WebApplication6
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
string s = TextBox1.Text;
Label1.Text = "String length: " + s.Length;
Label2.Text = "Substring: " + s.Substring(4, 3);
Label3.Text = "Upper String: " + s.ToUpper();
Label4.Text = "Lower String: " + s.ToLower();
string rev = ""; for (int i=
s.Length - 1; i >= 0; i--)
rev = rev + s[i];
Label5.Text = "Reverse String: " + rev.ToString();
Label6.Text = "Replace 's' by 't' in String: " + s.Replace('s', 't');
Label7.Text = "Insert 'u' in String: " + s.Insert(3, "u");
Label8.Text = "String Truncate: " + s.Trim();
Label9.Text = "Remove String: " + s.Remove(4);
Label10.Text= "Index of String: " + s.IndexOf('e');
}

protected void Button2_Click(object sender, EventArgs e)


{
Label1.Text = "";
Label2.Text = "";
Label3.Text = "";
Label4.Text = "";
Label5.Text = "";
Label6.Text = "";
Label7.Text = "";
Label8.Text = "";
Label9.Text = "";
Label10.Text = "";

}
}
}
OUTPUT:-

Atharva Jethva
(IF19023)
Pract_1(c)

namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void TextBox1_TextChanged(object sender, EventArgs e)


{

protected void Button1_Click(object sender, EventArgs e)


{
Label6.Text = "Student Id:" + TextBox1.Text;
Label7.Text = "Student Name:" + TextBox2.Text;
Label8.Text = "Course Name:" + TextBox3.Text;
Label9.Text = "Date of Birth" + Calendar1.SelectedDate.ToShortDateString();
}

protected void Button2_Click(object sender, EventArgs e)


{
Label1.Text = "";
Label2.Text = "";
Label3.Text = "";
Label4.Text = "";
Label6.Text = "";
Label7.Text = "";
Label8.Text = "";
Label9.Text = "";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
Label9.Text= "";

}
}
}
OUTPUT:-

Atharva Jethva
(IF19023)
Pract_1(d)

protected void Page_Load(object sender, EventArgs e)


{Label12.Text = "";
string[] ColorNames = new string[] { "Red", "Yellow", "Black",
"Green", "Blue", "Pink" };
foreach (string ColorName in ColorNames)
{
Label12.Text = Label12.Text + " " +
ColorName.ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{int a, b, c, i, n;
a = 0; b = 1;
Label6.Text = a.ToString() + b.ToString();
n = Convert.ToInt32(TextBox1.Text);
for (i = 1; i <= n; ++i)
{ c = a + b;
Label6.Text = Label6.Text + c.ToString();
a = b;
b = c;
}
}protected void Button2_Click(object sender, EventArgs
int i, c = 0, j, num;
num = Convert.ToInt32(TextBox2.Text);
for (j = 1; j <= num; j++)
{i = num % j; if (i == 0)
{ c = c + 1; }}
if (c == 2)
Label7.Text = "The given number is prime";
else
Label7.Text = "The given number is not prime";
}
protected void Button3_Click(object sender, EventArgs
{ long num, i, sum =
0; num =
Convert.ToInt32(Tex
tBox3.Text);
while (num > 0) {i = num % 10; sum = i + sum * 10;
num = num / 10; Label8.Text = sum.ToString();}}
protected void Button4_Click(object sender, EventArgs
e){ long num, i, sum = 0; num =
Convert.ToInt32(TextBox4.Text);
while (num > 0) { i = num %
10; sum = i + sum; num = num
/ 10;} Label9.Text =
sum.ToString();}
protected void Button5_Click(object sender, EventArgs e)
{char c = Convert.ToChar(TextBox5.Text);
switch (c)
{case 'a':
Label10.Text = "a is vowel";
break;
case 'e':
Label10.Text = "e is vowel";
break;
case 'i':
Label10.Text = "i is vowel";
break; case 'o':
Label10.Text = "o is vowel";
break; case 'u':
Label10.Text = "u is vowel";
break; default:
Label10.Text = "It is not vowel";
break; }
}
}

Atharva Jethva
(IF19023)
Pract 2(a)

i) Finding factorial Value:-


class fact {
public int n, f;
public fact()
{ f = 1; }
public void cal()
{
int i;
for(i=1; i<=n; i++)
{ f=f
* i;
}
} } protected void Button1_Click(object sender,
EventArgs e)
{fact f1 = new fact(); f1.n =
int.Parse(TextBox1.Text);
f1.cal();
Label2.Text=f1.f.ToString();
}
}
}

OUTPUT:-

Atharva Jethva
(IF19023)
Pract 2(a)
ii) Money Conversion:

protected void Button1_Click(object sender, EventArgs e)


{
curConv s = new curConv();
double r =
Convert.ToDouble(TextBox1.Text);
double rate = s.Dolr(r);
Label1.Text = rate.ToString();
} protected void Button2_Click(object sender, EventArgs
e)
{
curConv s = new curConv(); double r =
Convert.ToDouble(TextBox1.Text); double
rate = s.Euros(r);
Label2.Text = rate.ToString();
}
protected void Button3_Click(object sender, EventArgs e)
{
curConv s =new curConv(); double r =
Convert.ToDouble(TextBox1.Text); double
rate =s.Pound(r);
Label3.Text = rate.ToString();
} protected void Button4_Click(object sender, EventArgs
e)
{
curConv s =new curConv(); double r =
Convert.ToDouble(TextBox1.Text); double
rate = s.Yen(r);

Atharva Jethva
(IF19023)
Label4.Text = rate.ToString();
}
public class
curConv
{ public double
Dolr(double r)
{r=r*
0.015;
return r;}
public double Euros(double
r) {r = r * 0.012; return r;}
public double Pound(double r)
{ r = r * 0.011; return r; }
public double Yen(double r)
{ r = r * 1.64; return r; }

Pract 2(a) iii) Quadratic

Eqations
Atharva Jethva
(IF19023)
OUTPUT:-
Pract_2(a)

Atharva Jethva
(IF19023)
(iv) Temperature Conversion

Pract_2(b)
(i)Function Overloading
OUTPUT:-

Pract 2(b)

(ii)Inheritance(All Types)

1. Single Inhertance

Atharva Jethva
(IF19023)
Protected void Button1_Click(object sender, EventArgs e)

B s = new B(); int n =

Convert.ToInt32(TextBox1.Text); int x

= s.sqr(n); int y = s.cub(n);

Label1.Text = x.ToString();

Label2.Text = y.ToString();

public class A

public int sqr(int Val1)

{ return Val1 * Val1;

public class B : A

public int cub(int Val1)

int v1 = sqr(Val1);

return v1 * Val1;

}
Pract_2(b)

Atharva Jethva
(IF19023)
(ii) 2.Multi-Level Inheritance

protected void Button1_Click(object sender, EventArgs e)

{ C s = new C(); int n =

Convert.ToInt32(TextBox1.Text); int x

= s.pow2(n); int y = s.pow3(n); int z =

s.pow4(n);

Label1.Text = x.ToString();

Label2.Text = y.ToString();

Label3.Text = z.ToString();

public class A

public int pow2(int Val1)

return Val1 * Val1;

public class B : A

public int pow3(int Val1)

int v1 = pow2(Val1);

return v1 * Val1;

public class C : B

{
public int pow4(int Val1)

int v1 = pow3(Val1);

return v1 * Val1;

OUTPUT:-

Atharva Jethva
(IF19023)
Pract_2(b)
(ii) 3.Hierarchical Inheritance

public class A

public int a;

public int b;

public class B:A

public int add(int Val1,int Val2)

a = Val1; b

= Val2;

return a + b;

public class C : A

public int sub(int Val1, int Val2)

a = Val1; b = Val2;

return a - b;

public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object


sender, EventArgs e)

Atharva Jethva
(IF19023)
protected void Button1_Click(object sender, EventArgs e)

B s1 = new B(); C s2 = new C(); int m

= Convert.ToInt32(TextBox1.Text); int

n = Convert.ToInt32(TextBox2.Text);

int x = s1.add(m, n); int y = s2.sub(m,

n);

Label1.Text = x.ToString();

Label2.Text = y.ToString();

Atharva Jethva
(IF19023)
Pract_2(b)
(iii) Constructor Overloading

public partial class WebForm1 : System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e)

add obj1 = new add(2); add

obj2 = new add(2,3); add

obj3 = new add(2,3,4);

Label1.Text = obj1.r.ToString();

Label2.Text = obj2.r.ToString();

Label3.Text = obj3.r.ToString();

public class add

public int r;

public add(int a)

r = a + a;

public add(int a, int b)

r = a + b;

public add(int a, int b, int c)

r = a + b + c;
Atharva Jethva
(IF19023)
}

OUTPUT :-

(iv) Interfaces(Area of Circle & Reactangle)

Atharva Jethva
(IF19023)
Pract_2(b)

interface Area

double show(double s, double t);

class Rect : Area

public double show(double s, double t)

return s * t;

}}

class Circle : Area

public double show(double s, double t)

return (3.14 * s * s);

public partial class WebForm1 : System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e)

Rect r1 = new Rect();

double x = r1.show(3, 4);

Circle c1 = new Circle();

double y = c1.show(3, 4);

Atharva Jethva
(IF19023)
Label1.Text = x.ToString();

Label2.Text = y.ToString();

OUTPUT :-

Atharva Jethva
(IF19023)
Pract2_C
(i) Delegates and Events
public delegate string

dele(); public static string

display1()

string s1 = "Atharva Jethva";

return s1;

public static string display2()

string s2 = "Atharva Hitesh Jethva";

return s2;

protected void Page_Load(object sender, EventArgs e)

dele d1 = new dele(display1);

d1(); dele d2 = new dele(display2);

d2(); Label1.Text = d1();

Label2.Text = d2();

Atharva Jethva
(IF19023)
OUTPUT:-

Pract_2(c)
(ii) Exception Handling
try

Atharva Jethva
(IF19023)
{

int a = Convert.ToInt32(TextBox1.Text);

int[] b = { 12, 23, 33 };

int resultVal;

resultVal =(b[3]/a);

Label1.Text = "The result is :" + resultVal.ToString();

catch (System.DivideByZeroException ex)

Label1.Text = ex.ToString();

catch(System.IndexOutOfRangeException ex)

Label1.Text = ex.ToString();

OUTPUT:-

Atharva Jethva
(IF19023)
Pract_3(a)

Atharva Jethva
(IF19023)
Pract3_(b)

Atharva Jethva
(IF19023)
Atharva Jethva
(IF19023)
OUTPUT:-

Atharva Jethva
(IF19023)
Atharva Jethva
(IF19023)
Pract_3(c)

OUTPUT:-

Pract_3(c)

Atharva Jethva
(IF19023)
Pract_4(a)

Atharva Jethva
(IF19023)
Atharva Jethva
(IF19023)
Pract_4(b)

Atharva Jethva
(IF19023)
OUTPUT:-

Atharva Jethva
(IF19023)
Pract_4(c)

OUTPUT:-

Atharva Jethva
(IF19023)
Pract5_a

OUTPUT

Atharva Jethva
(IF19023)
Pract5_b

OUTPUT

Atharva Jethva
(IF19023)
Pract5_c

Atharva Jethva
(IF19023)
Output:-

Pract6_a

Atharva Jethva
(IF19023)
Atharva Jethva
(IF19023)
Pract6_b

OUTPUT:-

Atharva Jethva
(IF19023)
Pract6_c

Atharva Jethva
(IF19023)
OUTPUT:-

Atharva Jethva
(IF19023)
Pract7_a

Atharva Jethva
(IF19023)
Pract7_b

Atharva Jethva
(IF19023)
Prcat7_c

Atharva Jethva
(IF19023)
OUTPUT:-

Atharva Jethva
(IF19023)
Pract8_c

Atharva Jethva
(IF19023)
Pract9_a
Control template
Atharva Jethva
(IF19023)
OUTPUT

Atharva Jethva
(IF19023)
HyperLink

Output:-

Atharva Jethva
(IF19023)
Pract10_a

Atharva Jethva
(IF19023)
Atharva Jethva
(IF19023)
Pract10_c

Output:-

Pract_11

Atharva Jethva
(IF19023)
using System.Linq; using

System.Web; using

System.Web.UI; using

System.Web.UI.WebControls;

using TSClassLib; public partial class _Default :

System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e)

protected void Button1_Click(object sender, EventArgs e)

TS t = new TS();

TextBox1.Text = t.UpperConvert(TextBox1.Text);

protected void Button2_Click(object sender, EventArgs e)

TS t = new TS();

TextBox1.Text = t.LowerConvert(TextBox1.Text);

OUTPUT:-

Atharva Jethva
(IF19023)
Atharva Jethva
(IF19023)

You might also like