Beruflich Dokumente
Kultur Dokumente
1) AIM: Write a program for stack using linked list PROGRAM: #include<iostream.h> #include<conio.h> #include<stdio.h> #include<malloc.h> struct chainnode { int item; chainnode *next; }; class stacklist { private: struct chainnode *top; int listsize; public: stacklist() { listsize=0; } int asizeof() { return(listsize); } int push(int element) { struct chainnode *temp; temp=new chainnode ; if(!temp) return(0); temp->item=element; temp->next=top; top=temp; listsize++; return(1); } int pop() {
Page 1
Page 4
2) AIM: Write a program for queue using linked list PROGRAM: #include<iostream.h> #include<conio.h> #include<stdio.h> #include<malloc.h> struct chainnode { int item; chainnode *next; }; class queuelist { private: struct chainnode *front,*rare; int listsize; public: queuelist() { listsize=0; } int asizeof() { return(listsize); } int insert(int element) { struct chainnode *temp;
Page 5
of
Page 7
3)AIM: Write a program for implementing Binary search. PROGRAM: #include<iostream.h> #include<conio.h> void main() { int a[20],n,mid,f,l,c,flag=0,x; clrscr(); cout<<"Enter the size of the array:"; cin>>n; cout<<"\nEnter the elements in ascending order:"; for(c=0;c<n;c++) cin>>a[c]; cout<<"\nEnter the searching element:\n"; cin>>x; c=0;f=0;l=n; while((flag==0)&&(c<n)) { mid=(f+l)/2;
Page 9
Page 10
4) AIM: Write a program for mergesort. PROGRAM: #include<iostream.h> #include<conio.h> int a[50]; void merge(int,int,int); void merge_sort(int low,int high) { int mid; if(low<high) { mid=(low+high)/2; merge_sort(low,mid); merge_sort(mid+1,high); merge(low,mid,high); } } void merge(int low,int mid,int high) { int h,i,j,b[50],k; h=low; i=low; j=mid+1; while((h<=mid)&&(j<=high)) { if(a[h]<=a[j]) { b[i]=a[h]; h++; } else { b[i]=a[j];
Page 11
Page 12
Please Enter THE NUMBER OF ELEMENTS you want to sort [THEN PRESS ENTER]: 5 Now, Please Enter the ( 5 ) numbers (ELEMENTS) [THEN PRESS ENTER]: 23 56 11 9 30 So, the sorted list (using MERGE SORT) will be : 9 11 23 30 56
5) AIM: Write a program for Quick sort PROGRAM: #include<iostream.h> #include<conio.h> #include<process.h> class Qsort { int *a; int n; public: Qsort(int size)
Page 13
Page 15
Page 16
Page 17
Enter how many numbers u want to sort 5 Enter the values 21 11 90 45 9 the sorted order is : 9 11 21 45 90
8)AIM: Write a program for implementation of prims algorithm PROGRAM: #include<iostream.h> #include<conio.h> void main() { int min=0,pnear[10],n=7,j,p,i,k,l,min1,o; int c[100][100]; int t[100][2]; clrscr(); cout<<"Enter number of nodes:"; cin>>n;
Page 19
9) AIM: Write a program for implementation of BFS (Breadth First Search) PROGRAM: #include<iostream.h> #include<conio.h> class bfs { int v,u,n,i,j,str; int gra[20][20],visited[20]; public: bfs(){} void bfs1(int); void bft(); void input(); int adj(int,int); }; void bfs::input() { cout<<"\nEnter the number of nodes\n"; cin>>n; cout<<"\nEnter the adjcency matrix\n"; for(i=1;i<=n;i++) for(j=1;j<=n;j++) cin>>gra[i][j]; } int bfs::adj(int a,int b) { if(gra[a][b]==1) return 1; else return 0; } void bfs::bft() {
Page 22
Enter the number of nodes 3 Enter the adjcency matrix 101 101 100 BFT is 1 3 2
Page 24
Page 27
12) AIM: Write a HTML program to implement Timetable PROGRAM: <html> <head>
Page 28
Page 30
Page 31
Page 32
Page 33
Page 34
Page 35
Page 36
Page 37
Page 38
Page 39
Page 41
Page 42
Page 44
17) AIM: Write a Servlet program to access details from a form PROGRAM:
Page 45
studentform.html <html> <head> <title>student form</title> </head> <body> <center> <form method="get" action="/staticform/student"> enter student name: <input type=text name=sname><br><br> enter student age: <input type=text name=sage><br><br> <input type="submit" name=send value="send"> </form> </center> </body> StudentEx.java import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class StudentEx extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter k = res.getWriter(); String name = req.getParameter("sname"); String age = req.getParameter("sage"); k.println("<body bgcolor = cyan>"); k.println("Hello: "+ name ); k.println("your age:"+age); k.println("</body>"); } } web.xml
Page 46
<web-app> <servlet> <servlet-name>first</servlet-name> <servlet-class>StudentEx</servlet-class> </servlet> <servlet-mapping> <servlet-name>first</servlet-name> <url-pattern>/student</url-pattern> </servlet-mapping> </web-app>
Page 47
Page 48
Page 49
Page 50
OUTPUT:
19)AIM:- The Web Application takes the user details from the user, interact with the database and checks with the database user details. If user details exists login to site else display login page again. PROGRAM: <html> <body> <center><h1>MY Company</h1><br><br><br> <form name="form1" method="post" action="login">
Page 51
public class DBClass { public boolean validate(String uname,String pass){ try{ /* Type 1 driver Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connecttion con=DriverManager.getConnection("jdbc:odbc:myds n","scott","tiger"); */ Class.forName("com.mysql.jdbc.Driver"); Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/kiran","root","pas sword");
Page 52
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class LoginServlet extends HttpServlet { DBClass ud; public void init(){ud=new DBClass();} public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException { response.setContentType("text/html"); PrintWriter out=response.getWriter(); String uname=request.getParameter("uname"); String pass=request.getParameter("pass"); ud=new DBClass(); if(ud.validate(uname,pass)){ out.println("<h3>Welcome, "+uname+"<h3><br/>"); out.println(" You have logged into the Site"); } else{ out.println("<h2>Your Details not found please login with valid details...</h2>"); out.println("</body></html>"); } } }
Page 53
Web.xml:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'> <web-app> <servlet> <servlet-name>LoginServlet</servlet-name> <servlet-class>LoginServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>LoginServlet</servlet-name> <url-pattern>/login</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>Login.html</welcome-file> </welcome-file-list> </web-app>
Page 54
20)AIM: JSP Pages to take input from the User redirect to Another JSP to Print name and Date PROGRAM:
Page 55
Page 56
Page 57
21)AIM:Web Application take Student detail from the User and Displays the Class . if student marks are >=60 then First Class if >=50 second class if less then 50% then fail.
Page 58
</web-app>
Page 61
Page 62
Page 63