AWP Journal
AWP Journal
01
Aim:-
Write a console application that obtains four int values from the user and displays the
product.
Program:-
using System;
namespace GreaterNo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Four No.");
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
int c = Convert.ToInt32(Console.ReadLine());
int d = Convert.ToInt32(Console.ReadLine());
int prod = a * b * c * d;
Console.WriteLine("Product of given no. is: " + prod);
Console.ReadLine();
}
}
}
Output :
Enter Four No.
4
2
8
5
Product of given no. is: 320
Name:-
Roll No.:-
Practical No. 02
Aim:-
If you have two integers stored in variables var1 and var2, what Boolean tests can you
perform to see if one or the other (but not both) is greater than 10?
Program:-
using System;
namespace GreaterThan10
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Two No.:");
int var1 = Convert.ToInt32(Console.ReadLine());
int var2 = Convert.ToInt32(Console.ReadLine());
if (var1 > 10 && var2 > 10)
{
Console.WriteLine("Both Are Greater Than 10 ");
}
else if (var1 >10 && var2<10)
{
Console.WriteLine(var1 + " Is Greater Than 10");
}
else if(var1 <10 && var2 >10)
{
Console .WriteLine (var2+" Is Greater Than 10");
}
else
{
Console.WriteLine("Both Are Less Than 10 ");
}
Console.ReadLine();
}
}
}
Output:
Enter Two No.:
3
12
12 Is Greater Than 10
Name:-
Roll No.:-
Practical No. 03
Aim:-
Write an application that includes the logic from Exercise 1, obtains two numbers from
the user, and displays them, but rejects any input where both numbers are greater than 10 and
asks for two new numbers.
Program:-
using System;
namespace pract1b
{
class Program
{
static void Main(string[] args)
{
int var1, var2;
l1:Console.WriteLine("enter no");
var1 = Convert.ToInt32(Console.ReadLine());
var2 = Convert.ToInt32(Console.ReadLine());
if(var1 >10&&var2<10)
{
Console.WriteLine("var1 is greater ");
}
else if(var2>10 && var1<10)
{
Console.WriteLine("var2 is greater");
}
else if(var1>10 && var2>10)
{
Console.WriteLine("re-enter the no.");
goto l1;
}
else
{
Console.WriteLine("both are less");
}
Console.ReadLine();
}
}
}
Output:
enter no
18
5
var1 is greater
Name:-
Roll No.:-
Practical No. 04
Aim:-
Write a program in C# to generate Fibonacci series
Program:-
using System;
namespace fibo
class Program
{
static void Main(string[] args)
{
int a=0, b=1, c;
Console.WriteLine("Fibonacci series");
for (int i = 0; i <= 10; i++)
{
c= a + b;
a = b;
b = c;
Console.Write(c +" ");
}
Console.ReadLine();
}
}
}
Output:
Fibonacci series
1 2 3 5 8 13 21 34 55 89 144
Practical No. 05
Name:-
Roll No.:-
Aim:-
Write a Program in C# to Reverse No.
Program:-
using System;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int num,rev=0,digit;
Console.WriteLine("Enter the number");
num = Convert.ToInt32(Console.ReadLine());
while (num > 0)
{
digit = num % 10;
rev = rev * 10 + digit;
num = num / 10;
}
Console.WriteLine("Reverse number :{0}",rev);
Console.ReadKey();
}
}
}
OUTPUT
Enter the number
1234
Reverse number :4321
Practical No. 6
Name:-
Roll No.:-
Aim:-
Write a Program to Palindrome Method using C#.
Program:-
using System;
namespace ConsoleApplication3
{
class Program
{
public static int reverse(int num)
{
int revnum=0,digit;
while (num > 0)
{
digit = num % 10;
revnum = revnum * 10 + digit;
num = num / 10;
}
return (revnum);
}
public static bool IsPalindrome(int num)
{
if (reverse(num) == num)
return (true);
else
return (false);
}
OUTPUT:
Enter the number 121
Reverse of 121=121
Number is Palindrome
Practical No. 07
Name:-
Roll No.:-
Aim:-
Write program in C# to test number entered by user is prime number or not.
Program:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace prime_no
{
class Program
{
static void Main(string[] args)
{ int flag=0;
Console.WriteLine("Enter no:");
int a = Convert.ToInt32(Console.ReadLine());
for (int j = 2; j <a ; j++)
{
if (a == 2)
{ break; }
if ((a%j)==0)
{
flag=1;
break;
}
else
{
continue; } }
if(flag==0)
{ Console.WriteLine(“given no”+a+”is prime”); }
else
{ Console.WriteLine(“given no”+a+”is not prime”);
}
Console.ReadLine();
}
}
}
Output::
Enter no:
5
given No 5 is prime
PRACTICAL NO:8
Name:-
Roll No.:-
Aim:-
Write program in C# to Generate prime numbers Series.
Program:-
using System;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int i, j;
Console.WriteLine("Enter min value:");
int min = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter mix value:");
int max = Convert.ToInt32(Console.ReadLine());
for (i = min; i <= max; i++)
{
for (j = 2; j <= i/2; j++)
{
if ((i%j) == 0)
break;
}
if (i == 1)
Console.WriteLine(i + " is neither prime not composite");
else if(j>(i/2))
Console.Write(i +"\t");
}
Console.ReadLine();
}
}
}
OUTPUT
Enter min value:
1
Enter mix value:
50
1 is neither prime not composite
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
Practical No. 9
Name:-
Roll No.:-
Aim:-
Write a program to reverse a number and find sum of digits of a number.
Program:-
using System;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int num,rev=0,digit,sumdigit=0;
Console.WriteLine("Enter the number");
num = Convert.ToInt32(Console.ReadLine());
while (num > 0)
{
digit = num % 10;
rev = rev * 10 + digit;
sumdigit = sumdigit + digit;
num = num / 10;
}
Console.WriteLine("Reverse number :{0}",rev);
Console.WriteLine("Sum of Digit :{0}",sumdigit);
Console.ReadKey();
}
}
}
OUTPUT
Enter the number
123
Reverse number :321
Sum of Digit :6
Practical No. 10
Aim:-
Name:-
Roll No.:-
Write a program to Test for vowels.
Program:-
using System;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
char ch;
Console.WriteLine("Enter the charecter");
ch = (char)Console.Read();
switch (ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
Console.WriteLine(ch + " is Vowel");
break;
default:
Console.WriteLine(ch + " is not a Vowel");
break;
}
Console.ReadKey();
}
}
}
OUTPUT
Enter the charecter
a
a is Vowel
Practical No. 11
Name:-
Roll No.:-
Aim:-
Write an application that uses two command-line arguments to place values into a string
and an integer variable, respectively then display these values.
Program:-
using System;
namespace P1E
{
class Program
{
static void Main(string[] args)
{
string name;
int rollno;
name =args[0];
rollno = Convert.ToInt32(args[1]);
Console.WriteLine("string parameter is {0}",name);
Console.WriteLine("integer parameter is {0}",rollno);
Console.ReadLine();
}
}
}
OUTPUT:
C:\Program Files\Microsoft Visual Studio 11.0>cd..
C:\Program Files>cd..
C:\>cd C:\tyit12\P1E\P1E
C:\tyit12\P1E\P1E>CSC Program.cs
Microsoft (R) Visual C# Compiler version 4.0.30319.17929
for Microsoft (R) .NET Framework 4.5
Copyright (C) Microsoft Corporation. All rights reserved.
C:\tyit12\P1E\P1E>Program sushmita 17
string parameter is sushmita
integer parameter is 17
Practical No. 12
Name:-
Roll No.:-
Aim:-
Generate various patterns with numbers.
A 1
1 2
1 2 3
Program:-
using System;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int i,j;
for (i = 1; i <= 3; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write(i + " ");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
B 1
2 2
3 3 3
Program:-
using System;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int i,j;
for (i = 1; i <= 3; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write(J + " ");
}
Name:-
Roll No.:-
Console.WriteLine();
}
Console.ReadKey();
}
}
}
C *
* *
* * *
Program:-
using System;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int i,j;
for (i = 1; i <= 3; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write("* ");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
D 3 2 1
3 2
1
Program:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int i,j;
for (i = 1; i <= 3; i++)
Name:-
Roll No.:-
{
for (j = 3; j >= i; j--)
{
Console.Write(j+" ");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
E 3 3 3
2 2
1
Program:-
using System;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int i,j;
for (i = 3; i >= 1; i--)
{
for (j = 1; j <= i; j++)
{
Console.Write(i+" ");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
Practical No. 13
Name:-
Roll No.:-
Aim:-
Write a program to Test use of for each loop with arrays.
Program:-
using System;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int []arr=new int []{1,2,3,4,5,6,7,8,9,10};
foreach(int i in arr)
{
Console.Write(i + " ");
}
Console.ReadKey();
}
}
}
OUTPUT
1 2 3 4 5 6 7 8 9 10
Practical No. 14
Aim:-
Write a C# Program for implementing the concept of Recursive Method
Name:-
Roll No.:-
Program:-
using System;
namespace CalculatorApplication
{
class NumberManipulator
{
public int factorial(int num)
{
int result;
if (num == 1)
{
return 1;
}
else
{
result = factorial(num - 1) * num;
return result;
}
}
static void Main(string[] args)
{
NumberManipulator n = new NumberManipulator();
Console.WriteLine("Factorial of 6 is : {0}", n.factorial(6));
Console.WriteLine("Factorial of 7 is : {0}", n.factorial(7));
Console.WriteLine("Factorial of 8 is : {0}", n.factorial(8));
Console.ReadLine();
}
}
}
OUTPUT
Factorial of 6 is: 720
Factorial of 7 is: 5040
Factorial of 8 is: 40320
Practical No. 15
Aim:-
Write a C# Program for implementing the concept of jagged array
Name:-
Roll No.:-
Program:-
using System;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int[][] jaggedArray = new int[4][];
jaggedArray[0] = new int[2] { 7, 9 };
jaggedArray[1] = new int[4] { 12, 42, 26, 38 };
jaggedArray[2] = new int[6] { 3, 5, 7, 9, 11, 13 };
jaggedArray[3] = new int[3] { 4, 6, 8 };
for (int i = 0; i < jaggedArray.Length; i++)
{
System.Console.Write("Element({0}): ", i + 1);
for (int j = 0; j < jaggedArray[i].Length; j++)
{
System.Console.Write(jaggedArray[i][j] + "\t");
}
System.Console.WriteLine();
}
Console.ReadLine();
}
}
}
OUTPUT
Element(1): 7 9
Element(2): 12 42 26 38
Element(3): 3 5 7 9 11 13
Element(4): 4 6 8
Practical No. 16
Aim:-
Write a console application that places double quotation marks around each word in a
string.
Name:-
Roll No.:-
Program:-
using System;
namespace P1D
{
class Program
{
static void Main(string[] args)
{
string str;
str = Console.ReadLine();
string[] word = str.Split();
foreach(string i in word)
{
Console.WriteLine("\"{0}\"",i);
}
Console.ReadLine();
}
}
}
OUTPUT:
sushmita sneha sayali kirtika
"sushmita"
"sneha"
"sayali"
"kirtika"
Practical No. 17
Aim:-
Write a program that takes two inputs as string from the users and performs the
following task:-
Name:-
Roll No.:-
a. First, the program copies the input of string2 to string3 and checks for the string3 ends with
‘ide’ or not. The program shows true if the string3 ends with ‘ide’.
b. Further, the program searches char ‘a’ from stringand returns the appropriate result.
c. Then inserts ‘hello’ in the string2 at position 5.
d. After performing the string manipulations, display all the strings at each level of the
manipulation.
Program:-
using System;
namespace Practical_no_17
{
class Program
{
static void Main(string[] args)
{
string str1, str2, str3;
Console.WriteLine("Enter first string");
str1 = Console.ReadLine();
Console.WriteLine("Enter second string");
str2 = Console.ReadLine();
str3 = string.Copy(str2);
Console.WriteLine("String 1 :" + str1);
Console.WriteLine("String 2 :" + str2);
Console.WriteLine("String 3 :" + str3);
Console.WriteLine("Check String 3 ends with 'ide' ? :"+str3.EndsWith("ide"));
Console.WriteLine("String 1 contains 'a' :" + str1.Contains("a")+ "at position
"+str1.IndexOf("a"));
Console.WriteLine("String 2 after inserting 'Hello' at 5th position " + str2.Insert(5, "Hello"));
Console.ReadKey();
}
}
}
OUTPUT
Enter first string
ckt
Enter second string
college
String 1 :ckt
String 2 :college
String 3 :college
Check String 3 ends with 'ide' ? :False
String 1 contains 'a' :Falseat position -1
String 2 after inserting 'Hello' at 5th position colleHelloge
Practical No. 18
Aim:-
Write an application that receives the following information from a set of students
Student Id, Student Name, Course Name, Date of Birth. The application should also display the
information of all the students once the data is entered. Implement this using an Array of
Structs.
Name:-
Roll No.:-
Program:-
using System;
namespace Practical_no_17
{
class Program
{
struct student
{
public string Student_Id, Student_Name, Course_Name;
public int day,month,year;
}
static void Main(string[] args)
{
student[] s = new student[5];
int i;
for (i = 0; i < 5; i++)
{
Console.Write("Enter the Student Id : ");
s[i].Student_Id = Console.ReadLine();
Console.Write("Enter the Student Name : ");
s[i].Student_Name = Console.ReadLine();
Console.Write("Enter the Course Name : ");
s[i].Course_Name = Console.ReadLine();
Console.Write("Enter the Day : ");
s[i].day = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the Month : ");
s[i].month = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the Year : ");
s[i].year = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Student List");
for (i = 0; i < 5; i++)
{
Console.WriteLine("Student Id :" + s[i].Student_Id);
Console.WriteLine("Student Name :" + s[i].Student_Name);
Console.WriteLine("Course Name :" + s[i].Course_Name);
Console.WriteLine("Enter the Day :" + s[i].day);
Console.WriteLine("Enter the Month :" + s[i].month);
Console.WriteLine("Enter the Year :" + s[i].year);
Console.WriteLine("***************************************************");
}
Console.ReadKey();
}
}
}
OUTPUT
Enter the Student Id : 1
Enter the Student Name : AMAR
Enter the Course Name : BCOM
Name:-
Roll No.:-
Enter the Day : 01
Enter the Month : 04
Enter the Year : 1980
Enter the Student Id : 2
Enter the Student Name : REEMA
Enter the Course Name : BA
Enter the Day : 09
Enter the Month : 07
Enter the Year : 1980
Enter the Student Id : 3
Enter the Student Name : ROHAN
Enter the Course Name : BA
Enter the Day : 04
Enter the Month : 02
Enter the Year : 1980
Enter the Student Id : 4
Enter the Student Name : GOPAL
Enter the Course Name : BSC
Enter the Day : 09
Enter the Month : 12
Enter the Year : 1980
Enter the Student Id : 5
Enter the Student Name : ROHIT
Enter the Course Name : BSC
Enter the Day : 09
Enter the Month : 12
Enter the Year : 1980
Student List
Student Id :1
Student Name :AMAR
Course Name :BCOM
Enter the Day :1
Enter the Month :4
Enter the Year :1980
***************************************************
Student Id :2
Student Name :REEMA
Course Name :BA
Enter the Day :9
Enter the Month :7
Enter the Year :1980
***************************************************
Student Id :3
Student Name :ROHAN
Course Name :BA
Enter the Day :4
Enter the Month :2
Enter the Year :1980
***************************************************
Student Id :4
Name:-
Roll No.:-
Student Name :GOPAL
Course Name :BSC
Enter the Day :9
Enter the Month :12
Enter the Year :1980
***************************************************
Student Id :5
Student Name :ROHIT
Course Name :BSC
Enter the Day :9
Enter the Month :12
Enter the Year :1980
***************************************************
Practical No. 19
Aim:-
Create a class “student” having two user defined properties to read and write the
student name and roll number respectively. Further use these user defined properties to
generate 5 students record.
Name:-
Roll No.:-
Program:-
using System;
namespace Using_Interface
{
class student
{
private int roll_no;
private string sname;
public int RollNo
{
get {return roll_no;}
set {roll_no =value;}
}
public string Name
{
get {return sname;}
set {sname =value;}
}
public student()
{
Console.WriteLine("Enter the student roll no : ");
RollNo=int.Parse(Console.ReadLine());
Console.WriteLine("Enter the student Name : ");
Name=Console.ReadLine();
}
public student getstudent()
{
return(new student());
}
public void display()
{
Console.WriteLine("Roll No : "+ RollNo);
Console.WriteLine("Name : "+ Name);
}
}
class Program
{
public static void Main(string[] args)
{
student[] s=new student[5];
for(int i=0;i<5;i++)
s[i]=new student();
foreach(student st in s)
st.display();
Console.ReadLine();
}
}
}
Name:-
Roll No.:-
OUTPUT
Enter the student roll no :
11
Enter the student Name :
rohit
Enter the student roll no :
12
Enter the student Name :
shilpa
Enter the student roll no :
13
Enter the student Name :
seema
Enter the student roll no :
14
Enter the student Name :
prasad
Enter the student roll no :
15
Enter the student Name :
renuka
Roll No : 11
Name : rohit
Roll No : 12
Name : shilpa
Roll No : 13
Name : seema
Roll No : 14
Name : prasad
Roll No : 15
Name : renuka
Name:-
Roll No.:-
Practical No. 20
Aim:-
Define a class which has three functions with the same name “square”. The first
function will take a value as an argument. The second function will take reference as an
argument. And the third function will take out parameter as an argument to the function. Use
main method to call all the functions.
Name:-
Roll No.:-
Program:-
using System;
namespace parameter
{
class Program
{
static int square(int a)
{
return (a * a);
}
static int square(ref int a)
{
return (a * a);
}
static void square(int a, out int o)
{
o = a * a;
}
static void Main(string[] args)
{
int a = 10,b=5,c=3,d;
Console.WriteLine("The first function will take a value as an argument. : " + square(a));
Console.WriteLine("The second function will take reference as an argument. :" + square(ref
b));
square(c, out d);
Console.WriteLine("The third function will take out parameter as an argument : " + d );
Console.ReadLine();
}
}
}
OUTPUT
The first function will take a value as an argument. : 100
The second function will take reference as an argument. :25
The third function will take out parameter as an argument : 9
Practical No. 21
Aim:-
Design a class to represent a bank account. Include the following members:-
Data members: Methods:
i. Name of the depositor. i. To assign initial values.
ii. Account number. ii. To deposit an amount.
iii. Type of account. iii. To withdraw an amount after checking
iv. Balance amount in the account. balance.
Name:-
Roll No.:-
iv. To display the name and balance.
Create one bank account to implement the above methods.
Program:-
using System;
namespace ConsoleApplication9
{
class BankException : Exception
{
public BankException(string msg): base(msg)
{ }
}
class Account
{
private string Name;
private string AccountType;
private long AcctNumber;
private double Balance;
public override string ToString()
{
return Name + " " + Balance;
}
public Account()
{
Console.WriteLine("Enter the Account number :");
AcctNumber = long.Parse(Console.ReadLine());
Console.WriteLine("Enter the Name of Depositer :");
Name = Console.ReadLine();
Console.WriteLine("Enter Type of Account :");
AccountType = Console.ReadLine();
Console.WriteLine("Enter Balance:");
Balance = double.Parse(Console.ReadLine());
}
public void Withdraw(double Amount)
{
try
{
if (Balance - Amount < 0) throw new BankException("Not sufficient Balance");
else
Balance -= Amount;
}
catch (BankException b)
{
Console.WriteLine(b.Message);
}
}
public void deposit(double Amount)
{
Balance += Amount;
}
Name:-
Roll No.:-
}
class program
{
static void Main(string[] args)
{
Account a = new Account();
a.deposit(5000.00);
a.Withdraw(5400.00);
Console.WriteLine(a.ToString ());
a.Withdraw(2000);
Console.WriteLine(a.ToString());
Console.ReadKey();
}
}
}
OUTPUT
Enter the Account number :
129212
Enter the Name of Depositer :
ckt
Enter Type of Account :
saving
Enter Balance:
200
Not sufficient Balance
ckt 5200
ckt 3200
Practical No. 22
Aim:-
Write a program in C# to define two methods of same name(area()) ,where one method
calculates area of triangle, second calculates area of circle.
Program:-
using System;
namespace parameter
{
Name:-
Roll No.:-
class Program
{
static double area(int l,int b)
{
return (0.5 * l * b);
}
static double area(int r)
{
return (3.14 * r*r);
}
static void Main(string[] args)
{
int length,breadth, radius;
Console.WriteLine("Enter the Length and Breadth");
length =Convert.ToInt32(Console.ReadLine());
breadth = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the Radius");
radius = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Area of Traingle : " + area(length,breadth));
Console.WriteLine("Area of Circle :" +area(radius ));
Console.ReadLine();
}
}
}
OUTPUT
Enter the Length and Breadth
5
3
Enter the Radius
2
Area of Traingle : 7.5
Area of Circle :12.56
Practical No. 23
Aim:-
Write a program for Function Overloading in C#.
Program:-
using System;
namespace UsingMethodOverloading
{
class volumefind
{
Name:-
Roll No.:-
public int volume(int s)
{
return (s * s * s);
}
public double volume(float r, float h)
{
return (3.14 * r * r * h);
}
public double volume(float l, float b, float h)
{
return (l * b * h);
}
class Program
{
static void Main(string[] args)
{
volumefind v = new volumefind();
int cube =v. volume(5);
double cylender = v.volume(4.5F, 6.15F);
double box =v. volume(4.5F, 7.9F, 12.7F);
Console.WriteLine("volume of cube=" + cube);
Console.WriteLine("volume of cylender=" + cylender);
Console.WriteLine("volume of box=" + box);
Console.ReadLine();
}
}
}
}
Output:
volume of cube=125
volume of cylender=391.047756063938
volume of box=451.484998669624
Practical No. 24
Aim:-
Design C# program to demonstrate different types Inheritance.
Simple Inheritance
Program:-
using System;
namespace UsingSingleInheritance
{
class company
Name:-
Roll No.:-
{
public void Companyname()
{
Console .WriteLine ("Name of the company:");
String cn = Convert.ToString(Console.ReadLine());
}
public void CompanyAddress()
{
Console.WriteLine("Address of company:");
String ca = Convert.ToString(Console.ReadLine());
}
}
class Employee : company
{
public void NameOfEmployee()
{
Console.WriteLine("Name of the Employee:");
String en = Convert.ToString(Console.ReadLine());
}
public void Salary()
{
Console.WriteLine("Salary of the Employee:");
int s = Convert.ToInt32(Console.ReadLine());
}
}
class Program
{
static void Main(string[] args)
{
Employee emp = new Employee();
emp.Companyname();
emp.CompanyAddress();
emp.NameOfEmployee();
emp.Salary();
}
}
}
Output:
Name of the company:
ICICI Company
Address of company:
Mumbai
Name of the Employee:
Janki
Salary of the Employee:
25000
Name:-
Roll No.:-
Hirarchy Inheritance.
Program:-
using System;
class headoffice
{
public void headofficeadd()
{
Console.WriteLine("head office address");
}
}
class branchoffice1 : headoffice
{
public void branchofficeadd()
{
Console.WriteLine("branch office address");
}
}
class branchoffice2 : headoffice
{
public void branchofficeadd()
{
Console.WriteLine("branch office address");
}
}
namespace p2c2hierarchical
{
class Program
{
static void Main(string[] args)
{
branchoffice2 b2 = new branchoffice2();
b2.headofficeadd();
b2.branchofficeadd();
Console.ReadLine();
}
}
}
Output:
head office address
branch office address
Hybrid Inheritance.
Program:-
using System;
class headoffice
{
Name:-
Roll No.:-
public void headofficeadd()
{
Console.WriteLine("head office address");
}
}
class branchoffice1 : headoffice
{
public void branchofficeadd()
{
Console.WriteLine("branch office address");
}
}
class branchoffice2 : headoffice
{
public void branchofficeadd()
{
Console.WriteLine("branch office address");
}
}
class employee : branchoffice2
{
public void nameofemp()
{
Console.WriteLine("name of the employee");
}
public void salary()
{
Console.WriteLine("salary of employee");
}
}
namespace p2c2hybrid
{
class Program
{
static void Main(string[] args)
{
employee e = new employee();
e.headofficeadd();
e.branchofficeadd();
e.branchofficeadd();
e.nameofemp();
e.salary();
Console.ReadLine();
}
}
}
Output:
Name:-
Roll No.:-
head office address
branch office address
branch office address
name of the employee
salary of employee
Multilevel Inheritance.
Program:-
using System;
namespace UsingMultilevelInheritance
{
class HeadOffice
{
public void HeadOfficeAddress()
{
Console .WriteLine ("Addresss of the Head Office:");
String ha = Convert.ToString(Console.ReadLine());
}
}
class BranchOffice : HeadOffice
{
public void BranchOfficeAddrss()
{
Console.WriteLine("Address of the Branch office:");
String ba = Convert.ToString(Console.ReadLine());
}
}
class Employee : BranchOffice
{
public void NameOfTheEmployee()
{
Console.WriteLine("Name of the Employee:");
String en = Convert.ToString(Console.ReadLine());
}
public void salary()
{
Console.WriteLine("Salary of the Employee:");
int s = Convert.ToInt32(Console.ReadLine());
}
}
class Program
{
static void Main(string[] args)
{
Employee emp = new Employee();
emp.HeadOfficeAddress();
emp.BranchOfficeAddrss();
emp.NameOfTheEmployee();
Name:-
Roll No.:-
emp.salary();
}
}
}
Output:
Addresss of the Head Office:
Mumbai
Address of the Branch office:
Pune
Name of the Employee:
Janki
Salary of the Employee:
25000
Practical No. 25
Aim:-
Write a program to for Constructor Overloading in C#.
Program:-
using System;
namespace Constructor_Overloading
{
class GameScore
Name:-
Roll No.:-
{
string user;
int age;
public GameScore()
{
user = "Steven";
age = 28;
Console.WriteLine("Previous User {0} and he was {1} year old", user, age);
}
public GameScore(string name, int age1)
{
user = name;
age = age1;
Console.WriteLine("Current User {0} and he is {1} year old", user, age);
}
}
class Program
{
static void Main(string[] args)
{
GameScore gs = new GameScore();
GameScore gs1 = new GameScore("Clark", 35);
Console.ReadLine();
}
}
}
OUTPUT
Previous User Steven and he was 28 year old
Current User Clark and he is 35 year old
Practical No. 26
Aim:-
Write a program to perform factorial of a number by overloading three constructor
methods viz: default constructor, parameterized constructor and copy constructor respectively.
Further create a “show()” method to display the factorial of the number.
Program:-
using System;
namespace Constructor_Overloading
Name:-
Roll No.:-
{
class Sample
{
public int n;
public Sample()
{
n = 5;
}
public Sample(int x)
{
n = x;
}
public Sample(Sample s)
{
n = s.n;
}
public void show()
{
int f = 1;
while (n > 1)
{
f = f * n;
n--;
}
Console.WriteLine("Factorial : " + f);
}
}
class Program
{
static void Main(string[] args)
{
Sample de = new Sample();
Sample pa = new Sample(6);
Sample co = new Sample(pa.n);
de.show();
pa.show();
co.show();
Console.ReadLine();
}
}
}
OUTPUT
Factorial : 120
Factorial : 720
Factorial : 720
Name:-
Roll No.:-
Practical No. 27
Aim:-
Design three constructors for the same class named “complexaddition”. The first
constructor should be the default constructor having no arguments. It is used to create objects
which are not initialized. The second constructor takes one argument; it is used to create objects
and initialize them. The third constructor takes two arguments; it is also used to create objects
and initialize them to specific value. Create a method “sum” which takes two arguments of type
complexaddition and also return a value of type complexaddition. Use this method to perform
the addition of two complex numbers of type complexaddition. Class “complexaddition” also
has two data members named real and imaginary.
Name:-
Roll No.:-
Program:-
using System;
namespace numbers
{
class ComplexAddition
{
public int real;
public int imaginary;
public ComplexAddition()
{
real = 1;
imaginary = 1;
}
public ComplexAddition(int Tempreal, int Tempimaginary)
{
real = Tempreal;
imaginary = Tempimaginary;
}
public ComplexAddition(ComplexAddition c)
{
real = c.real;
imaginary = c.imaginary;
}
public ComplexAddition sum(ComplexAddition c1, ComplexAddition c2)
{
ComplexAddition CTemp = new ComplexAddition();
CTemp.real = c1.real + c2.real;
CTemp.imaginary = c1.imaginary + c2.imaginary;
return CTemp;
}
}
class TestComplex
{
static void Main()
{
ComplexAddition c1 = new ComplexAddition(4, 8);
ComplexAddition c2 = new ComplexAddition(5, 7);
ComplexAddition c3 = new ComplexAddition();
ComplexAddition c4 = new ComplexAddition(c2);
c3 = c3.sum(c1,c4);
Console.WriteLine("-----Sum-----");
Console.WriteLine("Real : " + c3.real);
Console.WriteLine("Imaginary : " + c3.imaginary);
Console.ReadKey();
}
}
}
Name:-
Roll No.:-
OUTPUT
-----Sum-----
Real : 9
Imaginary : 15
Practical No. 28
Aim:-
Write a Program to demonstrate the implementation of exception handling.
Using System;
namespace ErrorHandlingApplication
{
class DivNumbers
{
int result;
Name:-
Roll No.:-
DivNumbers()
{
result = 0;
}
public void division(int num1, int num2)
{
try
{
result = num1 / num2;
}
catch (DivideByZeroException e)
{
Console.WriteLine("Exception caught: {0}", e);
}
finally
{
Console.WriteLine("Result: {0}", result);
}
}
static void Main(string[] args)
{
DivNumbers d = new DivNumbers();
d.division(25, 0);
Console.ReadKey();
}
}
}
OUTPUT
Exception caught: System.DivideByZeroException: Attempted to divide by zero.
at ...
Result: 0
Practical No. 29
Aim:-
Create user defined exception “bankexception” which will throw the exception when the
balance amount is less than 500 into the account. Write a program to show the use of “bank
exception”.
Program:-
using System;
namespace ConsoleApplication2
{
Name:-
Roll No.:-
class TestBank
{
static void Main(string[] args)
{
Bank bank = new Bank();
try
{
bank.showBalance();
}
catch(BankException e)
{
Console.WriteLine("AmountIsLessException: {0}", e.Message);
}
Console.ReadKey();
}
}
}
public class BankException: ApplicationException
{
public BankException(string message): base(message)
{
}
}
public class Bank
{
int amount = 499;
public void showBalance()
{
if(amount <500)
{
throw (new BankException("The balance amount is less than 500"));
}
else
{
Console.WriteLine("Bank: {0}", amount );
}
}}
Practical No. 30
Aim:-
Write a program to overload a function ”calculation()” three times to perform the
following:-
a. Factorial of a integer value (taking int as argument and return type).
b. Reverse of a long value (taking long as argument but no return type).
c. Adding three integer values without using ‘+’ operator (with 3 int argument and int return
type). Use main method to call all the functions.
Program:-
Name:-
Roll No.:-
using System;
namespace ConsoleApplication8
{
class CalculationMethod
{
public int Calculation(int num)
{
if (num <= 1)
return (1);
else
return(num * Calculation(num - 1));
}
void Calculation(long num)
{
long m, r = 0;
while (num > 0)
{
m = num % 10;
r = r * 10 + m;
num /= 10;
}
Console.WriteLine("Reverse of {0} is {1}", num, r);
}
public int Calculation(int num1, int num2, int num3)
{
return (num1-~num2-1- ~num3-1);
}
static void Main(string[] args)
{
CalculationMethod cm = new CalculationMethod();
Console.WriteLine("Factorial of 5 is" + cm.Calculation(5));
cm.Calculation(243767665621);
Console.WriteLine("Addition of 3, 4,2 without '+' operator = " + cm.Calculation(3,4,2));
Console.ReadKey();
}
}
}
OUTPUT
Factorial of 5 is120
Reverse of 0 is 126566767342
Addition of 3, 4,2 without '+' operator = 9
Name:-
Roll No.:-
Practical No. 31
Aim:-
Create an interface area that are implemented by two classes square and circle that
compute their areas using the method compute in the interface area. The main class shows the
implementation of areas of any square and circle if side of square is 15 and radius of circle is
15.27. (Area of square= (side*side) and area of circle=3.14*radius*radius).
Program:-
using System;
Name:-
Roll No.:-
namespace Using_Interface
{
interface Area
{
void compute(double value);
}
interface volume
{
void calculate(double side);
}
public class square : Area
{
Name:-
Roll No.:-
{
circle c=new circle();
square s = new square();
cube cu = new cube();
Console.WriteLine("Circle with radius 15.27");
c.compute(15.27);
Console.WriteLine("Square with side 12.5");
s.compute(12.5);
Console.WriteLine("Volume of Cube with 5");
cu.calculate(5);
Console.ReadLine();
}
}
}
OUTPUT
Circle with radius 15.27
The area of circle is : 732.162906
Square with side 12.5
The area of square is : 156.25
Volume of Cube with 5
The volume of cube is : 125
Practical No. 32
Aim:-
The class computation implements two interfaces, addition and multiplication. It
declares two data members and defines the code for methods add( ) and mul( ).write a program
to find the addition and multiplication of 1 and 1239.
Program:-
using System;
namespace Using_Interface
{
interface Addition
Name:-
Roll No.:-
{
int add();
}
interface multiplication
{
int mul();
}
class computation : Addition, multiplication
{
int x, y;
Output:
Addition= 1240
Multiplication= 1239
Name:-
Roll No.:-
Practical No. 33
Aim:-
Create a delegate mydelegate of int type (both argument and return type). Create a class
delegatetest having three static methods:
a. add() that add two interger value.
b. mul() that multiply two interger value.
c. sub() that substract two interger value.
Program:-
using System;
delegate int mydelegate(int n,int m);
namespace DelegateAppl
Name:-
Roll No.:-
{
class DelegateTest
{
static int num;
public static int Add(int p,int q)
{
num = p + q;
return num;
}
public static int Mul(int p, int q)
{
num = p * q;
return num;
}
public static int sub(int p,int q)
{
num =p - q;
return num;
}
public static int getNum()
{
return num;
}
static void Main(string[] args)
{
mydelegate m1 = new mydelegate(Add);
mydelegate m2 = new mydelegate(Mul);
mydelegate m3 = new mydelegate(sub);
m1(25,15);
Console.WriteLine("Value of Add: {0}", getNum());
m2(5,5);
Console.WriteLine("Value of Mul: {0}", getNum());
m3(15,2);
Console.WriteLine("Value of Sub: {0}", getNum());
Console.ReadKey();
}
}
}
OUTPUT
Value of Add: 40
Value of Mul: 25
Value of Sub: 13
Name:-
Roll No.:-
Practical No. 34
Aim:-
Write the program where main method implements the delegate. Create a delegate
Mdelegate of int type (both argument and return type). Create a class delegate example having
three static methods:
a. reverse() that will reverse an interger value.
b. adddigit() that will add enter digit in an interger value.
c. Factorial () that will generate factorial of an interger value.
Program:-
using System;
delegate int Mdelegate(int n);
namespace ConsoleApplication5
Name:-
Roll No.:-
{
class Program
{
public static int Reverse(int p)
{
int digit,revnum=0;
while(p>0)
{
digit=p%10;
revnum =revnum *10 +digit ;
p=p /10;
}
return revnum ;
}
public static int fact(int q)
{
int f=1;
while(q>1)
{
f=f*q;
q--;
}
return f;
}
public static int adddigit(int r)
{
int d;
Console.WriteLine("Enter a digit : ");
d=int.Parse(Console.ReadLine());
return (r+d);
}
static void Main(string[] args)
{
Mdelegate m=new Mdelegate (Reverse);
Console.WriteLine("value of num : {0}" ,m(1234));
Mdelegate m1=new Mdelegate (fact);
Console.WriteLine("value of num : {0}" ,m1(5));
Mdelegate m2=new Mdelegate (adddigit);
Console.WriteLine("value of num : {0}" ,m2(25));
Console.ReadKey();
}
}
}
OUTPUT
value of num : 4321
Name:-
Roll No.:-
value of num : 120
Enter a digit :
12
value of num : 37
Practical No.35
Working With CSS
Design a Web Form and apply the different styles and themes using CSS
Name:-
Roll No.:-
background-color: green ;
width: 844px;
height: 86px;
clear: both;
}
Step 6: Now Open Default.aspx and switch to Design View. From the Solution
Explorer, drag the file Styles.css from the Styles folder onto the page.
<head runat=”server”>
<title></title>
<link href=”Styles/Styles.css” rel=”stylesheet” type=”text/css” />
</head>
Step 7: Finally, save the changes to all open documents (press Ctrl+Shift+S) and then
request Default.aspx in your browser.
OUTPUT
Practical No.36
To Redirect The Page To Another Site
Redirect.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Redirect.aspx.cs"
Inherits="Redirect" %>
Name:-
Roll No.:-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Redirect.aspx.cs
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
}
protected void btnclick_Click(object sender, EventArgs e)
{
Response.Redirect("http://www.ckthakurcollege.net");
}
protected void btnclickpage_Click(object sender, EventArgs e)
{
Name:-
Roll No.:-
Server.Transfer("welcome.aspx");
}
}
Welcome.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="welcome.aspx.cs"
Inherits="welcome" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Welcome to CKT College</h1>
</div>
</form>
</body>
</html>
OUTPUT
Practical No.37
Working with Different Contols
Date :
A
Design a webpage using CheckBox and a panel control. Place two textboxes
i.e textbox1 and textbox2 and a Button control inside the panel so that on
click ofthis button the factorial of the value provided in the textbox1 will
get display in textbox Set the visible property of panel control to false.
Name:-
Roll No.:-
Write the C# code tomake the panel visible on the checked changed event
of CheckBox so that the factorial operation can be performed
Step 3: Drag Panel Control from the ToolBox.Drag two textboxes i.e textbox1 and textbox2
and a Button control inside the panel &Visible Property False.
Step 4: Now double click on CheckBox and write down the following code in Event Handler
File.
Step 5: Double click on Button and write down the following code in Event Handler File to
calculate the Factorial.
Name:-
Roll No.:-
OUTPUT
B
Design a webpage with CheckBox and PlaceHolder control and perform
the following operation:- Write code behind to create an image control with
a image having equal height and width and a label with the text property
Name:-
Roll No.:-
set with the name of the image displayed in the image control having font
color red. Make sure the above set of performance should be perform only
when the user grant the permission by checking the checkbox with text
“display image”.
Step 2: Drag CheckBox from the ToolBox. Change ID Property to chkdisplay, Text to
Display Image and AutoPostBack Property True.
Step 4: Now double click on CheckBox and write down the following code in Event Handler
File.
Step 6: Now double click on Web Page you are in the page load event of web page as per the
requirement and write down the following code in Event Handler File.
Name:-
Roll No.:-
Step 7:Finally, save the changes to all open documents (press Ctrl+Shift+S) and then
request Default.aspx in your browser.
OUTPUT:
C
Write an application that receives the following information from a set of
students: Student Id, Student Name, Course Name, and Date of Birth. The
application should also display the information of all the students in
textbox or label once user click on submit. Implement this using web server
control.
Step 2: Drag 4 Labels from ToolBox and change the Property in following ways
Step 3: Drag 4 TextBox from ToolBox and change the Property in following ways
Name:-
Roll No.:-
Control Names ID
TextBox1 Txtid
TextBox2 Txtname
TextBox3 Txtcourse
TextBox4 Txtdob
Step 4: Drag Label and Button. and change the Property in following ways
Step 5: Now double click on Button and write down the following code in Event Handler
File.
OUTPUT
Name:-
Roll No.:-
Practical No. 38
Working with Validation Controls
A
Create web page with validation control.
Name field should contain atleast one character, CustNo(textbox) should
follow following pattern { 'CS'- followed by 3 digit } e.g CS-001,if password
entered in two password field does not match then error message should
appear, Validate email-id entered by user.
Validation.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Validation.aspx.cs" Inherits="Validation" %>
Name:-
Roll No.:-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 160px;
}
.style3
{
width: 206px;
}
.style4
{
width: 462px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td class="style2">
Name</td>
<td class="style3">
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
<td class="style4">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
Name:-
Roll No.:-
ControlToValidate="txtname"
ErrorMessage="Name should contain atleast one
character"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style2">
Customer No</td>
<td class="style3">
<asp:TextBox ID="txtcustno" runat="server"></asp:TextBox>
</td>
<td class="style4">
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server"
ControlToValidate="txtcustno"
ErrorMessage="CustNo should follow pattern { 'CS'- followed by 3 digit } e.g
CS-001"
ValidationExpression="CS-
\d{3}"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style2">
E Mail</td>
<td class="style3">
<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
</td>
<td class="style4">
<asp:RegularExpressionValidator ID="RegularExpressionValidator2"
runat="server"
ControlToValidate="txtemail" ErrorMessage="Enter Proper E Mail"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-
.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style2">
Password</td>
<td class="style3">
Name:-
Roll No.:-
<asp:TextBox ID="txtpass" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td class="style4">
</td>
</tr>
<tr>
<td class="style2">
ReEnter Password</td>
<td class="style3">
<asp:TextBox ID="txtreenterpass" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td class="style4">
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="txtpass" ControlToValidate="txtreenterpass"
ErrorMessage="Enter Correct Password"></asp:CompareValidator>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td class="style3">
<asp:Button ID="btnsubmit" runat="server" Text="Submit" />
</td>
<td class="style4">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
OUTPUT 1
Name:-
Roll No.:-
OUTPUT 2
B
Design a web page to create college ID card with fields namely first name,
middle name, last name, class, semester, roll number, address and
telephone number, email_Id with proper validation for each field using
validation controls. Display the records on a click of a button in a Label.
Make a provision to upload the photograph of the candidate.
Validation.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Validation2aspx.aspx.cs" Inherits="Validation2aspx" %>
Name:-
Roll No.:-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
font-weight: bold;
width: 142px;
text-align: left;
}
.style3
{
width: 142px;
}
.style4
{
width: 240px;
}
.style5
{
font-weight: bold;
width: 142px;
height: 24px;
}
.style6
{
width: 240px;
height: 24px;
}
.style7
{
height: 24px;
Name:-
Roll No.:-
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td class="style3">
<b>First Name</b></td>
<td class="style4">
<asp:TextBox ID="txtfirst" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtfirst" ErrorMessage="*"
ForeColor="#FF6600"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
<b>Middle Name</b></td>
<td class="style4">
<asp:TextBox ID="txtmiddle" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtmiddle" ErrorMessage="*"
ForeColor="#FF6600"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
<b>Last Name</b></td>
<td class="style4">
<asp:TextBox ID="txtlast" runat="server"></asp:TextBox>
</td>
<td>
Name:-
Roll No.:-
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtlast" ErrorMessage="*"
ForeColor="#FF6600"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
<b>C</b><b style="mso-bidi-font-weight:normal"><span style="font-
size:12.0pt;line-height:115%;font-family:"Times New
Roman","serif";
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-
language:
EN-IN;mso-fareast-language:EN-US;mso-bidi-language:AR-
SA">lass</span></b></td>
<td class="style4">
<asp:TextBox ID="txtclass" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txtclass" ErrorMessage="*"
ForeColor="#FF6600"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style2">
<b style="mso-bidi-font-weight: normal">
<span style="font-size: 12.0pt; line-height: 115%; font-family: "Times
New Roman","serif"; mso-fareast-font-family: Calibri; mso-
fareast-theme-font: minor-latin; mso-ansi-language: EN-IN; mso-fareast-
language: EN-US; mso-bidi-language: AR-SA">
Semester</span></b></td>
<td class="style4">
<asp:TextBox ID="txtsem" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="txtsem" ErrorMessage="*"
ForeColor="#FF6600"></asp:RequiredFieldValidator>
</td>
Name:-
Roll No.:-
</tr>
<tr>
<td class="style2">
<b style="mso-bidi-font-weight: normal">
<span style="font-size: 12.0pt; line-height: 115%; font-family: "Times
New Roman","serif"; mso-fareast-font-family: Calibri; mso-
fareast-theme-font: minor-latin; mso-ansi-language: EN-IN; mso-fareast-
language: EN-US; mso-bidi-language: AR-SA">
Roll Number</span></b></td>
<td class="style4">
<asp:TextBox ID="txtroll" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ControlToValidate="txtroll" ErrorMessage="*"
ForeColor="#FF6600"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style3">
<b>A</b><b style="mso-bidi-font-weight: normal"><span
style="font-size: 12.0pt; line-height: 115%; font-family:
"Times New Roman","serif"; mso-fareast-font-family:
Calibri; mso-fareast-theme-font: minor-latin; mso-ansi-language: EN-IN; mso-
fareast-language: EN-US; mso-bidi-language: AR-
SA">ddress</span></b></td>
<td class="style4">
<asp:TextBox ID="txtadd" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ControlToValidate="txtadd" ErrorMessage="*"
ForeColor="#FF6600"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style2">
<b style="mso-bidi-font-weight: normal">
Name:-
Roll No.:-
<span style="font-size: 12.0pt; line-height: 115%; font-family: "Times
New Roman","serif"; mso-fareast-font-family: Calibri; mso-
fareast-theme-font: minor-latin; mso-ansi-language: EN-IN; mso-fareast-
language: EN-US; mso-bidi-language: AR-SA">
Telephone number</span></b></td>
<td class="style4">
<asp:TextBox ID="txttel" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"
ControlToValidate="txttel" ErrorMessage="*"
ForeColor="#FF6600"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style5">
<b style="mso-bidi-font-weight: normal">
<span style="font-size: 12.0pt; line-height: 115%; font-family: "Times
New Roman","serif"; mso-fareast-font-family: Calibri; mso-
fareast-theme-font: minor-latin; mso-ansi-language: EN-IN; mso-fareast-
language: EN-US; mso-bidi-language: AR-SA">
Email_Id</span></b></td>
<td class="style6">
<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
</td>
<td class="style7">
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server"
ControlToValidate="txtemail" ErrorMessage="Enter proper E-Mail
"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style2">
Photo</td>
<td class="style4">
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<br />
Name:-
Roll No.:-
<asp:Button ID="btnupload" runat="server" Text="Upload" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td class="style4">
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td class="style4">
<asp:Button ID="btnsubmit" runat="server" Text="Submit" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td class="style4">
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
OUTPUT
Name:-
Roll No.:-
Practical No. 39
Working with State Management
ViewState.aspx
Name:-
Roll No.:-
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="ViewState.aspx.cs" Inherits="ViewState" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtcount" runat="server"></asp:TextBox>
<br />
<br />
<br />
<asp:Button ID="btnclick" runat="server" onclick="btnclick_Click"
Text="Click" />
</div>
</form>
</body>
</html>
ViewState.aspx.cs
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
OUTPUT
Practical No. 40
Design a webpage with a digital clock showing time and an image control
with 4 images randomly get displayed on a page loading event.
Steps:
Name:-
Roll No.:-
1. Add a web form/page in your application.
2. Add ScriptManager on to the web form
3. Add UpdatePanel control on to the web form.
4. Add the following tag inside the updatepanel1 conrol.
<ContentTemplate>
</ContentTemplate>
5. Add Timer control inside the updatePanel control.
6. Change the Tick property of Timer control to 1000(1second). For every 1
sec this control will rise a event called tick event.
7. Add image control inside the updatePanel control.
8. Change the Height and Width properties of image control to
Height=”200px” Width=”200px”.
9. Add new folder and name it as “Images”.
10. Copy 5 jpg images and paste it into the “Images” folder. Rename the 5
images to (1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg)
11.Do double click on the top of timer control . It will automatically create
thetick_event handler().
12. Write the following function. This function is used to generate random
images.
private void RandomImage()
{
Random random = new Random();
int i = random.Next(1, 4);
Image1.ImageUrl = "~/Images/" + i.ToString() + ".jpg";
}
13. Call the RandomImage() function inside the Timer1_tick()
protected void Timer1_Tick(object sender, EventArgs e)
{
RandomImage();
}
14.Call the RandomImage() function inside the Page_Load()
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{RandomImage();}
Name:-
Roll No.:-
}
15.Now run the program and see the output
Practical No. 41
Name:-
Roll No.:-
Example
using System;
using System.Collections.Generic; using System.Linq;
using System.Web; using System.Web.UI;
using System.Web.UI.WebControls; using System.Data;
using System.Data.SqlClient;
}
protected void btnsave_Click1(object sender, EventArgs e)
{
// Creating instance of SqlConnection
SqlConnection conn = new SqlConnection("Data Source=CKT;Initial
Catalog=Sample;Integrated Security=True");
Name:-
Roll No.:-
cmd.Connection = conn;
cmd.CommandText = "insert into stud values (" + TextBox1.Text +
",'" +TextBox2.Text + "','" + TextBox3.Text + "')"; // set
//the sql command ( Statement )
cmd.ExecuteNonQuery();
ScriptManager.RegisterStartupScript(this, this.GetType(),
"Messagebox", "alert('Record Saved Successfully');", true); // showing
messagebox for confirmation message for user
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
conn.Close();// Close the connection
}
}
Name:-
Roll No.:-