Mouse Events in VB



Mouse Events

Screen Design






Source Code


Private Sub Form_Load()
Option1.Value = False
Option2.Value = False
ImgSun.Height = 900
ImgSun.Width = 1200

ImgWinter.Height = 900
ImgWinter.Width = 1200


End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Option1 = True Then
ImgSun.Move X, Y
Else
ImgWinter.Move X, Y
End If



End Sub







Key Board Events in VB

Key Board Events

Source Code and Screen Design


Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 38 Then
MsgBox ("The UP Arrow was Pressed")
End If
End Sub



Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 40 Then
MsgBox ("The DOWN Arrow was Pressed")
ElseIf KeyCode = 37 Then
MsgBox ("The LEFT Arrow was Pressed")
ElseIf KeyCode = 39 Then
MsgBox ("The RIGHT Arrow was Pressed")
End If
End Sub







Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text1.SetFocus
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

Dim Mychar As String
Mychar = Text1.Text
Text1.Text = Mychar

MsgBox "You Have Pressed " & Mychar & Asc(Mychar)
Text1.Text = ""

End Sub







DCL Commands


DATA CONTROL COMMANDS

CREATE TABLE


SYNTAX


CREATE TABLE (column definition1, column definition2);

Example


SQL> create table gemployee(name varchar2(10),id varchar2(10),address varchar2(19),post varchar2(20),salary number(6,2));
Table created.


SQL> DESC GEMPLOYEE;


Name Null? Type
----------------------------------------- -------- ----------------------------
NAME VARCHAR2(10)
ID VARCHAR2(10)
ADDRESS VARCHAR2(19)
POST VARCHAR2(20)
SALARY NUMBER(5)

INSERT VALUES


SYNTAX


INSERT INTO table_name(column1,column2….)VALUES (value1,value2..);

Example


SQL> insert into gemployee values('&name','&id','&address','&post','&salary');
Enter value for name: siva
Enter value for id: 5
Enter value for address: mainroad
Enter value for post: manager
Enter value for salary: 2000
old 1: insert into gemployee values('&name','&id','&address','&post','&salary')
new 1: insert into gemployee values('siva','5','mainroad','manager','2000')
1 row created.

SQL> insert into gemployee values('&name','&id','&address','&post','&salary');
Enter value for name: rose
Enter value for id: 67
Enter value for address: weststreet
Enter value for post: clerk
Enter value for salary: 500
old 1: insert into gemployee values('&name','&id','&address','&post','&salary')
new 1: insert into gemployee values('rose','67','weststreet','clerk','500')
1 row created.

SQL> insert into gemployee values('&name','&id','&address','&post','&salary');
Enter value for name: anvitha
Enter value for id: 56
Enter value for address: eaststreet
Enter value for post: assistant
Enter value for salary: 200
old 1: insert into gemployee values('&name','&id','&address','&post','&salary')
new 1: insert into gemployee values('anvitha','56','eaststreet','assistant','200')
1 row created.

SQL> SELECT * FROM GEMPLOYEE;


NAME ID ADDRESS POST SALARY
--------- - ---------- ------------------- -------------------- ---------- ----------
siva 5 mainroad manager 2000
rose 67 weststreet clerk 500
anvitha 56 eaststreet assistant 200

GRANT


SYNTAX
GRANT privilege_name ON object_name TO {user_namepublicrole_name};

Example


SQL> grant all on gemployee to system;
Grant succeeded.

REVOKE


SYNTAX


REVOKE privilege_name ON object_name FROM {user_namepublicrole_name};

Example

SQL> revoke select on gemployee from system;
Revoke succeeded.

TRIGGERS


ORACLE OR SQL SERVER TRIGGERS


CREATE TABLE


SYNTAX


CREATE TABLE (column definition1, column definition2);

Example


SQL> create table it_file(itemcode number(6),qty_hand number(5));
Table created.


INSERT VALUES


SYNTAX


INSERT INTO table_name(column1,column2….)VALUES (value1,value2..);

Example

SQL> insert into it_file values(1201,200);
1 row created.


CREATE TRIGGER


SYNTAX

CREATE OR REPLACE trigger
[befor/after][insert/update/delete]on
{referencing/old [as] old/new}
[for each statement/for each row][when ]
PI/SQL_block

Example


SQL> create trigger fff
2 before update on it_file for each row
3 begin
4 if:new.qty_hand<:old.qty_hand then
5 raise_application_error(-20001,'quantity on hand is less');
6 end if;
7 end;
8 /
Trigger created.


UPDATE


SQL> update it_file set qty_hand=qty_hand+200 where itemcode='1201';
1 row updated.

SQL> update it_file set qty_hand=qty_hand-200 where itemcode='1201';
update it_file set qty_hand=qty_hand-200 where itemcode='1201'
*
ERROR at line 1:
ORA-20001: quantity on hand is less
ORA-06512: at "SCOTT.FFF", line 3
ORA-04088: error during execution of trigger 'SCOTT.FFF'

Design and Analysis Algorithms Lab

Program List


Quick Sort
Binary Search
Binary Tree Traversal
Prim's Algorithm
Strassen's Matrix Multiplication
Dijkstra's Algorithm
Knapsack Problem
Subset Sum Problem
Travelling Salesman Problem
Warshall's Algorithm











1 2 3 4 5 6 7 8 9 10

Quick Sort




SOURCE CODE


#include”stdio.h”
#include”iostream.h”
#include”conio.h”
#include”iomanip.h”

class quick
{
private:
int elements[20],maxsize;
public:
void quicksort(int elements[20],int maxsize);
void sort(int elements[20],int left,int right);
};

void main()
{
int i,maxsize,elements[20];
clrscr();
cout < < "Enter The Number Of Elements : "; cin > > maxsize;
for(i=0;i <> > elements[i];
}
cout < < "Array Before Sorting \n"; cout < < "INDEX \t ELEMENT \n"; for(i=0;i < i="0;i" l="left;" r="right;" pivot="elements[left];"> =pivot)&&(left < pivot="left;" left="l;" right="r;"> pivot)
sort(elements,pivot+1,right);
}



Binary Search






SOURCE CODE



#include”iostream.h”
#include”conio.h”

void binsearch(int ar[],int size,int ele)
{
int lb=0,ub=size-1,mid;
for(;lb < =ub;) { mid=(lb+ub)/2; if(ar[mid]==ele) { cout < < "\n SEARCH SUCCESSFULL"; break; } else if(ar[mid] < lb="mid+1;" ub="mid-1;" i="0;i" j="i+1;j"> ar[j])
{
temp=ar[i];
ar[i]=ar[j];
ar[j]=temp;
}
}

void display(int ar[],int size)
{
cout < < "\n The Elements In Sorted Order Is \n"; for(int i=0;i < i="0;i"> > ar[i];
}
void main()
{
clrscr();
int size;
cout < < "Enter The Number Of Elements : "; cin > > size;
int *ar=new int(size);
cout < < "\n Enter The Elements Of The Array \n"; input(ar,size); sort(ar,size); int ele; display(ar,size); cout < < "\n Enter The Element To Be Found: "; cin > > ele;
binsearch(ar,size,ele);
getch();
}




OUTPUT


Enter The Number Of Elements : 5
Enter The Elements Of The Array
2
4
6
3
1

The Elements In Sorted Order Is
1
2
3
4
6
Enter The Element To Be Found: 1
SEARCH SUCCESSFULL

Binary Tree Traversal





SOURCE CODE



#include”iostream.h”
#include”conio.h”
#include”stdio.h”
#include <>

struct node
{
int data;
node *left;
node *right;
};

node *tree=NULL;
node *insert(node *tree,int ele);
void preorder(node *tree);
void inorder(node *tree);
void postorder(node *tree);

void main()
{
clrscr();
int ch,ele;
do
{
clrscr();
cout < < "\n\t 1.INSERT A NODE IN BINARY TREE "; cout < < "\n\t 2.PREORDER TRAVERSAL"; cout < < "\n\t 3.INORDER TRAVERSAL"; cout < < "\n\t 4.POSTORDER TRAVERSAL "; cout < < "\n\t 5.EXIT"; cout < < "\n\n\t ENTER YOUR CHOICE: "; cin > > ch;

switch(ch)
{
case 1:
cout < < "\t ENTER THE ELEMENT: "; cin > > ele;
tree=insert(tree,ele);
break;

case 2:
cout < < "\n\t PREORDER TRAVERSAL \n"; preorder(tree); break; case 3: cout < < "\n\t INORDER TRAVERSAL \n"; inorder(tree); break; case 4: cout < < "\n\t POSTORDER TRAVERSAL \n"; postorder(tree); break; case 5: exit(0); } }while(ch!=5); } node *insert(node *tree,int ele) { static count=1; if(tree==NULL) { tree=new node; tree- > left=tree- > right=NULL;
tree- > data=ele;
count++;
}
else
{
if(count%2==0)
tree- > left=insert(tree- > left,ele);
else
tree- > right=insert(tree- > right,ele);
}
return (tree);
}

void preorder(node *tree)
{
if(tree!=NULL)
{
cout < < "\n " < <> data;
preorder(tree- > left);
preorder(tree- > right);
getch();
}
}

void inorder(node *tree)
{
if(tree!=NULL)
{
inorder(tree- > left);
cout < < "\n " < <> data;
inorder(tree- > right);
getch();
}
}

void postorder(node *tree)
{
if(tree!=NULL)
{
postorder(tree- > left);
postorder(tree- > right);
cout < < "\n " < <> data;
getch();
}
}














OUTPUT:
1.INSERT A NODE IN BINARY TREE
2.PREORDER TRAVERSAL
3.INORDER TRAVERSAL
4.POSTORDER TRAVERSAL
5.EXIT
ENTER YOUR CHOICE: 1
ENTER THE ELEMENT: 4

1.INSERT A NODE IN BINARY TREE
2.PREORDER TRAVERSAL
3.INORDER TRAVERSAL
4.POSTORDER TRAVERSAL
5.EXIT
ENTER YOUR CHOICE: 1
ENTER THE ELEMENT: 3

1.INSERT A NODE IN BINARY TREE
2.PREORDER TRAVERSAL
3.INORDER TRAVERSAL
4.POSTORDER TRAVERSAL
5.EXIT
ENTER YOUR CHOICE: 1
ENTER THE ELEMENT: 5

1.INSERT A NODE IN BINARY TREE
2.PREORDER TRAVERSAL
3.INORDER TRAVERSAL
4.POSTORDER TRAVERSAL
5.EXIT
ENTER YOUR CHOICE: 2
PREORDER TRAVERSAL

4
3
5

1.INSERT A NODE IN BINARY TREE
2.PREORDER TRAVERSAL
3.INORDER TRAVERSAL
4.POSTORDER TRAVERSAL
5.EXIT
ENTER YOUR CHOICE: 3
INORDER TRAVERSAL
3
4
5



1.INSERT A NODE IN BINARY TREE
2.PREORDER TRAVERSAL
3.INORDER TRAVERSAL
4.POSTORDER TRAVERSAL
5.EXIT
ENTER YOUR CHOICE: 4
POSTORDER TRAVERSAL
3
5
4




Prim's Algorithm

Page 1 2 3 4 5 6 7 8 9 10




SOURCE CODE



#include”iostream.h”
#include”stdio.h”
#include”conio.h”
#include”iomanip.h”
#define INFINITY 32767

class graph
{
char vertex[15],path[15];
int visited[15],w[15][15],dist[15],i,j,k,d;
public:
graph(int);
void create(int);
void spantree(int);
};
graph::graph(int n)
{
for(i=1;i < =n;i++) { path[i]=0; dist[i]=INFINITY; } } void graph::create(int v) { int n; char m; for(i=1;i < =v;i++) { cin > > vertex[i];
visited[i]=0;
for(j=1;j < =v;j++) w[i][j]=0; } for(i=1;i < =v;i++) { cout < < "\n No Of Adjecency For " < <> > n;
for(j=1;j < =n;j++) { cout < < "Adjecency " < <> > m;
cout < < "Distance Is : "; cin > > d;
for(k=1;k < =v;k++) { if(vertex[k]==m) w[i][k]=d; } } } for(i=1;i < =v;i++) { for(j=1;j < =v;j++) cout < < count="0;"> > source;
for(i=1;i < =n&&vertex[i]!=source;i++) if(i < i="1;i" dec="i;" i="1;i" min="INFINITY;" i="1;i" min="dist[i];" dec="i;" i="1;i" j="1;j" i="1;i"> > ch;
if(ch=='y'ch=='Y')
{
for(i=1;i < =n;i++) { visited[i]=0; dist[i]=INFINITY; path[i]=0; } count=0; goto source; } } void main() { int n; clrscr(); cout < < "\n Enter The Number Of Nodes: "; cin > > n;
graph x(n);
cout < < "\n Enter The Vertex' One By One: \n"; x.create(n); x.spantree(n); getch(); }

Strassen's Matrix Multiplication


Page 1 2 3 4 5 6 7 8 9 10







SOURCE CODE

#include”iostream.h”
#include”conio.h”

class smm{
int a[2][2],b[2][2],c[2][2];
public:
void smm1();
void strmatmul();
};

void smm::smm1()
{
int i,j;
cout < < "Enter The Values Of A Matrix \n"; for(i=0;i < j="0;j"> > a[i][j];
cout < < "Enter The Values For B Matrix \n"; for(i=0;i < j="0;j"> > b[i][j];
}

void smm::strmatmul()
{
int m[25]={0},i,j;

m[1]=(a[0][0]+a[1][1])*(b[0][0]+b[1][1]);
m[2]=(a[1][0]+a[1][1])*b[0][0];
m[3]=a[0][0]*(b[0][1]-b[1][1]);
m[4]=a[1][1]*(b[1][0]-b[0][0]);
m[5]=(a[0][0]+a[0][1])*b[1][1];
m[6]=(a[1][0]-a[0][0])*(b[0][0]+b[0][1]);
m[7]=(a[0][1]-a[1][1])*(b[1][0]+b[1][1]);

c[0][0]=m[1]+m[4]-m[5]+m[7];
c[0][1]=m[3]+m[5];
c[1][0]=m[2]+m[4];
c[1][1]=m[1]+m[3]-m[2]+m[6];


cout < < "\n STRASSEN'S MATRIX MULTIPLICATION \n"; for(i=0;i < j="0;j">


Dijkstra's Algorithm




SOURCE CODE


#include”iostream.h”
#include”conio.h”
#include”iomanip.h”
#define MAX 10

class dijkstra
{
private:
int cost[MAX][MAX],d[MAX],p[MAX],visited[MAX],n;
public:
void readmatrix();
void shortpath(int);
void display(int);
};

void dijkstra::readmatrix()
{
int i,j;
cout < < "Enter The Number Of Vertices : "; cin > > n;
cout < < "Enter The Cost Matrix Of The Graph: "; for(i=1;i < =n;i++) for(j=1;j < =n;j++) cin > > cost[i][j];
}
void dijkstra::shortpath(int src)
{
int i,j,min,u,v;
for(i=1;i < =n;i++) { d[i]=cost[src][i]; visited[i]=0; p[i]=src; } visited[src]=1; for(i=1;i < =n;i++) { min=999; u=0; for(j=1;j < =n;j++) { if((!visited[j])&&(d[j]!=0)) if(d[j] < min="d[j];" u="j;" v="1;v" i="1;i" i="="src)" k="i;" k="p[k];"> > source;
dij.shortpath(source);
dij.display(source);
getch();
return 0;
}

Knapsack Problem






SOURCE CODE

#include”iostream.h”
#include”stdio.h”
#include”conio.h”
void knapsack(int n,int w);
int n,i,w,W;
int weight[50],v[50],item[10];
int C[50][50];
void main()
{
clrscr();
cout < < "Enter The Number Of Items: ";
cin > > n;
cout < < "Enter capacity : ";
cin > > W;
cout < < "Enter Weights: ";
for(i=1;i < =n;i++)
cin > > weight[i];
cout < < "Enter Values \n";
for(i=1;i < =n;i++)
{
item[i]=0;
cin > > v[i];
}
knapsack(n,w);
getch();
}

void knapsack(int n,int w)
{
for(int c=0;c < =W;c++)
C[0][c]=0;
for(i=0;i < =n;i++)
C[i][0]=0;
for(i=1;i < =n;i++)
{
for(w=1;w < =n+1;w++)
if(weight[i] < =w)
if(v[i]+C[i-1][w-weight[i]] > C[i-1][w])
{
C[i][w]=v[i]+C[i-1][w-weight[i]];
item[i]=1;
}
else
C[i][w]=C[i-1][w];
else
C[i][w]=C[i-1][w];
}
for(i=0;i < =n;i++)
{
cout < < "\n";
for(w=0;w < =W;w++)
cout < < C[i][w] < < "\t";
}
cout < < "\n";
}

Subset Sum Problem

Page 1 2 3 4 5 6 7 8 9 10


SOURCE CODE


#include”iostream.h”
#include”conio.h”
#include <>
#define MAX 10

class subset
{
private:
int n,exsetsum,set[MAX],selected[MAX];
public:
void readset();
void setsum();
};

void subset::readset()
{
int i;
cout < < "Enter the Number Of Elements In The Set : "; cin > > n;
cout < < "\n Enter The Elements Of The Set \n"; for(i=1;i < =n;i++) cin > > set[i];
cout < < "\n Enter The Expected Sum Of Subset : "; cin > > exsetsum;
}
void subset::setsum()
{
int i,j,no,sum,k,s;
no=pow(2,n);
cout < < "\n All Possible Subsets Whose Sums Is Equal Is " < < i="1;i" s="i;" sum="0;" j="1;j" k="1;"> 0)
{
if(s%2)
{
sum+=set[k];
selected[k]=1;
}
s=s/2;
k++;
}

if(sum==exsetsum)
{
for(j=1;j < =n;j++) if(selected[j]) cout < <>


Travelling Salesman Problem




SOURCE CODE

#include”iostream.h”
#include”conio.h”
int a[10][10],visited[10],cost=0,n,min1;
void mincost(int city);
int least(int c)
{
int i,nc=999,min=999;
for(i=1;i < =n;i++) { if((a[c][i]!=0)&&(visited[i]==0)) if(a[c][i] < min="a[i][0]+a[c][i];" nc="i;" min1="a[c][i];" cost="min1;"> ";
ncity=least(city);
if(ncity==999)
{
ncity=0;
cout < <> > n;
cout < < "Enter The Cost Matrix \n"; for(i=0;i < j="0;j"> > a[i][j];
visited[i]=0;
}
}
cout < < "\n\n Starting From The City: "; mincost(0); cout < < "\n Minimum Cost Is :\t " < <>

Warshall's Algorithm



SOURCE CODE



#include”iostream.h”
#include”conio.h”
#include”stdio.h”
#include <>
#define INFINITY 32768

class path
{
int n;
int p[10][10];
int p1[10][10];
int a[10][10];
int c[10][10];
public:
void get();
void pm();
void ap();
void disp();
};
void path::get()
{
int i,j,k;
clrscr();
cout < < "Enter The Number Of Vertices: "; cin > > n;
cout < < "Enter The Adjacency Matrix \n"; for(i=1;i < =n;i++) { for(j=1;j < =n;j++) { cout < < "a[" < <> > a[i][j];
p[i][j]=0;
}
}
cout < < "Enter The Cost Matrix \n"; for(i=1;i < =n;i++) { for(j=1;j < =n;j++) { cin > > c[i][j];
}
}
for(i=1;i < =n;i++) { for(j=1;j < =n;j++) { p[i][j]=a[i][j]; } } } void path::disp() { for(int i=1;i < =n;i++) { for(int j=1;j < =n;j++) { cout < < k="1;k" i="1;i" j="1;j" i="1;i" j="1;j" k="1;k" i="1;i" j="1;j">

ENUMERATION




SOURCE CODE

#include “iostream.h”
#include “conio.h”

enum day{MONDAY=1,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY,SUNDAY};

int main()
{
int day;
clrscr();
cout << "Enter The Day Number : "; cin >> day;
if((day==SATURDAY)(day==SUNDAY))
cout << "WEEKEND"; else if((day > =MONDAY)(day < =FRIDAY)) cout << "WORKING DAY"; else cout << "INVALID NUMBER"; getch(); return 0; } OUTPUT


Enter The Day Number : 2
WORKING DAY

Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

FUNCTION OVERLOADING






SOURCE CODE

#include “iostream.h”
#include “conio.h”
#include
#define PI 3.141

class shape
{
public:
void volume(int);
void volume(int,float);
void volume(int,float,double);
};

void shape::volume(int r)
{
int vol=pow(r,3);
cout << "Volume Of Cube Is: " << vol="PI*r*h;" vol="l*b*h;">> r;
s.volume(r);
cout << "Enter The Value Of r,h: "; cin >> r >> h;
s.volume(r,h);
cout << "Enter The Value Of l,b,h: "; cin >> l >> b >> h;
s.volume(l,b,h);
getch();
}

OUTPUT


Enter The Value Of r: 3
Volume Of Cube Is: 27

Enter The Value Of r,h: 2
9.5
Volume Of Cylinder Is: 59.679001

Enter The Value Of l,b,h: 2
7.9
23.9
Area Of Rectangle Is: 377.619999


SCOPE AND STORAGE CLASS





SOURCE CODE

#include “iostream.h”
#include “conio.h”
#include

extern i=10;

class var
{
public:
void first();
void second();
};

void main()
{
clrscr();

var v;
v.first();
v.first();
v.second();
getch();
}

void var::first()
{
static int s=1;
auto int a=20;
register int r=30;
cout << "i= " << s= " << s << endl << " a= " << a << endl << " r= " << r << endl << endl; i++; s++; a++; r++; } void var::second() { int n=5; cout << ">0)
{
int n=1;
cout << "Value Of n Inside The Block Is " << size="4">OUTPUT
i= 10
s= 1
a= 20
r= 30

i= 11
s= 2
a= 20
r= 30

Value Of n Outside The Block Is 5
Value Of n Inside The Block Is 1
Value Of n Outside The Block Is 6




STACK



IMPLEMENTATION OF ADT - STACK

SOURCE CODE:

#include “iostream.h”
#include “conio.h”

class stack
{
public:
int top,ele,s[20];
stack();
void push();
void pop();
void list();
void display();
};

stack::stack()
{
top=0;
}

void stack::push()
{
clrscr();
cout << "PUSH OPERATION \n"; if(top==10) cout << "The Stack Is Full"; else { cout << "Enter The Number Of Elements To Be Entered : "; int m; cin >> m;
cout << "Enter The Elements \n"; for(int i=0;i> ele;
s[top]=ele;
top=top+1;
}
display();
}
}


void stack::pop()
{
clrscr();
cout << "POP OPERATION \n"; if(top==0) cout << "The Stack Is Empty"; else { top=top-1; cout << "The Popped Element Is : " << top="=" i="0;i" x="stack();">> ch;
switch(ch)
{
case 1:
x.push();
break;
case 2:
x.pop();
break;
case 3:
x.list();
break;
default:
cout << "Your Choice Is Wrong"; } cout << "Do You Want To Continue? "; cin >> c;
}while(c='Y'c='y');
}

OUTPUT


STACK OPERATION
MENU
1.PUSH
2.POP
3.LIST
Enter Your Choice : 1
PUSH OPERATION
Enter The Number Of Elements To Be Entered : 4
Enter The Elements
1
2
3
4
The Elements Are
1
2
3
4
Do You Want To Continue? Y
STACK OPERATION
MENU
1.PUSH
2.POP
3.LIST
Enter Your Choice : 2
POP OPERATION
The Popped Element Is : 4
The Index Of The Popped Element Is : 3
The Elements Are
1
2
3
Do You Want To Continue? Y
STACK OPERATION
MENU
1.PUSH
2.POP
3.LIST
Enter Your Choice : 3
LIST OPERATION
The Elements Are
1
2
3
Do You Want To Continue? N



QUEUE





IMPLEMENTATION OF ADT - QUEUE

SOURCE CODE

#include “iostream.h”
#include “conio.h”
#include

class queue
{
public:
int queue1[5],rear,front;
void display();

queue()
{
rear=-1;
front=-1;
}

void insert(int x)
{
if(rear>4)
{
cout << "Queue Overflow"; front=rear=-1; return; } queue1[++rear]=x; cout << "Inserted " << front="="rear)" rear="="front)" i="front+1;i<="rear;i++)">> ch;
switch(ch)
{
case 1:
cout << "Enter The Element : "; cin >> ch;
qu.insert(ch);
break;
case 2:
qu.delet();
break;
case 3:
qu.display();
break;
case 4:
exit(0);
}
}
}



OUTPUT


MAIN MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice : 1
Enter The Element : 1
Inserted 1
MAIN MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice : 1
Enter The Element : 2
Inserted 2
MAIN MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice : 1
Enter The Element : 3
Inserted 3
MAIN MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice : 3
1 2 3
MAIN MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice : 2
Deleted 1
MAIN MENU
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice : 4



CONSTRUCTOR AND DESTRUCTOR






DEFINE AND USE THE CONSTRUCTOR AND DESTRUCTOR

SOURCE CODE

#include “iostream.h”
#include “conio.h”

class myclass{
int a,b;
public:
myclass();
~myclass();
void show();
};

myclass::myclass()
{
cout << "\n Constructor \n"; a=10; b=20; } myclass::~myclass() { cout << "\n Destructing… \n"; } void myclass::show() { cout << "\n A= " << b= " << b; cout << " size="4">OUTPUT


Constructor
A= 10
B= 20
Sum Is 30
Destructing…



COPY CONSTRUCTOR






SOURCE CODE

#include “iostream.h”
#include “conio.h”

class code
{
int id;
public:
code()
{
}
code(int a)
{
id=a;
}
code(code &x)
{
id=x.id;
}
void display(void)
{
cout << c="a;" d="a;">OUTPUT
ID Of A: 100
ID Of B: 100
ID Of C: 100
ID Of D: 100

Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24


CONSTRUCTOR OVERLOADING






SOURCE CODE

#include “iostream.h”
#include “conio.h”

class add
{
private:
int inum1,inum2,inum3;
public:
add(void);
add(int,int);
void input(int,int);
void sum(void);
void disp(void);
};

add::add(void)
{
inum1=inum2=inum3=0;
}

add::add(int ix,int iy)
{
inum1=ix;
inum2=iy;
inum3=0;
}

void add::input(int ivar1,int ivar2)
{
inum1=ivar1;
inum2=ivar2;
}

void add::sum(void)
{
inum3=inum1+inum2;
}

void add::disp(void)
{
cout << "\n The Sum Of Three Numbers Is " << aptr="new"> sum();
aptr-> disp();
a2.disp();
getch();
}


OUTPUT


The Sum Of Three Numbers Is 13
The Sum Of Three Numbers Is 7

Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

PARAMETERIZED CONSTRUCTOR






SOURCE CODE

#include “iostream.h”
#include “conio.h”

class con
{
int c;
public:
con();
con(int x);
con(int x,int y);
con(int x,int y,int z);
};

con::con()
{
c=0;
cout << "\n Result Is " << c="x*x;" c="x*y;" c="x*y*z;" size="4">OUTPUT


Result Is 0
Result Is 9
Result Is 15
Result Is 12





STATIC MEMBER AND METHODS










SOURCE CODE

#include “iostream.h”
#include “conio.h”
class test
{
int code;
static int count;
public:
void setcode(void)
{
code=++count;
}
void showcode(void)
{
cout << "Object Number " <<>
} static void showcount(void)
{ cout << "count " <<>
}
};
int test::count; int main()
{ clrscr();
test t1,t2;
t1.setcode();
t2.setcode();
test::showcount();
test t3;
t3.setcode();
test::showcount();
t1.showcode();
t2.showcode();
t3.showcode();
getch();
return 0;
}

OUTPUT

count 2
count 3
Object Number 1
Object Number 2
Object Number 3




OVERLOADING BINARY OPERATORS




OVERLOADING BINARY OPERATORS USING FRIEND FUNCTION

SOURCE CODE


#include “iostream.h”
#include
#include “conio.h”

class sample
{
int weight,height;
public:
void show();
sample()
{
};

sample(int w,int h);
friend sample operator+(sample &s1,sample &s2);
friend sample operator-(sample &s1,sample &s2);
friend sample operator*(sample &s1,sample &s2);
friend sample operator/(sample &s1,sample &s2);
friend sample operator%(sample &s1,sample &s2);
};

sample::sample(int w,int h)
{
weight=w;
height=h;
}

void sample::show()
{
cout << "\n The Weight Is " << weight="s1.weight+s2.weight;" height="s1.height+s2.height;" weight="s1.weight-s2.weight;" height="s1.height-s2.height;" weight="s1.weight*s2.weight;" height="s1.height*s2.height;" weight="s1.weight/s2.weight;" height="s1.height/s2.height;" weight="s1.weight%s2.weight;" height="s1.height%s2.height;" s3="s1+s2;" s4="s1-s2;" s5="s1*s2;" s6="s1/s2;" s7="s1%s2;" size="5">OUTPUT
Overloading All Binary Operators

Overloading + Operator
The Weight Is 150
The Height Is 150

Overloading - Operator
The Weight Is 50
The Height Is 50

Overloading * Operator
The Weight Is 5000
The Height Is 5000

Overloading / Operator
The Weight Is 2
The Height Is 2

Overloading % Operator
The Weight Is 0
The Height Is 0




OVERLOADING UNARY OPERATORS

OVERLOADING UNARY OPERATORS USING FRIEND FUNCTION


SOURCE CODE

#include “iostream.h”
#include “conio.h”

class unary_opr
{
int num;
public:
unary_opr()
{
num=0;
};
unary_opr(int a)
{
num=a;
}
friend unary_opr operator++(unary_opr);
friend unary_opr operator++(unary_opr,int);
friend unary_opr operator--(unary_opr);
friend unary_opr operator--(unary_opr,int);

void display()
{
cout << "\n The Result Is " << num="++s1.num;" num="s1.num++;" num="--s1.num;" num="s1.num--;" b2="++b1;" b2="b1++;" b3="--b1;" b4="b1--;" size="5">OUTPUT

PREFIX
The Result Is 3
POSTFIX
The Result Is 2
PREFIX
The Result Is 1
POSTFIX
The Result Is 2






CREATION OF CLASSES


SOURCE CODE

#include “iostream.h”
#include “conio.h”

class mod
{
int a,b,c;
public:
void getdata();
void display();
};

void mod::getdata()
{
cout << "Enter The Values Of a and b: ";
cin >> a >> b;
}

void mod::display()
{
c=a%b;
cout << "Result Is " << c;
}

void main()
{
mod d;
clrscr();
d.getdata();
d.display();
getch();
}



OUTPUT


Enter The Values Of a and b: 5
2
Result Is 1

INLINE FUNCTION


SOURCE CODE

#include “iostream.h”
#include “conio.h”

inline int big(int a,int b,int c)
{
if((a>b)&&(a>c))
return (a);
if((b>a)&&(b>c))
return (c);
if((c>a)&&(c>b))
return (c);
else
return (0);
}

void main()
{
int x,y,z,r;
char ch;
clrscr();
lable:
cout << "Enter The Value For x,y,z \n"; cin >> x >> y >> z;
r=big(x,y,z);
if(r!=0)
cout << "Biggest Number Is " <<>> ch;
if((ch=='Y')(ch=='y'))
goto lable;
getch();
}








OUTPUT


Enter The Value For x,y,z
12
54
34
Biggest Number Is 34
Do You Want To Continue? n




VECTOR CONTAINER







Program

#include "iostream.h"
#include "conio.h"
#include "stdlib.h"
using namespace std;
void display(vector &v)
{
for(int i=0;i<> v;
cout << "Initial size =" << i="0;i<5;i++)">> x;
v.push_back(x);
}
cout << "size after adding 5 values:"; cout << nsize =" << v.size() << ">::iterator itr=v.begin();
itr=itr+3;
v.insert(itr,1,9);
cout << "\n contents after inserting\n"; display(v); v.erase(v.begin()+3,v.begin()+5); cout << "contents after deletion:\n"; display(v); cout << "end\n"; return 0; } Output

Initial size =0
Enter five integer values:
1
2
3
4
5

size after adding 5 values:5

current contents:
1 2 3 4 5

size =6

contents now
1 2 3 4 5 6

contents after inserting
1 2 3 9 4 5 6

contents after deletion:
1 2 3 5 6

end
Press any key to continue




EXCEPTION HANDLING





Program

#include "iostream.h"
#include "conio.h"
using namespace std;
double divide(double a,double b)
{
try
{
if(!b) throw(b);
}
catch(double)
{
cout << "cannot divide by zero"; exit(1);

} return a/b;
}
int main() { cout << size="5">
Output

4
cannot divide by zero

Press any key to continue



FUNCTION TEMPLATE








Program

#include “iostream.h”
#include “conio.h”
template <>
void sort(type1 x[],type2 y)
{
type1 t;
type2 i,j;
for(i=0;i < j="0;j">=x[j+1])
{
t=x[j];
x[j]=x[j+1];
x[j+1]=t;
}
}
}
for(i=0;i <>> n;
cout < < "\n Enter " < < i="0;i">> d[i];
cout < < "\n Enter " < < i="0;i">> a[i];
cout < < "\n Enter " < < i="0;i">> c[i];
cout < < "\n\t After sorting"; cout < < "\n Float values:"; sort(d,n); cout < < "\n Integer values:"; sort(a,n); cout < < "\n Character values:"; sort(c,n); } Output

FUNCTION TEMPLATE
-----------------

INPUT
*****
Enter the values:3

Enter 3 float values:3.3 2.2 1.1

Enter 3 integer values:9 3 1

Enter 3 character values:s k e

After sorting

Float values: 1.1 2.2 3.3
Integer values: 1 3 9
Character values: e k s




HYBRID INHERITANCE







Program

#include “iostream.h”
#include “conio.h”
class student
{
protected:
int rno;
public:
void getnumber(int a)
{
rno=a;
}
void putnumber()
{
cout << "\n\nRNO:" << p1="x;" p2="y;" score="s;" total="p1+p2+score;" score=" << total; } void main() { result s1; clrscr(); cout << ">
}


Output

HYBRID FUNCTION

RNO:11

MARKS OBTAINED
PART1 83.5
PART2 77.5
sports
Total score = 186.300003

Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24