0% found this document useful (0 votes)
14 views27 pages

AWP Sem5

Awp syllabus for sem 5

Uploaded by

siddhantk22it
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)
14 views27 pages

AWP Sem5

Awp syllabus for sem 5

Uploaded by

siddhantk22it
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/ 27

Practical - 1

1.) Working with basic C# and ASP.NET

a. Create an application that obtains four int values from the user and
displays the product.

using System;
class demo
{
static void Main(string[] args)
{
int num1,num2,num3,num4,res;
Console.WriteLine("Enter First Number : ");
num1=Int32.Parse(Console.ReadLine());

Console.WriteLine("Enter Second Number : ");


num2 = Int32.Parse(Console.ReadLine());

Console.WriteLine("Enter Third Number : ");


num3 = Int32.Parse(Console.ReadLine());

Console.WriteLine("Enter Fourth Number : ");


num4 = Int32.Parse(Console.ReadLine());

res=num1*num2*num3*num4;
Console.WriteLine("Product is : " + res);
}
}

Output
b. Create an application to demonstrate string operations.

using System;

class demo
{
static void Main(string[] args)
{
// Define two strings
string str1 = "Hello";
string str2 = "World!!";

// Concatenation
string concat = str1 + " " + str2;
Console.WriteLine("Concatenated String: " + concat);

// Substring
string substring = concat.Substring(6, 5); // Extracts "World"
Console.WriteLine("Substring: " + substring);

// Uppercase
string upper = concat.ToUpper();
Console.WriteLine("Uppercase: " + upper);

// Lowercase
string lower = concat.ToLower();
Console.WriteLine("Lowercase: " + lower);

// Length
int len = concat.Length;
Console.WriteLine("Length: " + len);

// Replace
string replaced = concat.Replace("World", "C#");
Console.WriteLine("Replaced: " + replaced);

// Trim
string str = " Hello World ";
string str_trim = str.Trim();
Console.WriteLine("Trimmed: " + str_trim);

// Split
string[] words = concat.Split(' ');
Console.WriteLine("Split: ");
foreach (string word in words)
{
Console.WriteLine(word);
}

// Contains
bool str3 = concat .Contains("Hello");
Console.WriteLine("Contains 'Hello': " + str3);

// Join
string join = string.Join(" ", words);
Console.WriteLine("Joined: " + join);
}
}

Output

c. Programs to create and use DLL

> SampleLib(LibraryFile)
namespace SampleLib
{
public class Class1
{
public int add(int x,int y)
{
return x + y;
}
public int sub(int x, int y)
{
return x - y;
}
public int mul(int x, int y)
{
return x * y;
}
public float div(int x, int y)
{
return x / y;
}
}
}

> Sample(ConsoleApp)
using System;
using SampleLib;
class demo
{
public static void Main(String[] args)
{
Class1 c = new Class1();
int n1, n2;
Console.WriteLine("Enter First Number : ");
n1=Int32.Parse(Console.ReadLine());

Console.WriteLine("Enter Second Number : ");


n2 = Int32.Parse(Console.ReadLine());

Console.WriteLine("Addition is : "+(c.add(n1, n2)));


Console.WriteLine("Subtraction is : "+(c.sub(n1, n2)));
Console.WriteLine("Multiplication is : " + (c.mul(n1, n2)));
Console.WriteLine("Division is : " + (c.div(n1, n2)));
}
}

Output
d. Create an application to demonstrate following operations
i. Generate Fibonacci series.

using System;
class demo
{
static void Main(String[] args)
{
int a = 0, b = 1, c, i, range;
Console.WriteLine("Enter the Range of Fibonacci Series : ");
range = Int32.Parse(Console.ReadLine());
Console.WriteLine("Fibonacci Series : ");
Console.WriteLine(a);
Console.WriteLine(b);
for (i = 0; i < range - 2; i++)
{
c = a + b;
a = b;
b=c;
Console.WriteLine(c);
}

}
}

Output
ii. Test for prime numbers.

using System;
class demo
{
static void Main(String[] args)
{
int count = 0, num;
Console.WriteLine("Enter the Number : ");
num = int.Parse(Console.ReadLine());
for (int i = 1; i <= num; i++)
{
if (num % i == 0)
{
count++;
}
}
if (count == 2)
{
Console.WriteLine(num + " is a Prime Number");
}
else
{
Console.WriteLine(num + " is not a Prime Number");
}

}
}

