Tuesday, March 27, 2018

queue using Linked list

/* Program to implement queue using Linked list */
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
#include <stdlib.h>
struct node
{
int info;
struct node *link;
};
struct node *front, *rear;

void main ( )
{
clrscr();
void insert(),delet(),display();
int ch;
while (1)
{
printf ("1. Insert\n");
printf ("2. Delete\n");
printf ("3. Display\n");
printf ("4. Exit\n");
printf ("Enter your choice :");
scanf ("%d", &ch);
switch (ch)
{
case 1 :
insert ( );
break;
case 2 :
delet( );
break;
case 3 :
display ( );
break;
case 4 :
exit(0);
default:
printf ("Please enter correct choice \n");
}
}
getch();
    }

void insert ( )
{
struct node *ptr;
ptr = (struct node*) malloc (sizeof (struct node));
int item;
printf ("Input the element for inserting :\n");
scanf ("%d", &item);
ptr-> info = item;
ptr->link = NULL;
if (front==NULL) /* queue is empty*/
front = ptr;
else
rear->link = ptr;
rear = ptr;
}
void delet( )
{
struct node *ptr;
if (front==NULL)
{
printf ("Queue is underflow \n");
return;
}
if (front==rear)
{
free (front);
rear = NULL;
}
else
{
ptr = front;
front = ptr->link;
free (ptr);
}
}
void display ( )
{
struct node *ptr;
ptr = front;
if (front==NULL)
printf("Queue is empty\n");
else
{
printf("\nElements in the Queue are:\n");
while(ptr!=NULL)
{
printf(" %d\n",ptr->info);
ptr=ptr->link;
}
printf("\n");
}
}

queue using array

/* Program to implement queue using array */
#include <stdio.h>
#include <conio.h>
#define MAX 100

int q[MAX + 1], front = 0, rear = 0;

void main ( )
{
clrscr();
void create(),traverse(),insert(),delet();
create ( );
traverse ();
insert ( );
printf("\n After insert an element");
traverse();
delet ( );
printf("\nAfter deletion");
traverse ( );
getch ( );
}

void create ( )
{
char ch;
front=1;
do
{
rear++;
printf ("\nInput element in queue:\n");
scanf ("%d", & q[rear]);
printf ("Press <Y/N> for more element");
ch = getch ( );
}
while (ch=='Y');
}

void traverse ( )
{
int i;
printf ("\nelements in the Queue are:\n");
for (i=front; i<=rear;++i)
printf ("%d\n", q[i]);
}

void insert ( )
{
int m;
if (rear == MAX)
{
printf ("Queue is overflow \n");
return;
}
printf ("\nInput new element to insert\n");
scanf ("%d", &m);
rear++;
q[rear]=m;
}

void delet( )
{
if (front==0)
{
printf ("Queue is underflow\n");
return;
}
if (front==rear)
{
q[front] = '\0';
front = rear = 0;
}
else
{
q[front] = '\0';
front++;
}
}

Monday, March 12, 2018

Regarding Record W&IT Lab



  1. Bio-data Form Registration
  2. TimeTable Design
  3. HTML page with different Frames 
  4. Web page with different Styles 
  5. Exception Handling in Java Script 
  6. Sorting Values in Array Using Java Script

AIM
Description 
Source Code
Input&Output
Result

Wednesday, March 7, 2018

webpage by applying the different styles


3. Design the webpage by applying the different styles using inline, external & internal style sheets.
Inline.html”
<html>
<head>
<title>inline</title></head>
<body>
<p style="color:purple;margin-left:20px;">This is a paragraph line. </p>
<div style="color:purple;font-size:16px;background-color:#FF6633;">
This is a paragraph Second line.</p>
</body>
</html>



<html>
<head>
<style type="text/css">
p {
   color:purple;
   margin-left:20px;
  }
div{
   color:purple;
   font-size:16px;
   background-color:#FF6633;
  }
</style>
</head>
<body>
    <p>This is a paragraph line.</p>
    <div>This is a paragraph Second line.</div>
</body>
<html>



jnj_css.css
body
{
background-color:#f9864d;
}
p{
color:orange;
font-size:18px;
}

External.html
<html>
<head>
<link rel="stylesheet" type="text/css" href="jnj_css.css" />
</head>
<body>
<p>This is a paragraph line.</p>
<div>This is a paragraph Second line.</div>
</body>
</html>

html page with different types of frames


