AWP Sem5
AWP Sem5
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());
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
> 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());
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];
Output
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
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;
}
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)
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;
class B : A
{
public int sum;
class C : B
{
void showSum()
{
Console.WriteLine("Addition is : " + sum);
}
Output
iii.Hierarchical Inheritance
using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter First Number:");
int num1 = Int32.Parse(Console.ReadLine());
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();
}
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();
Output
using System;
class demo
{
public delegate void add(int a, int b);
public delegate void division(float a, float b);
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());
Output
Practical - 3
> 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)
{
Output
b. Demonstrate the use of Calendar control to perform following operations
> WebForm1.aspx
<!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)
{
Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate,Calendar1.SelectedDate.
AddDays(10));
e.Cell.Text = "Ganpati Festival";
e.Cell.BackColor=System.Drawing.Color.Red;
}
}
}
}
Output