Output
iii. Test for vowels.

using System;

class Vowel
{
static void Main(string[] args)
{
Console.Write("Enter a Character : ");
char ch = Console.ReadLine()[0];

if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||


ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
{
Console.WriteLine(ch + " is a vowel.");
}
else
{
Console.WriteLine(ch + " is not a vowel.");
}
}
}

Output

iv. Use of foreach loop with arrays

using System;

class demo
{
static void Main(string[] args)
{
int[] numbers = {12,15,30,25,7};
Console.Write("Array Elements are : ");
foreach (int number in numbers)
{
Console.Write(number + " ");
}
}
}

Output

v. Reverse a number and find the sum of digits of a number

using System;

class demo
{
static void Main(string[] args)
{
Console.Write("Enter a Number : ");
int number = int.Parse(Console.ReadLine());
int rev=0, sum=0, remainder, num=number;

while (number != 0)
{
remainder = number % 10;
rev = rev * 10 + remainder;
sum += remainder;
number /= 10;
}

Console.WriteLine("Original Number : " + num);


Console.WriteLine("Reversed Number : " + rev);
Console.WriteLine("Sum of Digits : " + sum);}}
Output
Practical - 2

2.) Create a simple application to demonstrate use of following concepts

a. Function Overloading

using System;
class prac
{
public static void area(int l, int b)
{
Console.WriteLine("Area of Rectangle:" + (l * b));
}
public static void area(int r)
{
Console.WriteLine("Area of Circle:" + (3.14*r*r));
}
public static void Main(string[] args)
{
Console.WriteLine("Enter Length: ");
int l=Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter Breath: ");
int b=Int32.Parse(Console.ReadLine());
area(l, b);
Console.WriteLine("Enter Radius: ");
int r=Int32.Parse(Console.ReadLine()) ;
area(r);
}
}

Output
b. Inheritance (all types)

i.Single Level Inheritance


using System;
class A
{
public int roll_no;
public String name;
public void getInfo(int r_no, String n)
{
roll_no = r_no;
name = n;
}
}

class B : A
{
void showInfo()
{
Console.WriteLine("NAME : " + name);
Console.WriteLine("ROLLNO : " + roll_no);
}
public static void Main(String[] args)
{
B b1 = new B();
A a1 = new A();
int r = 9468;
String s = "TRUPTI GAIKWAD";
b1.getInfo(r, s);
b1.showInfo();
}
}

Output
ii.Multi Level Inheritance
using System;

class A
{
public int num1;
public int num2;

public void getNum(int n1, int n2)


{
num1 = n1;
num2 = n2;
}
}

class B : A
{
public int sum;

public void addNum()


{
sum = num1 + num2;
}
}

class C : B
{

void showSum()
{
Console.WriteLine("Addition is : " + sum);
}

public static void Main(String[] args)


{
C c = new C();
c.getNum(20, 15);
c.addNum();
c.showSum(); }}

Output
iii.Hierarchical Inheritance
using System;

public class numbers


{
protected int number1;
protected int number2;

public void getNumbers(int num1, int num2)


{
number1 = num1;
number2 = num2;
}
}

public class Addition : numbers


{
public int performadd()
{
return number1 + number2;
}
}

public class Subtraction : numbers


{
public int performSub()
{
return number1 - number2;
}
}

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter First Number:");
int num1 = Int32.Parse(Console.ReadLine());

Console.WriteLine("Enter Second Number:");


int num2 = Int32.Parse(Console.ReadLine());

Addition add = new Addition();


Subtraction sub = new Subtraction();
add.getNumbers(num1, num2);
sub.getNumbers(num1, num2);

Console.WriteLine("Addition of " + num1 + " and " + num2 + " is: " +
add.performadd());
Console.WriteLine("Subtraction of " + num2 + " from " + num1 + " is: " +
sub.performSub());

}
}

Output

c. Constructor overloading

using System;