2. To create an html page with different types of frames such as floating frame, navigation frame & mixed frame.
Procedure-
Ø  Create an html page named as mixedframe.html. Divide the page into 2 columns of 25% and 75% size. In 25% display the image file and divide the 75% into 2 rows(50% and 50%). In the first 50% display the other images
Ø   Create an html page named as navigationframe.html. divide the page into 2 columns  of 25%, 75% size. In 25% size call the hyperlink file and make the page to be get displayed on the other column when the link is clicked.
Ø  Create an html page named as floatingframe.html. In this file include a paragraph to explain floating frame and in floating frame include any html file created in above experiment.

File name:samba.html
<html>
<body>
<a href="frames.html" target="two">navigation frame</a><br>
<a href="floatingframe.html" target="two">floating frame</a><br>
<a href="mixedframe.html" target="two">mixed frame</a><br>
</body>
</html>
File name: navigation frame.html
<html>
<frameset cols="25%,*" scrolling="no" noresize>
<frame name="one"></frame>
<frame name="two"></frame>
</frameset>
</html>

File name: floatingframe.html
<html>
<head>
<title>floatingframe</title></head>
<body>
hello<br>
<p>this page contains floatingframes </p>
</html>

File name: mixedframe.html
<html>
<frameset cols="25%,*" scrolling="no" noresize>
<frame name="image1" src="Desert.jpg"></frame>
<frameset rows="50%,*" scrolling="no" noresize>
<frame name="image2" src="Tulips.jpg"></frame>
<frame name="image3" src="Penguins.jpg"></frame>
</frameset>
</html>

bio-data form using html


Prog-1. To create a simple student bio-data form using html5 . it should contain the following name (text box), address (multiline text box),gender (radio button male,female),skill sets known (check boxes – c,c++,java,C#etc), extra curricular activities (text box), nationality (combobox) ,submit and reset button.

<html>
 <body>
  <form>
  
   Name <br/>
   <input type="text" size="30" value="ABC">
   <br/><br/>

   Password <br/>
   <input type="password" >
   <br/><br/>
  
   Phone<br/>
   <input type="tel" name="Phone" maxlength="10">
   <br/><br/>
  
   Gender
   <input type="radio" name="gender" value="M" checked>Male
   <input type="radio" name="gender" value="F">Female
   <br/><br/>

   Languages known
<input type="checkbox">Telugu
   <input type="checkbox" checked>English
   <input type="checkbox">Hindi
   <br/><br/>

   Eduction
   <Select>
    <option>Graduation</option>
    <option selected>Post Graduation</option>
   </Select>
   <br/><br/>
skills
<input type="checkbox">C
   <input type="checkbox" checked>C++
   <input type="checkbox">JAVA
<br>
<br>
   Address <br/>
   <textarea rows="5" cols="30" style="resize: none;"></textarea>
   <br/><br/>
Nationality
<Select>
    <option>Indian</option>
    <option selected>Other</option>
   </Select>
<br>
<br>
 Extra curricular activities <br/>
   <textarea rows="5" cols="30" > </textarea>
   <br/><br/>
   Image<br/>
   <input type="file">  
   <br/><br/>

   <input type="reset" value="Reset">
   <input type="submit" value="Submit Form">
   </form>
 </body>
</html>

Data Structures Programs on STACK


/* Decimal to binary conversion uses stack */
#include <stdio.h>
#include <conio.h>
void main ( )
{
int stack[30], dec, rem, top=0;
clrscr();
printf ("\nEnter decimal number:\n");
scanf("%d", &dec);
while (dec!=0)
{
rem=dec%2;
top++;
stack[top]=rem;
dec=dec/2;
}
printf ("\nThe equivalent binary number is\n");
for (; top>0; top--)
{
printf ("%d", stack[top]);
}
getch ( );
}
/* Towers of Hanoi problem using recursion */
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
char A='A',B='B',C='C';
void hanoi(int, char, char, char);
clrscr();
printf ("Enter Number of Disks:");
scanf("%d",&n);
printf("\n\n Tower of Hanoi problem with %d disks\n",n);
printf("Sequence is :\n");
hanoi (n, A, B, C);
printf ("\n");
getch();
}
void hanoi(int n, char A, char B, char C)
{
if (n!=0)
{
hanoi (n-1,A,C,B);
printf ("Move disk %d from %c to %c\n",n,A,C);
hanoi (n-1,B,A,C);
}
}

/* Convert Infix Expression into Postfix Expression */
#include<stdio.h>
#include<conio.h>
#include<string.h>
char stack [30];
int top = -1;
void infix_to_postfix (char *);
void push(char);
char pop ( );
void main ( )
{
char infix [30];
clrscr();
printf ("\n Enter the infix expression:\n");
gets (infix);
infix_to_postfix (infix);
getch ( );
}
void push (char sym)
{
if (top >= 29)
{
printf ("\n stack is overflow");
getch ( );
return;
}
else
{
top = top + 1;
stack [top] = sym;
}
}
char pop ( )
{
char i;
if (top ==-1)
{
printf ("\n stack is empty");
return(0);
}
else
{
i = stack [top];
top = top - 1;
}
return (i);
}
int prec (char ch)
{
if (ch=='^')
{
return (5);
}
else if (ch=='*' || ch=='/')
{
return (4);
}
else if (ch=='+' || ch=='-')
{
return (3);
}
else
{
return (2);
}
}
void infix_to_postfix (char infix [ ])
{
int length;
static int index = 0, pos= 0;
char symbol, temp;
char postfix [50];
length = strlen(infix);
while (index < length)
{
symbol = infix[index];
switch (symbol)
{
case '(' : push (symbol);
break;
case ')' : temp = pop ( );
while (temp != '(')
{
postfix [pos]=temp;
pos++;
temp=pop ();
}
break;
case '+' :
case '-' :
case '*' :
case '/' :
while (prec (stack[top]) >= prec (symbol))
{
temp = pop();
postfix [pos]= temp;
pos++;
}
push (symbol);
break;
default:postfix [pos++] = symbol;
break;
}
index++;
}
while (top>=0)
{
temp = pop ( );
postfix [pos++] = temp;
}
postfix [pos++] = '\0';
printf("\nEquivalent postfix expression is:\n");
puts (postfix);
return;
}
/* Program to Evaluate Postfix Notation */
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main( )
{
char S[80];
int i, top=-1, n, x=0, y=0, stack[80];
clrscr ( );
printf ("\n Enter the valid postfix notation :");
gets(S);
n = strlen(S);
printf ("The value of the postfix notation is :");
for (i=0;i<n; i++)
{
switch (S[i])
{
case '+' :
y=stack[top];
x=stack[top-1];
top = top-1;
x=x+y;
stack[top] = x;
break;
case '-' :
y=stack[top];
x=stack[top-1];
top = top-1;
x=x-y;
stack[top] = x;
break;
case '*' :
y=stack[top];
x=stack[top-1];
top = top-1;
x=x*y;
stack[top] = x;
break;
case '/' :
y=stack[top];
x=stack[top-1];
top = top-1;
x=x/y;
stack[top] = x;
break;
default :
top = top+1;
if (S[i]>=48 && S[i]<=57)
x = S[i] - 48;
stack[top] = x;
x=0;
}
}
printf("%d", stack[top]);
getch( );
}

Sunday, March 4, 2018

stack using Link-list

/* Implementation of stack by using Linked-list */
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
struct node
{
int info;
struct node *link;
};
struct node *top;
void main()
{
void create(),traverse (),push ( ),pop ();
clrscr();
create ();
printf("\nstack is:\n");
traverse ();
push ();
printf("\nAfter push the element the stack is:\n");
traverse ();
pop ();
printf("\nAfter pop the element the stack is:\n");
traverse ( );
getch ( );
}

void create ( )
{
struct node *ptr, *cpt;
char ch;
ptr = (struct node *) malloc (sizeof (struct node));
printf ("Input first info");
scanf("%d",&ptr ->info);
ptr->link = NULL;
do
{
cpt=(struct node *) malloc (sizeof (struct node));
printf("\nInput next information\n");
scanf ("%d", &cpt->info);
cpt->link= ptr;
ptr=cpt;
printf("Press <Y/N> for more information");
ch=getche();
}
while (ch=='Y');
top = ptr;
}
void traverse ( )
{
struct node *ptr;
printf ("Traversing of stack :\n");
ptr=top;
while (ptr !=NULL)
{
printf ("%d\n", ptr->info);
ptr=ptr->link;
}
}


