Académique Documents
Professionnel Documents
Culture Documents
Q1. Develop a web page using servlet and JDBC to display the details of books on topic DBMS
Ans:
1
Q2. Write a program using JDBC and JSP to display the name, address and account number of all the
saving account holders of a branch of a Bank, having balance of Rs. 5000/- or more in their account.
Ans.
//signin.html
<html>
<title><signin></title>
<body bgcolor="#E7E7EF"><br><br><br>
<center><table>
</table></center>
</body>
2
</html>
//Check.java
import javax.servlet.*;
import java.io.*;
import java.sql.*;
import javax.servlet.http.*;
PrintWriter out=response.getWriter();
String acno=request.getParameter("user");
System.out.println(acno);
String pass=request.getParameter("pass");
HttpSession session=request.getSession();
session.setAttribute("sess",acno);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Statement st=con.createStatement();
if(rs.next())
{ String s1=rs.getString(1);
out.println("name"+s1);
RequestDispatcher rd=request.getRequestDispatcher("/user.jsp");
rd.forward(request,response);
}else
{ RequestDispatcher rd=request.getRequestDispatcher("signin.html");
rd.forward(request,response);
3
}
catch(Exception e){
}}}
//user.jsp
<html>
<body bgcolor="#ccccdd">
<%
String acno=(String)session.getAttribute("sess");
System.out.println(acno);
%><center>
</center>
</body>
</html>
//credit.html
<html>
<form action="credit.jsp">
<body bgcolor="#ccccdd"><center><table>
</body> </form>
</html>
4
Debit Design Page
//debit.html
<html>
<form action="debit.jsp">
<body bgcolor="#ccccdd"><center><table>
</body>
</form>
</html>
//credit.jsp
<html>
<%
String amount=request.getParameter("amnt");
int iamount=Integer.parseInt(amount);
String acnt=request.getParameter("ac");
int acno=Integer.parseInt(acnt);
String type="Credit";
String
dor =String.valueOf(calendar.get(Calendar.DATE))+"/"+String.valueOf(calendar.get
5
(Calendar.M
ONTH))+"/"+String.valueOf(calendar.get(Calendar.YEAR));
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Statement st=con.createStatement();
int totbal=0;
while(rs.next())
{ int s1=rs.getInt(5);
totbal=s1-iamount;
if(totbal<=0)
}else
}}
int i = pstmt.executeUpdate();
pstmt1.setString(1,dor);
pstmt1.setInt(2,totbal);
pstmt1.setInt(3,acno);
pstmt1.setString(4,type);
pstmt1.setInt(5,iamount);
int i1 = pstmt1.executeUpdate();
catch(Exception e){
}%></html>
6
Program to Credit the Amount and Display the balance
//debit.jsp
<html>
<body>
<%
String amount=request.getParameter("amnt");
int iamount=Integer.parseInt(amount);
String acnt=request.getParameter("ac");
int acno=Integer.parseInt(acnt);
String type="Debit";
ONTH))+"/"+String.valueOf(calendar.get(Calendar.YEAR));
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Statement st=con.createStatement();
int totbal=0;
while(rs.next())
{ int s1=rs.getInt(5);
if(s1>=500)
{totbal=s1-iamount;
7
out.println("Your balance is"+totbal);
}else{
totbal=s1;
int i = pstmt.executeUpdate();
pstmt1.setString(1,dor);
pstmt1.setInt(2,totbal);
pstmt1.setInt(3,acno);
pstmt1.setString(4,type);
pstmt1.setInt(5,iamount);
int i1 = pstmt1.executeUpdate();
catch(Exception e){
}%></html>
//month.jsp
<html>
<%String acno=(String)session.getAttribute("sess");
System.out.println(acno);
int chk=Integer.parseInt(acno);
int l=0;
int rowcu=0;
int totalRecords=0;
8
ResultSetMetaData rsmt=null;
ResultSet datars=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
cot=DriverManager.getConnection("jdbc:odbc:ques");
Statement stmtt=cot.createStatement();
Statement rowc=cot.createStatement();
Statement datas=cot.createStatement();
where Acno="+chk);
int x=0;
while(resucourow.next()){
x++;
resultt.next();
rsmt=resultt.getMetaData();
l=rsmt.getColumnCount();
System.out.println("Column Count"+l);
Acno="+chk);
}catch(Exception e1){
}%>
<tr>
cnames=rsmt.getColumnName(v);%>
9
<td width="50%"><font face="Arial, Helvetica" color = 'red'
size='5'><b><i><%=cnames.toUpperCase()%></i></b></font></td>
<%}%>
</tr><%
while(datars.next()){%>
<tr><%for(int vc=1;vc<=l;vc++){%>
Helvetica"><%=datars.getString(vc)%></font></td><%
}</html> }%>
Q3. Write a JSP program using JDBC to keep records of personal information of its employees. The
program should provide facility of view details of employees, modify their details and add details of
new employees. Design appropriate User Interface and implement proper validation mechanism for
Ans.
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
</head>
<body>
<table>
10
<tr><td>Country:</td><td>
<option>India</option>
<option>USA</option>
<option>UK</option>
<option>Other</option>
</select>
</td></tr>
</table>
</form>
<br/>
</body>
</html>
Update details:-
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/EditServlet")
response.setContentType("text/html");
11
PrintWriterout=response.getWriter();
out.println("<h1>Update Employee</h1>");
String sid=request.getParameter("id");
int id=Integer.parseInt(sid);
Empe=EmpDao.getEmployeeById(id);
out.print("<table>");
></tr>");
sword()+"'/>
</td></tr>");
></tr>");
out.print("<tr><td>Country:</td><td>");
out.print("<option>India</option>");
out.print("<option>USA</option>");
out.print("<option>UK</option>");
out.print("<option>Other</option>");
out.print("</select>");
out.print("</td></tr>");
out.print("</table>");
out.print("</form>");
out.close();
12
View Details :-
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/ViewServlet")
response.setContentType("text/html");
PrintWriterout=response.getWriter();
out.println("<h1>Employees List</h1>");
List<Emp> list=EmpDao.getAllEmployees();
out.print("<tr><th>Id</th><th>Name</th><th>Password</th><th>Email</th><th>Country</th>
<th>Edit</th><th>Delete</th></tr>");
for(Empe:list){
out.print("<tr><td>"+e.getId()+"</td><td>"+e.getName()+"</td><td>"+e.getPassword()+"</td>
<td>"+e.getEmail()+"</td><td>"+e.getCountry()+"</td><td><a href='EditServlet?id="+e.getId()
+"'>edit</a></td>
<td><a href='DeleteServlet?id="+e.getId()+"'>delete</a></td></tr>");
out.print("</table>");
out.close();
13
}
Output:-
Update
14
View
Q4.Create an XML document for keeping MCA students information at a study centre of IGNOU.
Ans.
15
PART-II: MCS-053 (Computer Graphics and Multimedia)
Q1. Write a program in C/C++ using OpenGL to draw a Triangle of orange colour and inside
Ans.
#include <windows.h>
#include <gl/glut.h>
#include <math.h>
void drawCircle(){
glBegin(GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
double x = 5*cos(angle);
16
double y = 5*sin(angle);
glVertex2d(x,y);
glEnd();
void drawRect(){
glColor3f(0.0,0.0,1.0);
glRectf(-5.0,5.0,5.0,-5.0);
void init(void){
glClearColor(0.0,1.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-10.0,10.0,-10.0,10.0,-10.0,10.0);
void display(void)
glClear(GL_COLOR_BUFFER_BIT);
drawRect();
drawCircle();
glutSwapBuffers();
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(320,320);
glutInitWindowPosition(50,50);
glutCreateWindow("2D Shapes");
init();
17
glutDisplayFunc(display);
glutMainLoop();
return 0;
Output :-
Ans.
#include<Windows.h>
// for MS Windows
#include<GL\glut.h>
void init()
18
glClearColor(0.5, 0.9, 0.4, 0.0);
glMatrixMode(GL_PROJECTION);
// Set 2D Transformation as gluOrtho2D(Min Width, Max Width, Min Height, Max Height)
glVertex2i(100, 350);
glVertex2i(300, 350);
glEnd();
// Front Wall
glBegin(GL_POLYGON);
glVertex2i(100, 350);
glVertex2i(300, 350);
glVertex2i(300, 100);
glVertex2i(100, 100);
glEnd();
// Front Door
glBegin(GL_POLYGON);
glVertex2i(150, 250);
glVertex2i(250, 250);
glVertex2i(250, 100);
glVertex2i(150, 100);
glEnd();
glPointSize(15);
glBegin(GL_POINTS);
19
glVertex2i(170, 170);
glEnd();
//side Wall
glBegin(GL_POLYGON);
glVertex2i(300, 350);
glVertex2i(700, 350);
glVertex2i(700, 100);
glVertex2i(300, 100);
glEnd();
glLineWidth(5);
glBegin(GL_LINES);
glVertex2i(390, 320);
glVertex2i(390, 230);
glVertex2i(330, 273);
glVertex2i(450, 273);
glEnd();
// window two
glBegin(GL_POLYGON);
glVertex2i(530, 320);
glVertex2i(650, 320);
glVertex2i(650, 230);
glVertex2i(530, 230);
glEnd();
20
// lines of window two
glLineWidth(5);
glBegin(GL_LINES);
glVertex2i(590, 320);
glVertex2i(590, 230);
glVertex2i(530, 273);
glVertex2i(650, 273);
glEnd();
// Entrance Path
glLineWidth(3);
glBegin(GL_POLYGON);
glVertex2i(150, 100);
glVertex2i(250, 100);
glVertex2i(210, 0);
glVertex2i(40, 0);
glEnd();
glFlush();
// Initialize GLUT
21
// window one
glBegin(GL_POLYGON);
glVertex2i(330, 320);
glVertex2i(450, 320);
glVertex2i(450, 230);
glVertex2i(330, 230);
glEnd();
void home()
//Roof
glBegin(GL_POLYGON);
glVertex2i(200, 500);
glVertex2i(600, 500);
glVertex2i(700, 350);
glVertex2i(300, 350);
glEnd();
glBegin(GL_TRIANGLES);
glVertex2i(200, 500);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
22
glutInitWindowPosition(100, 100);
glutInitWindowSize(800, 600);
init();
glutDisplayFunc(home);
glutMainLoop();
Ans.
#include <stdio.h>
#include <math.h>
#include <GL/glut.h>
FILE *fp;
23
float slopeinverse;
}EdgeBucket;
EdgeBucket buckets[maxVer];
}EdgeTableTuple;
// Scanline Function
void initEdgeTable()
int i;
EdgeTable[i].countEdgeBucket = 0;
ActiveEdgeTuple.countEdgeBucket = 0;
int j;
if (tup->countEdgeBucket)
printf("\nCount %d-----\n",tup->countEdgeBucket);
printf(" %d+%.2f+%.2f",
24
tup->buckets[j].ymax, tup->buckets[j].xofymin,tup->buckets[j].slopeinverse);
}}
void printTable()
int i,j;
if (EdgeTable[i].countEdgeBucket)
printTuple(&EdgeTable[i]);
int i,j;
EdgeBucket temp;
temp.ymax = ett->buckets[i].ymax;
temp.xofymin = ett->buckets[i].xofymin;
temp.slopeinverse = ett->buckets[i].slopeinverse;
j = i - 1;
j = j - 1;
25
}
(receiver->buckets[(receiver)->countEdgeBucket]).ymax = ym;
(receiver->buckets[(receiver)->countEdgeBucket]).xofymin = (float)xm;
(receiver->buckets[(receiver)->countEdgeBucket]).slopeinverse = slopInv;
insertionSort(receiver);
(receiver->countEdgeBucket)++;
{float m,minv;
if (x2==x1)
minv=0.000000;
else
m = ((float)(y2-y1))/((float)(x2-x1));
if (y2==y1)
26
return;
minv = (float)1.0/m;
if (y1>y2)
scanline=y2;
ymaxTS=y1;
xwithyminTS=x2;
else
scanline=y1;
ymaxTS=y2;
xwithyminTS=x1;
storeEdgeInTuple(&EdgeTable[scanline],ymaxTS,xwithyminTS,minv);
{int i,j;
if (Tup->buckets[i].ymax == yy)
printf("\nRemoved at %d",yy);
Tup->buckets[j].ymax =Tup->buckets[j+1].ymax;
27
Tup->buckets[j].xofymin =Tup->buckets[j+1].xofymin;
Tup->buckets[j].slopeinverse = Tup->buckets[j+1].slopeinverse;
Tup->countEdgeBucket--;
i--;
int i;
void ScanlineFill()
once.
28
// 1. Move from ET bucket y to the
storeEdgeInTuple(&ActiveEdgeTuple,EdgeTable[i].buckets[j].
ymax,EdgeTable[i].buckets[j].xofymin,
EdgeTable[i].buckets[j].slopeinverse);
printTuple(&ActiveEdgeTuple);
removeEdgeByYmax(&ActiveEdgeTuple, i);
insertionSort(&ActiveEdgeTuple);
printTuple(&ActiveEdgeTuple);
//3. Fill lines on scan line y by using pairs of x-coords from AET
j = 0;
FillFlag = 0;
coordCount = 0;
x1 = 0;
x2 = 0;
ymax1 = 0;
ymax2 = 0;
while (j<ActiveEdgeTuple.countEdgeBucket)
if (coordCount%2==0)
x1 = (int)(ActiveEdgeTuple.buckets[j].xofymin);
ymax1 = ActiveEdgeTuple.buckets[j].ymax;
29
if (x1==x2)
*/
if
(((x1==ymax1)&&(x2!=ymax2))||((x1!=ymax1)&&(x2==ymax2)))
x2 = x1;
ymax2 = ymax1;
}else
{coordCount++;
else
coordCount++;
else
x2 = (int)ActiveEdgeTuple.buckets[j].xofymin;
ymax2 = ActiveEdgeTuple.buckets[j].ymax;
FillFlag = 0;
if (x1==x2)
30
/*three cases can arive-
*/
if
(((x1==ymax1)&&(x2!=ymax2))||((x1!=ymax1)&&(x2==ymax2)))
x1 = x2;
ymax1 = ymax2;
else
coordCount++;
FillFlag = 1;
else
coordCount++;
FillFlag = 1;
if(FillFlag)
glColor3f(0.0f,0.7f,0.0f);
glBegin(GL_LINES);
glVertex2i(x1,i);
glVertex2i(x2,i);
31
glEnd();
glFlush();
j++;
updatexbyslopeinv(&ActiveEdgeTuple);
void myInit(void)
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,maxHt,0,maxWd);
glClear(GL_COLOR_BUFFER_BIT);
void drawPolyDino()
glColor3f(1.0f,0.0f,0.0f);
rewind(fp);
while(!feof(fp) )
count++;
if (count>2)
32
{
x1 = x2;
y1 = y2;
count=2;
if (count==1)
else
glBegin(GL_LINES);
glEnd();
glFlush();
}}}
void drawDino(void)
{initEdgeTable();
drawPolyDino();
printf("\nTable");
printTable();
fp=fopen ("PolyDino.txt","r");
33
if ( fp == NULL )
return;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(maxHt,maxWd);
glutInitWindowPosition(100, 150);
myInit();
glutDisplayFunc(drawDino);
glutMainLoop();
fclose(fp);
Output:-
Q4. Write a program in C/C++ to implement Cohen-Sutherland line clipping algorithm. In this
implementation consider two cases of a line: totally visible, totally invisible, against the rectangular
clipping window.
Ans.
34
#include <iostream>
code |= LEFT;
code |= RIGHT;
code |= BOTTOM;
code |= TOP;
return code;
35
}
while (true)
accept = true;
break;
// in same region
break;
else
// rectangle
36
int code_out;
double x, y;
if (code1 != 0)
code_out = code1;
else
code_out = code2;
// x = x1 + (1 / slope) * (y -y1)
y = y_max;
y = y_min;
x = x_max;
37
else if (code_out & LEFT)
x = x_min;
// by intersection point
if (code_out == code1)
x1 = x;
y1 = y;
else
x2 = x;
y2 = y;
if (accept)
<< y1 << " to "<< x2 << ", " << y2 << endl;
38
}
Else
// Driver code
int main()
cohenSutherlandClip(5, 5, 7, 7);
cohenSutherlandClip(1, 5, 4, 1);
return 0;
Output:-
Line rejected
39