1. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
IV YEAR B.E CSE
15PBCE72- OPEN SOURCE & .NET LABORATORY
ACADEMIC YEAR: 2019 - 2020
NAME:
REGISTER NO:
2. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
BONAFIDE CERTIFICATE
Reg.No.
This is to certify that this is a Bonafide Record of Practical Work done by
Mr./Ms…………………….………………..….of B.Tech Information Technology in the Open Source
& .NET Laboratory during the academic year 2019-2020.
HEAD OF THE DEPARTMENT
Submitted for the Practical Examination held on …………………
STAFF-IN-CHARGE
INTERNAL EXAMINER EXTERNAL EXAMINER
3. INDEX
Ex. No DATE NAME OF THE
EXPERIMENTS
Page
No.
MARKS SIGNATURE
LINUX
1.a Linux Installation (using
SERVER mode)
1.b Linux Installation (using
USER mode)
1.c Linux Installation (using
GRAPHICAL mode)
SHELL PROGRAMMING
2 Basic Unix Commands
3 Shell Programming
Constructs
4.a Reversing A Number
4.b Sum Of Odd And Even
Numbers
4.c Armstrong Number
4.d Counting Vowels In A Line
4.e Factorial Of A Number
PYTHON PROGRAMMING
5. BASIC PYTHON COMMANDS
5.a Prime Number
5.b Fibonacci Series
5.c PYTHON LIST
4. 5.d PYTHON TUPLE
5.e PYTHON DICTIONARY
5.f String Operations
.NET CONSOLE PROGRAMMING
6.a Largest And Average Of
Elements Using Array
6.b ATM Transactions
6.c ADO.NET
ASP.NET PROGRAMMING
7.a ASP.NET - Login Module
7.b ASP.NET-Grid view
7.c Library Management System
PERL PROGRAMMING
8.a Leap Year
8.b Swap Numbers
8.c Sum Of Series
PHP PROGRAMMING
9.a Website using PHP
9.b Creating and Validating Login
Page using PHP
5. Aim:
To install Linux operating system in the computer
PROCEDURE:
STEP 1: Insert the installation CD and enter the type of mode whether GUI mode or
command mode.
STEP 2: Here select GUI (Graphical User Interface) and press F10 to save.
STEP 3: There will be two options-Ok and Skip.
STEP 4: Press Ok and then Next.
STEP 5: Press the next then language potions will appear.
STEP 6: Select the language (US English).
STEP 7: Press next and there appears the option to type installation number.
STEP 8: Select the “Skip” and press Ok.
STEP 9: Then select “Install”.
STEP 10: Then it asks for next connection.
STEP 11: In the following window, there will be four options “DELETE ALL” (1st option).
STEP 12: Then select the option “Yes”.
STEP 13: Then it appears Time zone map. In the time zone, select the country “INDIA” from
the world map.
STEP 14: Select the “Next” option.
STEP 15: Select the “Root Password”.
STEP 16: Confirm the password in the next step.
STEP 17: Then in the step select the Software Device and Web Server.
EX.NO: 1.A
LINUX INSTALLATION (using SERVER mode)
DATE:
6. STEP 18: Select the “Customize Now” option.
STEP 19: It takes several minutes to install.
STEP 20: Then select the “Reboot”.
STEP 21: It shows license agreement then choose Firewall Protection-Enable or Disable as
we require.
STEP 22: The SELINUX (Security Linux) will appear.
STEP 23: Choose Embracing and then select “Forward”.
STEP 24: Then set “date and time”.
STEP 25: Then select software update if required.
STEP 26: Create user account. Here we create it as “Student Login”. Username, Full name
and Password are entered.
STEP 27: Then it asks for sound card within includes volume, speaker and so on.
STEP 28: Then installation takes place.
Result:
Thus Linux operating system using SERVER Mode is installed successfully.
7. Aim:
To install Linux using user mode.
PROCEDURE:
STEP 1: Select custom layout and click “OK”.
STEP 2: Then under partitioning delete the RAID levels with appropriate partitions.
STEP 3: The partition under mount point select “Software RAID” and fill “100 MB” and
choose “Force to be a primary partition”.
STEP 4: Then select “Software RAID” and fill “500MB” and “Add partition”.
STEP 5: Then select “Software/dev/sda” under partitioning and click “OK”.
STEP 6: It asks for “Root partition” and click RAID levels and type “Boot at “ext3” and click
“OK”.
STEP 7: Click the “Swap and select Raid Level 1” and click OK.
STEP 8: Then select the “Boot Leader”. Click GRUB Boot Leader.
STEP 9: Then give GRUB Boot – default boot label. Here we have “Red Hat Linux”.
STEP 10: Then select configuration and click “Activate on Boot”.
STEP 11: Then select “Network Configuration” and click Enable IPK4 support
STEP 12: Then click Manual Address Configuration and give IP address 10.00.1 and
255.255.248.
STEP 13: Then under “Host name Configuration” select “Automatically via DHCP” or
“manual”.
STEP 14: We can see the “Welcome Screen” and select time zone. Here we select Root
Password Configuration “America San-Paulo” and type the password. Installation takes few
minutes.
STEP 15: Customize software selection and select appropriate “Package Group Selection”.
EX.NO: 1.B
LINUX INSTALLATION (using USER mode)
DATE:
8. STEP 16: It should show the Desktop appropriate package tools and click Administration
Tools.
STEP 17: The packages we select are:-
Mail Server
Network Server
Development Libraries and so on
GNOME Desktop environment
STEP 18: “Dependency Check” takes place for several minutes.
10. Aim:
To install Linux using Graphical mode.
PROCEDURE:
STEP 1: We have several options in main menu as follows.
STEP 2: There are some list of games like FreeCell, Chess and so on.
STEP 3: There are some list of graphics in the next option.
STEP 4: We can select Word Sheet, Excel from Office.
STEP 5: Then under the programming we have several options.
STEP 6: Next we have “System Setting”.
STEP 7: Next they are “System Tools”.
STEP 8: Then we can open “New Terminal”
EX.NO: 1.C
LINUX INSTALLATION (using GRAPHICAL mode)
DATE:
12. AIM:
To study and execute basic linux commands.
PROCEDURE:
1. Create a directory Unix in your home directory
Solution : mkdir Unix
2. Create two sub directories dir1 and dir2 under Unix directory.
Solution : mkdir Unix/dir1 Unix/dir2
3. Go to dir1.
Solution : cd Unix/dir1
4. Create a file myFile in the dir1 and insert few lines.
Solution : cat > myFile
Hello!
Welcome to the course on Unix.
Happy Learning!
(press ctrl + z to exit)
5. Make a duplicate copy of the file myFile in dir2
Solution : cp myFile ../dir2/
man - The reference Manual
man displays the documentation for a command
usage: man <command name>
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs
6. Append few lines of statements in file myFile in dir2.
Solution : cat >> ../..dir2/myFile
Bye!
(press ctrl + z to exit)
EX.NO: 2
BASIC UNIX COMMANDS
DATE:
13. 7. Change the name of the file myFile in dir2 to newFile.
Solution : mv ../dir2/myFile ../dir2/newFile
Filters and Pipes:
8. Display how many number of lines, words and characters are there in myFile.
Solution : wc myFile
9. Count how many users are currently logged into the system
Solution : who | wc -l
10. Display the lines having the word "this" in myFile
Solution : grep -w “this” myFile
14.gzip and gunzip
gzip command is used to compress the file, and gunzip is used to de-compress it.
usage: gzip <file name>
It provides the extension .gz and removes the original file
$ wc sample_copy.txt
65 2776 17333 sample_copy.txt
$ gzip sample_copy.txt
$ wc sample_copy.txt.gz
26 155 7095 sample_copy.txt.gz
The compression ratio depends on the type, size and nature of the file
usage: gunzip <file name with.gz>
$ gunzip sample_copy.txt.gz
$ /*do ls and you can see the original file*/
If you want to compress the directory contents recursively,
use -r option with gzip command and unzip it use the
same option with gunzip command
14. 11. Count number of lines having the word "this" in myFile
Solution : grep -cw “this” myFile
12. Replace the word this by that for all occurrences in myFile.
Solution : sed 's/this/that/g' myFile
13. Replace the word this by that only for the first occurrence of it in a line.
Solution : sed 's/this/that/1' myFile
14. Print the first 3 lines from the file myFile
Solution : head -3 myFile
15. Print the last 3 lines from the file myFile
Solution : tail -3 myFile
16. Append a new line in the beginning of the file myFile
Solution : sed '1s/^/Hi Everyonen/' myFile
awk Scripting :
17. Create a file with name student.txt with the following contents in it
RollNo|Name|Marks1|Marks2|Marks3
123|Raghu|80|90|60
342|Maya|45|78|82
561|Gita|56|71|89
480|Mohan|71|90|89
a. Write an awk command to print the name and roll number of the students.
Solution : awk -F '|' '{print $1,$2}' student.txt
b . Write the awk command to calculate the total marks of each student and display the
total marks along with the name of the student.
The Output should be displayed in following format :
Student Name – Total Marks
Solution : awk -F '|' 'BEGIN{OFS="-"}{total=0;total=$3+$4+$5}{if (NR!=1) {print$2,total}}'
student.txt
15. AIM:
To study the shell programming constructs of UNIX operating system
INTRODUCTION:
A set of commands can be grouped together under a single file name &
executed.This is done using shell scripts. Shell provides us with the features to enable it to
be used as programming language. Some of these features are programming constructs,
logical and conditionals operators, command substitution, escape mechanisms, positional
parameters etc
#SYMBOL:
This symbol is used scripts to give comment lines
$SYMBOL:
This symbol is used in shell scripts to retrieve the value that is scanned
READ COMMAND:
This command waits for the user to input the value for the variable
SYNTAX:
Read variable name
ECHO COMMAND:
This command is used to display whatever message we want to display on the
screen
SYNTAX:
Echo message
ARITHMETIC OPERATIONS&EXPRESSIONS:
ARITHMETIC OPERTAORS:
+ Addition
-a subtraction
* multiplication
% division
Digit strings are taken as series of characters by the shell unless specified to take
their numerical value. The “expr” command helps us in getting the numerical value of the
digit strings
LOGICAL OPERATORS:
! – negates the following expression
-a – used for indicating AND
-O – used for indicating OR
COMPARSION OPERATORS:
N1-eq n2 will check if the two integers are equal
N1-ne n2 will check if the two integers are not equal
N1-gt n2 will check if the integer n1 is greater than n2
N1-lt n2 will check if the integer n1 is greater than or equal to n2
N1-ie n2 will check if the integer n1 is less than or equal to n2
EX.NO: 3
SHEEL PROGRAMMING CONSTRUCTS
DATE:
16. EXPRESSIONS
To perform addition of two numbers:
$ expr 3 + 5
$ y=10
$ y=`expr $y + 1`
sum=`expr $sum + $no
PROGRAMMING LANGUAGE CONSTRUCTS:
IF CONSTRUCT:
Syntax1
If(condition)
Then
Commands
Else
Commands
If
Syntax2
If(condition)
Then
Commands
If(condition)
Commands
Else
Commands
If
CASE CONSTRUCT:
Syntax
Case value in
Choice 1) commands;;
Choice 2) commands;;
……………….
……………….
Choice n commands;;
*) default commands;;
Esac
FOR CONSTRUCT:
Syntax
For<variable>in value 1 value 2 value 3……
Do
Commands
Done
17. WHILE CONSTRUCT:
Syntax
While control command
Do
Commands
Done
UNTIL COMANDS:
Syntax
Until control command
Do
Commands
Done
EXECUTION COMMAND:
A shell script can be executed in two ways
1) Type in”sh filename”at the $ prompt
2) Grant execute permission to the file and then type in the file name at the $prompt
DEBUG COMMAND:
This command is used for debugging the program (line by line execution takes place)
SYNTAX:
Sh-Xfilename
VI COMMANDS
Sno Command Description
1 vi filename Creates a new file if it already does not exist, otherwise
opens an existing file.
2 :q The command to quit out of vi
3 :q! to quit out of vi without saving
4 :w save the contents of the editoR
5 :wq Quit and save
6 i Inserts text before the current cursor location
7 a Inserts text after the current cursor location
8 x Deletes the character under the cursor location
9 k Moves the cursor up one line
10 j Moves the cursor down one line
11 h Moves the cursor to the left one character position
12 l Moves the cursor to the right one character position
18. AIM:
To write a shell program to check the given number and its reverse are same.
ALGORITHM:
step 1: Start
step 2: Intilize reverse=0.
step 3: Read digit
step 4: Check whether digit>0 then go to step 5
else go to step 9
step 5: Get the last digit of the given number and store it in r
step 6: reverse=digit%10
step 7: s =reverse+ s/10
Step 8: digit=digit/10
step 9: Go to step 4
step 10: Print reverse
step 11: Stop
EX.NO: 4.A
REVERSING A NUMBER
DATE:
19. PROGRAM
echo "Enter a number:"
read n
t=$n
s=0
while [ $n -gt 0 ]
do
r=`expr $n % 10`
s=`expr $r + $s * 10`
n=`expr $n / 10`
done
if [ $s = $t ]
then
echo "The given number and its reverse are same"
else
echo "The given number and its reverse are not same"
fi
20. OUTPUT
@boss$ sh reverse.sh
Enter a number:
123
The given number and its reverse are not same
-bash-3.2$ sh reverse.sh
Enter a number:
121
The given number and its reverse are same
22. AIM:
To write a shell program to to find the sum of odd and even numbers from a set of
numbers.
ALGORITHM:
Step1: Start
Step2: Read num
Step3: Check whether the num is divisible by 2 or not.
Step4: If yes, add the sum of even numbers
Step5: If no, add the sum of odd numbers
Step6: Display the sum of odd and even numbers
Step7: stop
EX.NO: 4.B
SUM OF ODD AND EVEN NUMBERS
DATE:
23. PROGRAM
echo "Enter the number of elements:"
read n
os=0
es=0
for((i = 1 ; i <= n ; i++))
do
echo "Enter the number:"
read no
if [ `expr $no % 2` = 0 ]
then
es=`expr $es + $no`
else
os=`expr $os + $no`
fi
done
echo "The sum of odd numbers is : $os"
echo "The sum of even numbers is : $es"
24. OUTPUT
boss$ sh oddeven.sh
Enter the number of elements:
5
Enter the number:
11
Enter the number:
22
Enter the number:
33
Enter the number:
44
Enter the number:
55
The sum of odd numbers is : 99
The sum of even numbers is : 66
26. AIM:
To write a shell program to to check the given integer is Armstrong number or not.
ALGORITHM:
Step 1: Start
Step 2: read number
Step 3: set sum=0 and duplicate=number
Step 4 : reminder=number%10
step 5: sum=sum+(reminder*reminder*reminder)
step 6: number=number/10
step 7: repeat steps 4 to 6 until number > 0
step 8: if sum = duplicate
display number is armstrong
else
display number is not armstrong
Step 9:stop
EX.NO: 4.C
ARMSTRONG NUMBER
DATE:
27. PROGRAM
echo "Enter a number:"
read n
t=$n
s=0
while [ $n -gt 0 ]
do
r=`expr $n % 10`
s=`expr $s + $r * $r * $r`
n=`expr $n / 10`
done
if [ $s = $t ]
then
echo "$t is an armstrong number"
else
echo "$t is not an armstrong number"
fi
28. OUTPUT
boss$ sh armstrong.sh
Enter a number:
123
123 is not an armstrong number
-bash-3.2$ sh armstrong.sh
Enter a number:
153
153 is an armstrong number
30. AIM:
To Write a Shell program to count the number of vowels in a line of text
ALGORITHM
STEP 1: START
STEP 2: SET vCount =0, cCount =0
STEP 3: Get the Input string
STEP 4: SET i =0.
STEP 5: REPEAT STEP 6 to STEP 8 UNTIL i is less than length of string
STEP 6: IF any character of str matches with any vowel then
vCount = vCount + 1.
STEP 7: IF any character excepting vowels lies BETWEEN a and z then
cCount = cCount =+1.
STEP 8: i = i + 1
STEP 9: PRINT vCount.
STEP 10: PRINT cCount.
STEP 11: END
EX.NO: 4.D
COUNTING VOWELS IN A LINE
DATE:
31. PROGRAM
echo "Enter the text:"
read s
l=`expr length $s`
c=0
vc=0
while [ $c -le $l ]
do
r=`expr substr $s $c 1`
if [ $r = 'a' -o $r = 'e' -o $r = 'i' -o $r = 'o' -o $r = 'u' ]
then
vc=`expr $vc + 1`
fi
c=`expr $c + 1`
done
echo "The number of vowels in the text $s is : $vc"
34. AIM:
To Write a Shell program to find the factorial of a number using for loop.
ALGORITHM:
Step 1: Start
Step 2: Declare variables n,factorial and i.
Step 3: Initialize variables
factorial←1
i←1
Step 4: Read value of n
Step 5: Repeat the steps until i=n
factorial←factorial*i
i←i+1
Step 6: Display factorial
Step 7: Stop
EX.NO: 4.E
FACTORIAL OF A NUMBER
DATE:
38. AIM:
To study and execute basic python commands.
PROCEDURE:
Starting Python
Start Python in interactive mode by invoking python in the command line.
$ python
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Arithmetic expressions
>>> celsius = 100
>>> farenheit = (9 * celsius / 5) + 32
>>> print farenheit
212
>>>
Indentation
Python programs get structured through indentation i.e code blocks are defined by
indentation,Python provides no braces to indicate block of code for class ,functions and
flow control.
The number of spaces in the indentation is not fixed value but all statements within the
block must be indented the same amount.
Control Flow
if condition:
statement1
statement2...
elif condition:
statement1
statement2...
else:
statement1
statement2..
initialization;
while(condition)
{
//Code block to execute something
}
for iterator_var in sequence:
statements(s)
EX.NO: 5
BASIC PYTHON COMMANDS
DATE:
39. Lists and slicing
Lists: There are the most versatile sequence type. The elements of a list can be any object
and lists are mutable.
The wind speed data (in km/hr) from a weather station, for a single day, obtained every 2
hours, starting from 12:00am: 3, 5, 3, 2, 0, 0, 5, 5, 11, 5, 10, 2.
1. Represent the data using a list.
2. Extract the wind speed at noon.
3. Extract all the wind speeds in the afternoon.
4. Extract the last measurement of the day.
>>> wind_speed = [3, 5, 3, 2, 0, 0, 5, 5, 11, 5, 10, 2]
>>> noon = wind_speed[6]
>>> print noon
5
>>> afternoon = wind_speed[7:12]
>>> print afternoon
[5, 11, 5, 10, 2]
>>> last = wind_speed[-1]
>>> print last
2
>>>
>>>myList = [1, 'hello', 2.35, True]
>>>print(myList)
List iteration
>>> wind_speed = [3, 5, 3, 2, 0, 0, 5, 5, 11, 5, 10, 0]
>>> sum = 0
>>> for item in wind_speed:
sum = sum + item
>>> avg = sum / len(wind_speed)
>>> print avg
4
List Methods
mylist=[10,20,30,40,50]
m=len(mylist)
print(mylist)
mylist.insert(0,5)
print(mylist)
mylist.append(60)
print(mylist)
40. Tuples and Slicing
A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The
differences between tuples and lists are, the tuples cannot be changed unlike lists and
tuples use parentheses, whereas lists use square brackets.These are like lists, But Tuples
are immutable.
tuplex =(2,4,3,5,4,6,7,8,6,1)
slice= tuplex[3:5]
print(_slice)
slice = tuplex[:6]
print(slice)
slice = tuplex[5:]
print(_slice)
slice = tuplex[:]
print(_slice)
slice = tuplex[-8:-4]
print(_slice)
tuplex =tuple("HELLO WORLD")
print(tuplex)
slice = tuplex[2:9:2]
print(_slice)
_slice = tuplex[::4]
print(_slice)
slice = tuplex[9:2:-4]
print(_slice)
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5 );
tup3 = "a", "b", "c", "d";
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5, 6, 7 );
print tup1[0];
print tup2[1:5]
tup1 = (12, 34.56);
tup2 = ('abc', 'xyz');
tup3 = tup1 + tup2;
print tup3
tup = ('physics', 'chemistry', 1997, 2000);
print tup;
del tup;
print "After deleting tup : ";
print tup;
41. Dictionary and Slicing
Dictionary in Python is an unordered collection of data values, used to store data values
like a map, which unlike other Data Types that hold only single value as an element, Dictionary
holds key:value pair. Key value is provided in the dictionary to make it more optimized. Each key-
value pair in a Dictionary is separated by a colon :, whereas each key is separated by a ‘comma’.
A Dictionary in Python works similar to the Dictionary in a real world. Keys of a Dictionary must
be unique and of immutable data type such as Strings, Integers and tuples, but the key-values can be
repeated and be of any type.
phonenumbers = {'Jack':'555-555', 'Jill':'555-556'}
phonebook = {}
phonebook["Jack"] = "555-555"
phonebook["Jill"] = "555-556"
print phonebook
dict={‘Name’:’SteveJobs’,’Age’:70,’’class’:’First’};
print(dict[‘Name’])
print(dict[‘Age’])
Strings and slicing
These are a special type of sequence that can store only characters and having
special notations.
Perform the following operations, on the word "newsworthy":
1. Extract the second letter.
2. Extract the first four letters.
3. Extract the last six letters.
>>> word = "newsworthy"
>>> print len(word)
10
>>> print word[1]
e
>>> print word[0:4]
news
>>> print word[4:10]
worthy
>>>
42. String iteration and concatenation
Reverse the word "linux" using string iteration and concatenation
>>> word = "linux"
>>> reversed = ""
>>> for ch in word:
... reversed = ch + reversed
...
>>> print reversed
xunil
>>>
String multiplication
Print a 5 step right-angled triangle using string multiplication.
>>> max = 5
>>> for i in range(0, max):
print "*" * (i+1)
...
*
**
***
****
*****
>>>
43. AIM:
To write a program to check whether a number entered by user is prime or not.
ALGORITHM:
Step 1: Start
Step 2: Declare variables n,i,flag.
Step 3: Initialize variables
flag←1
i←2
Step 4: Read n from user.
Step 5: Repeat the steps until i<(n/2)
5.1 If remainder of n÷i equals 0
flag←0
Go to step 6
5.2 i←i+1
Step 6: If flag=0
Display n is not prime
else
Display n is prime
Step 7: Stop
EX.NO: 5.A
PRIME NUMBER
DATE:
44. PROGRAM
# take input from the user
num = int(input("Enter a number: "))
# prime numbers are greater than 1
if num > 1:
# check for factors
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")
# if input number is less than
# or equal to 1, it is not prime
else:
print(num,"is not a prime number")
45. OUTPUT
user@boss:/$ vi prime.py
user@boss:/$ python prime.py
Enter a number: 7
(7, 'is a prime number')
user@boss:/$ python prime.py
Enter a number: 123
(123, 'is not a prime number')
(3, 'times', 41, 'is', 123)
47. AIM :
To Write a program to find the Fibonacci series till n term
ALGORITHM :
Step 1: Start
Step 2: Declare variables first_term,second_term and temp.
Step 3: Initialize variables first_term←0 second_term←1
Step 4 : Get the input as nterm
Step 5: Display first_term and second_term
Step 6: Repeat the steps until second_term≤nterm
temp←second_term
second_term←second_term+first term
first_term←temp
Display second_term
Step 7: Stop
EX.NO: 5.B
FIBONACCI SERIES
DATE:
48. PROGRAM :
nterms = int(input("How many terms? "))
# first two terms
n1 = 0
n2 = 1
count = 0
# check if the number of terms is valid
while count < nterms:
print(n1)
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1
51. AIM:
To write a program to find how many times an element occurred in list and find the
sum of elements in the list using predefined function and userdefined function
ALGORITHM:
Step 1:Take in the number of elements for the first list and store it in a variable.
Step 2:Take in the elements of the list one by one.
Step 3: Then take in the number to be searched in the list.
Step 4: Use a for loop to traverse through the elements in the list and increment the count
variable.
Step 5:. Display the value of the count variable which contains the number of times a
particular number occurs in a list
Step 6: In the for loop append each number to the list.
Step7 find the sum of all the elements in a list.
Step 8:Print the result.
EX.NO: 5.C
PYTHON LIST
DATE:
52. PROGRAM
#-*-coding:utf-8-*-
a=[]
n=int(input("Enter number of elements:"))
for i in range(1,n+1):
b=int(input("Enter element:"))
a.append(b)
k=0
num=int(input("Enter the number to be counted:"))
for j in a:
if(j==num):
k=k+1
print("Number of times",num,"appears is",k)
forele inrange(0, len(a)):
total =total +a[ele]
# printing total value
print("Sum of all elements in given list: ", total)
53. OUTPUT
user@boss:/$ python list.py
Enter number of elements:5
Enter element:2
Enter element:3
Enter element:4
Enter element:5
Enter element:6
Enter the number to be counted:2
('Number of times', 2, 'appears is', 1)
('Sum of all elements in given list: ', 20)
54. RESULT:
Thus, we implemented a python program to find how many times an element occurred in
list and find the sum of elements.
55. AIM:
To perform different operations on tuple
ALGORITHM
STEP 1: Create tuple from list.
STEP 2. check whether an element exists within a tuple
STEP 3:To remove an item from a tuple
Step 4: To find the index of an item of a tuple
Step 5: To create dictionary from tuple
EX.NO: 5.D
PYTHON TUPLE
DATE:
56. PROGRAM
#convert list to tuple
listx = [5, 10, 7, 4, 15, 3]
print(listx)
#use the tuple() function built-in Python, passing as parameter the list
tuplex = tuple(listx)
print(tuplex)
#tuples are immutable, so you can not remove elements
#using merge of tuples with the + operator you can remove an item and it will create a new
tuple
tuplex = tuplex[:2] + tuplex[3:]
print(tuplex)
tuplex = ("w", 3, "r", "e", "s", "o", "u", "r", "c", "e")
print("r" in tuplex)
print(5 in tuplex)
index = tuplex.index("w")
print(index)
#define the index from which you want to search
index = tuplex.index("u", 5)
print(index)
tuplex = ((2, "w"),(3, "r"))
print(dict((y, x) for x, y in tuplex))
59. AIM:
To create a program to create a telephone database using dictionaries.
ALGORITHM:
STEP 1: Enter Input either Add/Search/Delete/Update/View/Exit
STEP 2: If option A or a is entered add the number in Dictionary
STEP 3: If option D or d delete the number in Dictionary
STEP 3: If option S or s search the number in Dictionary and print .
STEP 4: If option U or u update the number in Dictionary and print .
STEP 5: If option V or v View the number in Dictionary and print .
STEP 6: If option is Q or q quit
STEP 7: If any other option print invalid command
EX.NO: 5.E
PYTHON DICTIONARY
DATE:
60. PROGRAM:
print"*****TELEPHONE DIRECTORY***"
list1=[]
list2=[]
dict1={}
temp=100
n=input("Enter the number of contacts : ")
for i in range(0,n):
name1=raw_input("Enter your name: ")
num=input("Enter your phone number: ")
list1.extend([name1])
list2.extend([num])
dict1=dict(zip(list1,list2))#to convert two list into dictionary
print dict1
print"""
1:Add a contact
2:Search a contact
3:Delete a contact
4:Update a contact
5:View directory
6:Exit"""
choice=input("Enter your choice")
def add(dict1):
name3=raw_input("Enter the new name you want to add: ")
num3=input("Enter the number: ")
dict1[name3]=num3
print dict1
def search(dict1,n,list1,temp):
name2=raw_input("Enter the name whose number is to be found: ")
for i in range(0,n):
if list1[i]==name2:
temp=i
if temp!=100:
print"Number is : ",list2[temp]
def delete(dict1):
name4=raw_input("Enter the name you want to delete: ")
del dict1[name4]
print dict1
61. def update(dict1,n,list1):
name5=raw_input("Enter the name which you want to update: ")
for i in range(0,n):
if list1[i]==name5:
temp=i
if temp!=100:
num5=input("Enter the new number")
dict1[name5]=num5
print dict1
def view(dict1):
print dict1
if(choice==1):
add(dict1)
elif(choice==2):
search(dict1,n,list1,temp)
elif(choice==3):
delete(dict1)
elif(choice==4):
update(dict1,n,list1)
else:
view(dict1)
62. OUTPUT
Enter the number of contacts : 4
Enter your name: stevejobs
Enter your phone number: 99123456
Enter your name: hilary
Enter your phone number: 7689092341
Enter your name: kavin
Enter your phone number: 897654321
Enter your name: athithi
Enter your phone number: 90213456
{'athithi': 90213456, 'kavin': 897654321, 'stevejobs': 99123456, 'hilary': 7689092341L}
1:Add a contact
2:Search a contact
3:Delete a contact
4:Update a contact
5:View directory
6:Exit
64. AIM:
To write a python program to concatenate first two characters from two string and
reverse a string with string operation.
ALGORITHM:
STEP 1:Get two strings from the user .
STEP 2:Find a length of the both string .
STEP 3:Print the length of the both string .
STEP 4:Using “if else” condition, check whether the two strings are equal or not.
STEP 5:Concatenate first two characters of the first string and last two character of the
second string.
STEP 6:Print the concatenated string .
EX.NO: 5.F
PYTHON STRING OPERATIONS
DATE:
65. PROGRAM
string1 = input("Enter first string: ")
string2 = input("Enter second string: ")
print("nLength of the first string =", len(string1))
print("nLength of the second string =", len(string2))
if string1 == string2:
print("nBoth strings are equal to each other.")
else:
print("nStrings are not equal.")
s1=string1[:2]+string2[:2]
print(s1);
s=""
length = len(s1) - 1
while length >= 0:
s = s + s1[length]
length = length - 1
print s
66. OUTPUT
user@boss:/$ python string.py
Enter first string: "hello"
Enter second string: "world"
('nLength of the first string =', 5)
('nLength of the second string =', 5)
Strings are not equal.
hewo
oweh
69. AIM:
To Write a Program to find largest array element and average of array elements via
methods
ALGORITHM:
1. Declare the variables in any programming language
2. initialize sum=0;
3. Enter the no of elements
4. Enter the elements values
5. Found the sum by using loop in array and update sum value in which loop must be
continue till (no of elements-1 ) times
6. avg=sum/no of elements
7. Find the Largest element by checking with temporary element.
8. Print the values of sum and largest element
EX.NO: 6.A
LARGEST AND AVERAGE OF ELMENTS USING ARRAY
DATE:
70. PROGRAM
using System;
class ArrayFunction
{
public static void Main()
{
long Largest;
double Average;
int c;
int num;
int[] array1;
Console.Write("Enter the number of Elements in an Array : ");
c=int.Parse(Console.ReadLine());
array1=new int[c];
for (int i=0 ; i<c ;i++)
{
Console.WriteLine("Enter the element " + i);
num=int.Parse(Console.ReadLine());
array1[i]=num;
}
foreach (int i in array1)
{
Console.Write(" " + i);
}
Console.WriteLine ();
Largest = Large(array1);
Average = Avg(array1);
Console.WriteLine ("n The largest element in the array is " +
Largest);
Console.WriteLine ("The Average of elements in the array is " +
Average);
Console.ReadLine();
}
// Determining the largest array element
static int Large (params int [] arr)
{
int temp=0;
for ( int i = 0; i < arr.Length; i++)
{
if (temp <= arr[i])
{
temp = arr[i];
}
71. }
return(temp);
}
// Determining the average of array elements
static double Avg (params int [] arr)
{
double sum=0;
for ( int i = 0; i < arr.Length; i++)
{
sum = sum + arr[i];
}
sum = sum/arr.Length;
return(sum);
}
}
72. OUTPUT:
Enter the number of Elements in an Array : 5
Enter the element 0 : 5
Enter the element 1 : 7
Enter the element 2 : 3
Enter the element 3 : 1
Enter the element 4 : 8
largest element in the array is 8
The Average of elements in the array is 4.8
74. AIM:
To Write a C# Program Displays the ATM Transaction.
ALGORITHM:
STEP 1 : Create the types of ATM transaction are
1) Balance checking
2) Cash withdrawal
3) Cash deposition
4) qUIT
STEP 2 : if the option entered is Blalance checking .print the Balance amount.
STEP3 :If the option entered is cash withdrawal, check for available balance deduct the
withdrawal amount from balance.
STEP 4:If the option is deposit add the amount to the existing balance
STEP 5:.Quit the application
EX.NO: 6.B
ATM TRANSACTIONS
DATE:
75. PROGRAM
using System;
class program
{
public static void Main()
{
int amount = 1000, deposit, withdraw;
int choice, pin = 0, x = 0;
Console.WriteLine("Enter Your Pin Number ");
pin = int.Parse(Console.ReadLine());
while (true)
{
Console.WriteLine("********Welcome to ATM Service**************n");
Console.WriteLine("1. Check Balancen");
Console.WriteLine("2. Withdraw Cashn");
Console.WriteLine("3. Deposit Cashn");
Console.WriteLine("4. Quitn");
Console.WriteLine("*********************************************nn");
Console.WriteLine("Enter your choice: ");
choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
Console.WriteLine("n YOUR BALANCE IN Rs : {0} ", amount);
break;
case 2:
Console.WriteLine("n ENTER THE AMOUNT TO WITHDRAW: ");
withdraw = int.Parse(Console.ReadLine());
if (withdraw % 100 != 0)
{
Console.WriteLine("n PLEASE ENTER THE AMOUNT IN MULTIPLES OF 100");
}
else if (withdraw > (amount - 500))
{
Console.WriteLine("n INSUFFICENT BALANCE");
}
else
{
amount = amount - withdraw;
Console.WriteLine("nn PLEASE COLLECT CASH");
Console.WriteLine("n YOUR CURRENT BALANCE IS {0}", amount);
}
break;
76. case 3:
Console.WriteLine("n ENTER THE AMOUNT TO DEPOSIT");
deposit = int.Parse(Console.ReadLine());
amount = amount + deposit;
Console.WriteLine("YOUR BALANCE IS {0}", amount);
break;
case 4:
Console.WriteLine("n THANK U USING ATM");
break;
}
}
Console.WriteLine("nn THANKS FOR USING OUT ATM SERVICE");
}
}
77. OUTPUT
Enter Your Pin Number
123
********Welcome to ATM Service**************
1. Check Balance
2. Withdraw Cash
3. Deposit Cash
4. Quit
*********************************************
Enter your choice:
1
YOUR BALANCE IN Rs : 1000
********Welcome to ATM Service**************
1. Check Balance
2. Withdraw Cash
3. Deposit Cash
4. Quit
*********************************************
Enter your choice:2
ENTER THE AMOUNT TO WITHDRAW:
500
********Welcome to ATM Service**************
1. Check Balance
2. Withdraw Cash
3. Deposit Cash
4. Quit
78. *********************************************
Enter your choice:3
ENTER THE AMOUNT TO DEPOSIT
1500
********Welcome to ATM Service**************
1. Check Balance
2. Withdraw Cash
3. Deposit Cash
4. Quit
*********************************************
Enter your choice:1
YOUR BALANCE IN Rs : 1500
80. AIM:
To Write a C# Program to display the number of rows in a table by connecting to
the database.
ALGORITHM:
STEP 1 : Establish the connection to the database
STEP 2 : Create the appropriate SQL Command for Selecting the number of rows.
STEP 3 : Execute the command using ExecuteScalar();
STEP 4: Print the total number of rows in the table
SQL SERVER
In Visual Studio
Go to Server Explore
Rightclick on the server
create the database
Create the following STUDENT table in database
sid int
Name varchar(50)
Address varchar(50)
Mobileint
Email varchar(50)
EX.NO: 6.C
ADO.NET
DATE:
81. PROGRAM :
using System;
using System.Data;
using System.Data.SqlClient;
public class TotalOrders
{
public static void Main()
{
string connectionString = @"Data Source=.SQLEXPRESS; Integrated Security=SSPI; ; User
Instance=True; Initial Catalog=C:UsersUserDocumentssample.mdf;";
string SQL = "SELECT COUNT(*)fROM student";
// Create ADO.NET objects.
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(SQL, con);
// Execute the command.
con.Open();
Console.WriteLine("Connection is " + con.State.ToString());
int result = (int)cmd.ExecuteScalar();
con.Close();
// Display the result of the operation.
Console.WriteLine(result.ToString() + " rows in table student");
}
}
83. RESULT : Thus database connection was established and database operation was
performed.
84. AIM:
To create a Login web page using ASP.Net
PROCEDURE:
File -> New -> Website
View -> Toolbox
From Toolbox Drag and Drop the Login Control in the Design Pane in .aspx
Click the LoginControl and right click the Properties. Check the appropriate properties
In Filename.cs write the C#code
In View -> server explorer -> your database -> Create table with username and password
details.Username should be primarykey.
ALGORITHM
Step 1: Get the user name and password from the user Interface
Step 2: Validate the username and password with the value in the database
Step 3: If both the username and password matches Display “Login Successful” else
“Login Failed”
EX.NO: 7.A
ASP.NET - LOGIN MODULE
DATE:
85. PROGRAM
Login.aspx
<body>
<form id="form1" runat="server">
<asp:Login ID="Login1" runat="server" OnAuthenticate= "ValidateUser"
FailureText="" BorderStyle="Double" Height="100px" style="margin-left: 210px"
Width="534px">
</asp:Login>
<div align="center">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Login.aspx.cs
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void ValidateUser(object sender, EventArgs e)
{
string connectionString = @"Data Source=.SQLEXPRESS; Integrated Security=SSPI;
; User Instance=True; Initial Catalog=C:UsersUserDocumentssample.mdf;";
string SQLQuery = "SELECT Name, Password FROM userdetails where name
=@usr";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(SQLQuery, con);
command.Parameters.AddWithValue("@usr", Login1.UserName.ToString());
SqlDataReader Dr;
con.Open();
Dr = command.ExecuteReader();
89. AIM:
To create a Grid view with Edit and Delete Option.
PROCEDURE:
Create a table with student details with registerno as primarykey
File -> New -> Website
View -> Toolbox
From Toolbox Drag and Drop the Grid View in the Design Pane in .aspx
Click the arrow mark in the top left corner of the Grid view Control
Choose DataSource -> New data Source
Click the database and click OK
choose the database name
Choose the table name studentdetails and select all Columns
Click Advanced-> Click generate Insert,Update and Delete Statements.
Click Finish
In design Pane right click the gridcontrol and choose properties
Set AutoGenerateDeleteButton and AutoGenerateEdit button as False
Run the Program
EX.NO: 7.B
ASP.NET-GRIDVIEW
DATE:
90. PROGRAM
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True" BorderStyle="Double"
DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="Registrationno" HeaderText="Registrationno"
SortExpression="Registrationno" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name"
/>
<asp:BoundField DataField="Course" HeaderText="Course"
SortExpression="Course" />
<asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
<asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:sampleConnectionString %>"
DeleteCommand="DELETE FROM [student] WHERE [Registrationno] =
@original_Registrationno AND (([Name] = @original_Name) OR ([Name] IS NULL AND
@original_Name IS NULL)) AND (([Course] = @original_Course) OR ([Course] IS NULL AND
@original_Course IS NULL)) AND (([Year] = @original_Year) OR ([Year] IS NULL AND
@original_Year IS NULL)) AND (([Age] = @original_Age) OR ([Age] IS NULL AND
@original_Age IS NULL))"
InsertCommand="INSERT INTO [student] ([Registrationno], [Name], [Course],
[Year], [Age]) VALUES (@Registrationno, @Name, @Course, @Year, @Age)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT [Registrationno], [Name], [Course], [Year], [Age] FROM
[student]"
UpdateCommand="UPDATE [student] SET [Name] = @Name, [Course] = @Course,
[Year] = @Year, [Age] = @Age WHERE [Registrationno] = @original_Registrationno AND
91. (([Name] = @original_Name) OR ([Name] IS NULL AND @original_Name IS NULL)) AND
(([Course] = @original_Course) OR ([Course] IS NULL AND @original_Course IS NULL))
AND (([Year] = @original_Year) OR ([Year] IS NULL AND @original_Year IS NULL)) AND
(([Age] = @original_Age) OR ([Age] IS NULL AND @original_Age IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_Registrationno" Type="Int32" />
<asp:Parameter Name="original_Name" Type="String" />
<asp:Parameter Name="original_Course" Type="String" />
<asp:Parameter Name="original_Year" Type="String" />
<asp:Parameter Name="original_Age" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Course" Type="String" />
<asp:Parameter Name="Year" Type="String" />
<asp:Parameter Name="Age" Type="Int32" />
<asp:Parameter Name="original_Registrationno" Type="Int32" />
<asp:Parameter Name="original_Name" Type="String" />
<asp:Parameter Name="original_Course" Type="String" />
<asp:Parameter Name="original_Year" Type="String" />
<asp:Parameter Name="original_Age" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Registrationno" Type="Int32" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Course" Type="String" />
<asp:Parameter Name="Year" Type="String" />
<asp:Parameter Name="Age" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
96. <asp:Image ID="Image1" ImageUrl="D:priya1App_Dataimagesreading.jpg"
style="text-align: center; height: 480px; width: 700px" runat="server" />
</asp:ContentPlaceHolder>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<h1>VISTAS</h1>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Default.aspx
<%@ Page MasterPageFile="MasterPage.master" %>
MasterPage.master.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DeleteLinkButton3_Click(object sender, EventArgs e)
{
Response.Redirect("UPDATE.aspx");
}
protected void InsertLinkButton3_Click(object sender, EventArgs e)
97. {
Response.Redirect("INSERT.aspx");
}
protected void UpdateLinkButton3_Click(object sender, EventArgs e)
{
Response.Redirect("UPDATE.aspx");
}
protected void loginLinkButton1_Click(object sender, EventArgs e)
{
// Response.Redirect("Login.aspx?url=" + Server.UrlEncode(Request.Url.AbsoluteUri));
Response.Redirect("Login.aspx");
}
}
Login.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" Title="Untitled Page"
%>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Login ID="Login1" runat="server" OnAuthenticate= "ValidateUser"
FailureText="">
</asp:Login>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</asp:Content>
Login.aspx.cs
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Login : System.Web.UI.Page
{
protected void ValidateUser(object sender, EventArgs e)
{
string connectionString = @"Data Source=.SQLEXPRESS; Integrated Security=SSPI; ; User
Instance=True; Initial Catalog=C:UsersUserDocumentssample.mdf;";
98. string SQLQuery = "SELECT Name, Password FROM userdetails where name =@usr";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(SQLQuery, con);
command.Parameters.AddWithValue("@usr", Login1.UserName.ToString());
SqlDataReader Dr;
con.Open();
Dr = command.ExecuteReader();
while (Dr.Read())
{
if ((Login1.UserName.ToString().Trim() == Dr.GetValue(0).ToString().Trim()) &
(Login1.Password.ToString().Trim() == Dr.GetValue(1).ToString().Trim()))
{
Label1.Text = "Successfully Logged In";
}
else
{
Label1.Text = "Not Successfully Logged In";
}
}
}
}
Insert.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="Insert.aspx.cs" Inherits="Insert" Title="Untitled Page"
%>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<table border="2" align="center" cellpadding="5" cellspacing="5">
<tr>
<td> Enter ID :</td>
<td> <asp:TextBox ID="id" runat="server" size="48"></asp:TextBox></td>
</tr>
<tr>
<td> Enter Title :</td>
<td><asp:TextBox ID="title" runat="server" size="48"></asp:TextBox></td>
</tr>
<tr>
<td> Enter Author :</td>
<td> <asp:TextBox ID="author" size="48" runat="server"></asp:TextBox> </td>
99. </tr>
<tr>
<td> Enter Edition :</td>
<td> <asp:TextBox ID="edition1" size="48" runat="server"></asp:TextBox> </td>
</tr>
<tr>
<td> Enter quantity: </td>
<td> <asp:TextBox ID="quantity" size="48" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="Button1" value="submit" onclick="insert_values" runat="server"
Text="Button" />
<asp:Button ID="Button2" value="Reset" runat="server" Text="Button" />
</td>
</tr>
</table>
</asp:Content>
Insert.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Insert : System.Web.UI.Page
{
protected void insert_values(object sender, EventArgs e)
{
string connectionString = @"Data Source=.SQLEXPRESS; Integrated Security=SSPI; ; User
Instance=True; Initial Catalog=C:UsersUserDocumentssample.mdf;";
100. string Query = "insert into libinfo(id,title,author,quantity,edition) values
(@uid,@utitle,@uauthor,@uquantity,@uedition)";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(Query, con);
cmd.Parameters.AddWithValue("@uid",id.Text);
cmd.Parameters.AddWithValue("@utitle", title.Text);
cmd.Parameters.AddWithValue("@uauthor",author.Text);
cmd.Parameters.AddWithValue("@uquantity",quantity.Text);
cmd.Parameters.AddWithValue("@uedition", edition1.Text);
con.Open();
int rows = cmd.ExecuteNonQuery();
if (rows > 0)
{
Page.ClientScript.RegisterStartupScript(
Page.GetType(),
"MessageBox",
"<script language='javascript'>alert('" + "Data Inserted" + "');</script>");
}
}
}
UPDATE.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="UPDATE.aspx.cs" Inherits="UPDATE" Title="Untitled
Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<center>Enter the title of the book to be searched :</center>
<asp:TextBox ID="SearchTextBox1" size="48" runat="server"></asp:TextBox>
<asp:Button ID="subButton1" value="submit" onclick="UPDATEDETAIL" runat="server"
Text="Search" />
<div id="loading" runat="server" visible="false">
<table border="2" align="center" cellpadding="5" cellspacing="5">
<tr>
<td> Enter ID :</td>
<td> <asp:TextBox ID="id1" runat="server" size="48"></asp:TextBox></td>
</tr>
<tr>
<td> Enter Title :</td>
<td><asp:TextBox ID="title1" runat="server" size="48"></asp:TextBox></td>
101. </tr>
<tr>
<td> Enter Author :</td>
<td> <asp:TextBox ID="author1" size="48" runat="server"></asp:TextBox> </td>
</tr>
<tr>
<td> Enter Edition :</td>
<td> <asp:TextBox ID="edition2" size="48" runat="server"></asp:TextBox> </td>
</tr>
<tr>
<td> Enter quantity: </td>
<td> <asp:TextBox ID="quantity1" size="48" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Button ID="updButton1" value="submit" onclick="UPDATEDETAIL" runat="server"
Text="Update" />
</td>
</tr>
</table>
</div>
</asp:Content>
UPDATE.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class UPDATE : System.Web.UI.Page
{
protected void UPDATEDETAIL(object sender, EventArgs e)
102. {
Button clickedButton = sender as Button;
if (clickedButton.ID == "subButton1")
{
loading.Visible = true;
string connectionString = @"Data Source=.SQLEXPRESS; Integrated Security=SSPI; ;
User Instance=True; Initial Catalog=C:UsersUserDocumentssample.mdf;";
string Query = "SELECT * FROM libinfo WHERE title = @utitle";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(Query, con);
cmd.Parameters.AddWithValue("@utitle", SearchTextBox1.Text.ToString());
SqlDataReader Dr;
con.Open();
Dr = cmd.ExecuteReader();
while (Dr.Read())
{
id1.Text = Dr.GetValue(0).ToString();
title1.Text = Dr.GetValue(1).ToString();
author1.Text = Dr.GetValue(2).ToString();
edition2.Text = Dr.GetValue(3).ToString();
quantity1.Text = Dr.GetValue(4).ToString();
}
con.Close();
}
if (clickedButton.ID == "updButton2")
{
string connectionString = @"Data Source=.SQLEXPRESS; Integrated Security=SSPI; ;
User Instance=True; Initial Catalog=C:UsersUserDocumentssample.mdf;";
string Query = "UPDATE LIBINFO SET ID = @uid1, TITLE = @utitle1,
author=@uauthor1, edition=@uedition1,quantity=@uquantity1 WHERE title = @u1title";
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand(Query, con);
cmd.Parameters.AddWithValue("@u1title", SearchTextBox1.Text);
cmd.Parameters.AddWithValue("@uid1", Convert.ToInt16(id1.Text));
cmd.Parameters.AddWithValue("@utitle1", title1.Text);
cmd.Parameters.AddWithValue("@uauthor1", author1.Text);
cmd.Parameters.AddWithValue("@uedition1", edition2.Text);
cmd.Parameters.AddWithValue("@uquantity1", Convert.ToInt16(quantity1.Text));
int updated = cmd.ExecuteNonQuery();
if (updated > 0)
{
Page.ClientScript.RegisterStartupScript(
Page.GetType(),
"MessageBox",
103. "<script language='javascript'>alert('" + updated.ToString() + " record updated." +
"');</script>");
}
}
}
}
Delete.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="Delete.aspx.cs" Inherits="Delete" Title="Untitled
Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<center>Enter the title of the book to be searched :</center>
<asp:TextBox ID="SearchTextBox2" size="48" runat="server"></asp:TextBox>
<asp:Button ID="subButton2" value="submit" onclick="DELETEDETAIL" runat="server"
Text="Search" />
<div id="loading1" runat="server" visible="false">
<table border="2" align="center" cellpadding="5" cellspacing="5">
<tr>
<td> Enter ID :</td>
<td> <asp:TextBox ID="id2" runat="server" size="48"></asp:TextBox></td>
</tr>
<tr>
<td> Enter Title :</td>
<td><asp:TextBox ID="title2" runat="server" size="48"></asp:TextBox></td>
</tr>
<tr>
<td> Enter Author :</td>
<td> <asp:TextBox ID="author2" size="48" runat="server"></asp:TextBox> </td>
</tr>
<tr>
<td> Enter Edition :</td>
<td> <asp:TextBox ID="edition3" size="48" runat="server"></asp:TextBox> </td>
</tr>
<tr>
<td> Enter quantity: </td>
<td> <asp:TextBox ID="quantity2" size="48" runat="server"></asp:TextBox></td>
</tr>
104. <tr>
<td>
<asp:Button ID="updButton2" value="submit" onclick="DELETEDETAIL" runat="server"
Text="Delete" />
</td>
</tr>
</table>
</div>
</asp:Content>
Delete.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Delete : System.Web.UI.Page
{
protected void DELETEDETAIL(object sender, EventArgs e)
{
Button clickedButton = sender as Button;
if (clickedButton.ID == "subButton2")
{
loading1.Visible = true;
string connectionString = @"Data Source=.SQLEXPRESS; Integrated Security=SSPI; ;
User Instance=True; Initial Catalog=C:UsersUserDocumentssample.mdf;";
string Query = "SELECT * FROM libinfo WHERE title = @utitle";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(Query, con);
cmd.Parameters.AddWithValue("@utitle", SearchTextBox2.Text.ToString());
SqlDataReader Dr;
con.Open();
Dr = cmd.ExecuteReader();
while (Dr.Read())
{
id2.Text = Dr.GetValue(0).ToString();
105. title2.Text = Dr.GetValue(1).ToString();
author2.Text = Dr.GetValue(2).ToString();
edition3.Text = Dr.GetValue(3).ToString();
quantity2.Text = Dr.GetValue(4).ToString();
}
con.Close();
}
if (clickedButton.ID == "updButton2")
{
string connectionString = @"Data Source=.SQLEXPRESS; Integrated Security=SSPI; ;
User Instance=True; Initial Catalog=C:UsersUserDocumentssample.mdf;";
string Query = "delete from LIBINFO WHERE title = @u1title";
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand(Query, con);
cmd.Parameters.AddWithValue("@u1title", SearchTextBox2.Text);
id2.Text = null;
title2.Text = null;
author2.Text = null;
edition3.Text = null;
quantity2.Text = null;
int deleted = cmd.ExecuteNonQuery();
if (deleted > 0)
{
Page.ClientScript.RegisterStartupScript(
Page.GetType(),
"MessageBox",
"<script language='javascript'>alert('" + deleted.ToString() + " record Deleted." +
"');</script>");
}
}
}
}
CREATE TABLE libinfo(
id int,
title varchar(50),
author varchar(50),
Quantity int,
Edition varchar(50))
109. RESULT:
Thus the web application program is executed with Insert, Update and Delete option.
110. Aim:
To write a Perl program to find whether the year entered is LEAP YEAR or not
ALGORITHM:
Step 1: Get two inputs Start Year and End Year
Step 2: loop through between the start and end year
Step 3: Check if year is divisible by 4 but not 100, DISPLAY "leap year"
Step 4: Check if year is divisible by 400, DISPLAY "leap year"
Step 5: Otherwise, DISPLAY "not leap year"
EX.NO: 8.A
LEAP YEAR
DATE:
111. PROGRAM
#!usr/bin/perl
# print a statement about the program
print "Perl Script to Print Leap years!nn";
# get the start and end year from user
print "Enter Start Year: ";
$startYear=<STDIN>;
print "Enter End Year: ";
$endYear=<STDIN>;
print "Leap years are:n";
# loop through between the start and end year
for($i=$startYear; $i <= $endYear; $i++){
if( (0 == $i % 4) && (0 != $i % 100) || (0 == $i % 400) ){
print "${i}n";
}
}
112. OUTPUT
$ perl perltest.pl
Perl Script to Print Leap years!
Enter Start Year: 2019
Enter End Year: 2030
Leap years are:
2020
2024
2028
113. RESULT:
Thus the PERL program to find whether the year entered is LEAP YEAR or not was
executed successfully.
114. AIM :
To swap two numbers using TEMP variable and without using TEMP variable using
PERL.
ALGORITHM
WITH TEMP VARIABLE
Step 1:Copy value of Var1 to Temp
Step 2:Copy value of Var2 to Var1
Step 3 :Copy value of Temp to Var2
WITHOUT TEMP VARIABLE
Step 1 : Add Var1 and Var2 and store to Var1
Step 2:Subtract Var2 from Var1 and store to Var2
Step 3 :Subtract Var2 from Var1 and store to Var1
EX.NO: 8.B
SWAP NUMBERS
DATE:
115. PROGRAM
$a=10;
$b=20;
print"Value of a: $a</br>";
print "Value of b: $b</br>";
$temp=$a;
$a=$b;
$b=$temp;
print "Value of a: $an";
print "Value of b: $bn";
$a=10;
$b=20;
print "Value of a: $an";
print "Value of b: $bn";
$a=$a+$b;
$b=$a-$b;
$a=$a-$b;
print "Value of a: $an";
print "Value of b: $bn";
116. OUTPUT:
user@boss:~$ perl swap.pl
Value of a: 10
Value of b: 20
Value of a using TEMP: 20
Value of b using TEMP: 10
Value of a: 10
Value of b: 20
Value of a without using TEMP: 20
Value of b: without using TEMP: 10
117. RESULT :
Thus swapping two numbers using TEMP variable and without using TEMP variable was
executed and result obtained.
118. AIM:
To write a program to Compute Sum of Series 1/1! + 1/2! + 1/3! + 1/4! + .. + 1/n!
using perl.
ALGORITHM:
STEP 1: Create a function factorial to find the factorial of number using fact=fact*i
STEP2: Create a function to find the sum of values using sum = sum+factorial(i)
STEP3:Print the Final value.
EX.NO: 8.C
SUM OF SERIES
DATE:
119. PROGRAM
sub factorial($n)
{
$res = 1;
for ($i = 2; $i <= $n; $i++)
$res *= $i;
return $res;
}
// A Simple Function to return
// value of 1/1! + 1/2! + .. + 1/n!
sub sum($n)
{
$sum = 0;
for ($i = 1; $i <= $n; $i++)
$sum += 1.0 / factorial($i);
return $sum;
}
// Driver Code
$n = 5;
print(sum($n));