void push ( )
{
struct node *ptr;
ptr = (struct node *) malloc (sizeof (struct node));
if (ptr==NULL)
{
printf("Overflow\n");
return;
}
printf ("Input New node information");
scanf ("%d", &ptr->info);
ptr->link=top;
top = ptr;
}
void pop ( )
{
struct node *ptr;
if (top==NULL)
{
printf ("Underflow \n");
return;
}
ptr=top;
top = ptr->link;
free (ptr);
}

stack using Array

/* Implementation of stack by using Array */
#include <stdio.h>
#include <conio.h>
#define MAX 50
int stack [MAX+1], top = 0;
void main ( )
{
void create( );
void traverse( );
void push( );
void pop( );
clrscr();
create ( );
printf("\n Stack is :\n");
traverse ( );
push ( );
printf("After Push an element the stack is:\n");
traverse ( );
pop ( );
printf("After pop the element the stack is:\n");
traverse ( );
getch ( );
}
void create ( )
{
char ch;
do
{
top ++;
printf ("Input Element");
scanf ("%d", &stack[top]);
printf ("Press <Y> for more element \n");
ch = getch ( );
}
while (ch=='Y');
}
void traverse ( )
{
int i;
for (i=top; i>0; --i)
printf ("%d\n", stack[i]);
}
void push ( )
{
int m;
if (top==MAX)
{
printf ("Stack is overflow");
return;
}
printf ("Input New Element to Insert");
scanf ("%d", &m);
top++;
stack[top]=m;
}
void pop ( )
{
if (top==0)
{
printf ("Stack is underflow\n");
return;
}
stack[top]='\0';
top--;
}

Saturday, March 3, 2018

single text field calculator

Write a jsp program to implement the single text field calculator.

 calculator.html
<html>
<title>calculator</title>
<head><h1><center>Basic Calculator</center></h1></head>
<body>
<center>
<form action="calculator.jsp" method="get">

<label for="num1"><b>Number 1</b></label>
<input type="text" name ="num1"><br><br>
<label for = "num2"><b>Number 2</b></label>
<input type="text" name="num2"><br><br>

<input type ="radio" name = "r1" value="Add">+ 
<input type = "radio" name = "r1" value="Sub">-<br>
<input type="radio" name="r1" value ="mul">* 
<input type = "radio" name="r1" value="div">/<br><br>

<input type="submit" value="submit">
</center>
</body>
</html>
Calculate.jsp
<html>
<title>calculator</title>
<head></head>
<body>
<%@page language="java"%>
<%
int num1 = Integer.parseInt(request.getParameter("num1"));
int num2 = Integer.parseInt(request.getParameter("num2"));
String operation = request.getParameter("r1");
if(operation.equals("Add")){
int add=num1+num2;
out.println("Addition is: "+add);
}
else if(operation.equals("Sub")){
int sub=num1-num2;
out.println("Substraction is: "+sub);
}
else if(operation.equals("mul")){
int mul=num1*num2;
out.println("multiplication is: "+mul);
}
else if(operation.equals("div"))
{
int div = num1/num2;
if(num1>=num2)
out.println("division is: "+div);
else
out.println("The division cannot be performed");
}
%>
</body>
</html>
web.xml
<web-app>
</web-app>

demonstrate exception handling in java script

To create an html page to demonstrate exception handling in javascript, Create an html page named as ―exception.html and do the following.
i. within the script tag write code to handle exception
a) define a method RunTest() to get any string values(str) from the user and call the method Areletters(str).
b) In Areletters(str) method check whether str contain only alphabets (a-z, AZ), if not throw exception.

c) Define a exception method Input Exception(str) to handle the exception thrown by the above method.


<!DOCTYPE html>
<html>
<body  >

<p >Click the button to demonstrate Exception handling </p>

<button  onclick="RunTest()" >Touch me</button>

<p id="message"></p>

<script>
 function isalpha(str) {
var f=0;
for(i=0;i<str.length;i++)
   {
            if (((str[i] >= 'a') && (str[i] <= 'z')) || ((str[i] >= 'A') && (str[i] <= 'Z')))
               f=0;
            else
            f=1;
}
if (f==0)
return 1;
else
return 0;
  }
function RunTest() {
    var str = prompt("Please enter any string", "sambasiva");



try {
        if(str == "") throw "is empty";
      else if(!isalpha(str)) throw "string must contain alphabets only";
       else
          document.getElementById("message").innerHTML =
        "Entered string: " + str;

    }

    catch(err) {
        document.getElementById("message").innerHTML = "Error: " + err + ".";
    }

 
}
</script>

</body>
</html>