class demo
{
demo()
{
Console.WriteLine("Default Constructor is called!!");
}

demo(int s)
{
Console.WriteLine("Parameterized Constructor is Called!!");
Console.WriteLine("Area of Square is : " + (s * s));
}
public static void Main(String[] args)
{
demo d1 = new demo();
demo d2 = new demo(12);
}
}
Output

d. Interfaces

using System;

// Interface definition
public interface Shape
{
double CalculateArea();
}

public class Circle : Shape


{
private double radius;

public Circle(double radius)


{
this.radius = radius;
}

public double CalculateArea()


{
return Math.PI * radius * radius;
}
}

public class Rectangle : Shape


{
private double length;
private double width;

public Rectangle(double length, double width)


{
this.length = length;
this.width = width;
}
public double CalculateArea()
{
return length * width;
}
}

public class Triangle : Shape


{
private double baseLength;
private double height;

public Triangle(double baseLength, double height)


{
this.baseLength = baseLength;
this.height = height;
}

public double CalculateArea()


{
return 0.5 * baseLength * height;
}
}

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Radius of the Circle:");
double radius = Double.Parse(Console.ReadLine());
Shape circle = new Circle(radius);
Console.WriteLine("Area of the circle: " + circle.CalculateArea());
Console.WriteLine();

Console.WriteLine("Enter Length of the Rectangle:");


double length = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter Width of the Rectangle:");
double width = Double.Parse(Console.ReadLine());
Shape rectangle = new Rectangle(length, width);
Console.WriteLine("Area of the Rectangle: " + rectangle.CalculateArea());
Console.WriteLine();

Console.WriteLine("Enter Base Length of the Triangle:");


double baseLength = Double.Parse(Console.ReadLine());
Console.WriteLine("Enter Height of the triangle:");
double height = Double.Parse(Console.ReadLine());
Shape triangle = new Triangle(baseLength, height);
Console.WriteLine("Area of the Triangle: " + triangle.CalculateArea());
}
}

Output

e. Using Delegates and events

using System;
class demo
{
public delegate void add(int a, int b);
public delegate void division(float a, float b);

public void sum(int a,int b)


{
Console.WriteLine("Addition of " +a+ " and " +b+ " is : "+(a+b));
}

public void sub(int a, int b)


{
Console.WriteLine("Subtraction of " + a + " and " + b + " is : " + (a - b));
}

public void mul(int a, int b)


{
Console.WriteLine("Multiplication of " + a + " and " + b + " is : " + (a * b));
}
public void div(float a, float b)
{
Console.WriteLine("Division of " + a + " and " + b + " is : " + (a / b));
}

public static void Main(string[] args)


{
demo d=new demo();
add a1 = new add(d.sum);
division d1=new division(d.div);
add a2=new add(d.sub);
add a3 = new add(d.mul);
a1(25, 15);
a2(25, 15);
a3(25, 15);
d1(25, 10);
}
}

Output

f. Exception handling

using System;

class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Enter the First Number:");
int num1 = Int32.Parse(Console.ReadLine());

Console.WriteLine("Enter the Second Number:");


int num2 = Int32.Parse(Console.ReadLine());

int result = num1 / num2;


Console.WriteLine("Division of "+num1+ " and " +num2+ " is : " + result);
}
catch (FormatException)
{
Console.WriteLine("Error: Please enter a valid number.");
}
catch (DivideByZeroException)
{
Console.WriteLine("Error: Division by zero is not allowed.");
}
catch (Exception e)
{
Console.WriteLine("An unexpected error occurred: " + e.Message);
}
finally
{
Console.WriteLine("END OF THE PROGRAM");
}
}
}

Output
Practical - 3

3.) Perform the following concepts

a. Create a simple web page with various server controls to demonstrate


setting and use of their properties. (Example: AutoPostBack)

> WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="Prac3A.WebForm1" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Enhanced Form</title>
<style type="text/css">
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 0;
}
.form-container {
width: 50%;
margin: 5% auto;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.form-container table {
width: 100%;
}
.form-container td {
padding: 10px;
}
.form-container .label {
font-weight: bold;
color: #333;
}
.form-container .textbox, .form-container .radio-button {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
.form-container .button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
.form-container .button:hover {
background-color: #45a049;
}
.form-container .result-label {
margin-top: 20px;
color: #007BFF;
font-weight: bold;
}
</style>
</head>
<body>
<form id="form1" runat="server" class="form-container">
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" CssClass="label"
Text="NAME"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"
CssClass="textbox"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" CssClass="label"
Text="PASSWORD"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"
CssClass="textbox"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" CssClass="label"
Text="GENDER"></asp:Label>
</td>
<td>
<asp:RadioButton ID="RadioButton1" runat="server"
GroupName="GENDER" Text="MALE" CssClass="radio-button" />
<asp:RadioButton ID="RadioButton2" runat="server"
GroupName="GENDER" Text="FEMALE" CssClass="radio-button" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server" CssClass="label"
Text="CLASS"></asp:Label>
</td>
<td>
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="CLASS"
Text="FY-IT" CssClass="radio-button" />
<asp:RadioButton ID="RadioButton4" runat="server" GroupName="CLASS"
Text="SY-IT" CssClass="radio-button" />
<asp:RadioButton ID="RadioButton5" runat="server" GroupName="CLASS"
Text="TY-IT" CssClass="radio-button" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Button1" runat="server" Text="DISPLAY"
OnClick="Button1_Click" CssClass="button" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="Label5" runat="server" CssClass="result-label"></asp:Label>
</td>
</tr>
</table>
</form>
</body>
</html>
> WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Prac3A
{
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 name = TextBox1.Text;
string password = TextBox2.Text;

string gender = "";


if (RadioButton1.Checked)
{
gender = "MALE";
}
else if (RadioButton2.Checked)
{
gender = "FEMALE";
}

string userClass = "";


if (RadioButton3.Checked)
{
userClass = "FY-IT";
}
else if (RadioButton4.Checked)
{
userClass = "SY-IT";
}
else if (RadioButton5.Checked)
{
userClass = "TY-IT";
}
Label5.Text = "Name: " + name + "<br>Gender: " + gender + "<br>Class: " +
userClass;
}
}
}

Output
b. Demonstrate the use of Calendar control to perform following operations

i. Display messages in a calendar control


ii. Display vacation in a calendar control
iii. Selected day in a calendar control using style

> WebForm1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"


Inherits="prac3b.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">

<div>
<asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC"
BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Full"
FirstDayOfWeek="Monday" Font-Names="Verdana" Font-Size="8pt"
ForeColor="#663399" Height="200px" NextPrevFormat="ShortMonth"
ShowGridLines="True" Width="220px" OnDayRender="Calendar1_DayRender">
<DayHeaderStyle BackColor="#FFCC66" BorderColor="#CC0099"
Font-Bold="True" Height="1px" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
</asp:Calendar>

<br />
<asp:Button ID="Button1" runat="server" Height="32px" OnClick="Button1_Click"
Text="DISPLAY" Width="100px" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="Label2" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="Label3" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="Label4" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="Label5" runat="server"></asp:Label>
<br />
<br />

</div>
</form>
</body>
</html>

> WebForm1.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

protected void Button1_Click(object sender, EventArgs e)


{
Calendar1.Caption = "My Calendar";
Calendar1.FirstDayOfWeek=FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;

Label1.Text="Selected Date : "+Calendar1.SelectedDate.Date.ToString();


Label2.Text="Today's Date : "+Calendar1.TodaysDate.Date.ToString();
Label3.Text ="Specified Date : "+"19/7/2024";
TimeSpan d=new DateTime(2024,9,7)-DateTime.Now;
Label4.Text="Number of Days Remaining for Ganapati Vacation :
"+d.Days.ToString();
TimeSpan d2 = new DateTime(2024,12,31)-DateTime.Now;
Label5.Text="Days Remaining for 31st Dec : "+d2.Days.ToString();

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)


{
if(e.Day.Date.Day==15 && e.Day.Date.Month == 8)
{
e.Cell.BackColor=System.Drawing.Color.AliceBlue;
e.Cell.Text = "Independence Day";
}
if(e.Day.Date.Day==7 && e.Day.Date.Month == 9)
{
Calendar1.SelectedDate = new DateTime(2024, 9, 7);

Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate,Calendar1.SelectedDate.
AddDays(10));
e.Cell.Text = "Ganpati Festival";
e.Cell.BackColor=System.Drawing.Color.Red;
}
}
}
}
Output

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy