Object Oriented Programming

Object Oriented Programming List
  1. ENUMERATION
  2. FUNCTION OVERLOADING
  3. SCOPE AND STORAGE CLASS
  4. STACK
  5. QUEUE
  6. CONSTRUCTOR AND DESTRUCTOR
  7. COPY CONSTRUCTOR
  8. CONSTRUCTOR OVERLOADING
  9. PARAMETERIZED CONSTRUCTOR
  10. STATIC MEMBER AND METHODS
  11. OVERLOADING BINARY OPERATORS
  12. OVERLOADING UNARY OPERATORS
  13. CREATION OF CLASSES
  14. INLINE FUNCTION
  15. VECTOR CONTAINER
  16. EXCEPTION HANDLING
  17. FUNCTION TEMPLATE
  18. ITERATORS
  19. SINGLE INHERITANCE
  20. MULTILEVEL INHERITANCE
  21. MULTIPLE INHERITANCE
  22. HYBRID INHERITANCE
  23. TEMPLATE CLASS
  24. VIRTUAL FUNCTION


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

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

ITERATORS



Program

#include
#include
using namespace std;
void main()
{
listl1;
listl2;
l1.push_back(10);
l1.push_back(50);
l1.push_back(30);

l2.push_back(22);
l2.push_back(60);
l2.push_back(11);
list::iterator p;
p=l1.begin();
l1.merge(l2);
l1.sort();
while(l1.size()>0)
{
int value=l1.front();
cout << value << endl;
l1.pop_front();
}

}


Output

10
11
22
30
50
60

Press any key to continue

MULTILEVEL INHERITANCE







Program

#include “iostream.h”
#include “conio.h”
class stu
{
protected:
char roll[20];
public:
void getdata();
void putdata();
};
class test:public stu
{
protected:
float sub1,sub2;
public:
void getmark();
void dismark();
};
class result:public test
{
float total;
public:
void display()
{
total=sub1+sub2;
putdata();
dismark();
cout << "\n\ntotal" <<>> roll;
}
void stu::putdata()
{
cout << "\n\n ROLL NUMBER:" <<>> sub1;
cout << "\n\n ENTER THE SUBJECT 2 MARK:"; cin >> sub2;
}
void test::dismark()
{
cout << "\n\n SUBJECT 1 MARK" << size="5">Output

ENTER THE ROLL NUMBER : 1234

ENTER THE SUBJECT 1 MARK : 89

ENTER THE SUBJECT 2 MARK :97

ROLL NUMBER :1234

SUBJECT 1 MARK :89

SUBJECT 2 MARK :97

TOTAL :186


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


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

MULTIPLE INHERITANCE






Program

#include “iostream.h”
#include “conio.h”
#include
const int max=50;
static int n;
class cust
{
public:
int cno[max];
char cname[max][15],cst[max][15],cares[max][15],ccity[max][15];
float camt[max];
void getdet();
};
class acc
{
protected:
int no;
float amt;
public:
void getamt();
};
class tran:public cust,public acc
{
public:
int op;
void tra();
void disp();
};
void cust::getdet()
{
for(int i=0;i<1;i++)>> cno[n];
cout << "\n enter the name"; cin >> cname[n];
camt[n]=0;
}
cout << "\n" <<>> no;
cout << "enter the amt:"; cin >> amt;
}
void tran::tra()
{
int op,c,i=0;
cout << "enter the transaction type:[1.credit][2.debit]"; cin >> op;
if(op==1)
{
getamt();
while(i < c="0;" op="="2)" c="1;" balance=" << camt[i]; break; } } if(c!=1) cout << " i="0;">> no;
cout << "\n customer details:"; while(i<=n) { if(cno[i]==no) { cout << "\n:" <<>> ch;
switch(ch)
{
case 1:
t.getdet();
break;
case 2:
t.tra();
break;
case 3:
t.disp();
break;
case 4:
break;
default:
cout << "invalid choice"; } } while(ch!=4); getch(); } Output


MULTIPLE INHERITANCE

1.create
2.transaction
3.display

Enter your choice:1

Enter the acc no: 1

Enter the name Lancy

1 record added

1.create
2.transaction
3.display

Enter your choice:2
Enter the transaction type:[1.credit][2.debit]1

Enter the acc no:1
Enter the amt:2500

1.create
2.transaction
3.display

Enter your choice:2
Enter the transaction type:[1.credit][2.debit]2

Enter the acc no:1
Enter the amt:100
Balance=2400

1.create
2.transaction
3.display

Enter your choice:3
Enter the accno:1

customer details:1
Name:Lancy
Balance:2400

1.create
2.transaction
3.display

Enter your choice:4




SINGLE INHERITANCE







Program

#include
#include “conio.h”
#include “iostream.h”
class base
{
public:
char nam[20],dofb[20];
float bp,gp;
void getdata();
};
class derived:public base
{
float da,hra,pf;
public:
void calculate();
void display();
};
void base::getdata()
{
cout << "\n\n\t enter the name:\t"; cin >> nam;
cout << "\n\n\t enter the date of birth:\t"; cin >> dofb;
cout << "\n\n\t enter the basic pay:\t"; cin >> bp;
}
void derived::calculate()
{
da=bp*0.12;
hra=bp*0.07;
pf=400;
gp=bp+da+hra+pf;
}
void derived::display()
{
cout << "\n\n\t NAME :\t" << size="5">Output

FRIEND FUNCTION

INPUT:

Enter the name :Lancy

Enter the date of birth :18-08-88

Enter the basic pay :25000


OUTPUT:

NAME :Lancy

DOB :18-08-88

BASIC PAY :25000

DA :3000

HRA :1750

PF :400

GROSS PAY :30150






TEMPLATE CLASS






Program

#include “iostream.h”
#include “conio.h”
template
class test
{
T1 a;
T2 b;
public:
test(T1 x,T2 y)
{
a=x;
b=y;
}
void show()
{
cout <<>
}
};
void main()
{
clrscr();
cout << "Template class\n";
testtest1(1.23,123);
testtest2(100,'w');
test1.show();
test2.show();
getch();
}

Output

Template class

1.23and123
100andw





VIRTUAL FUNCTION







Program:

#include “iostream.h”
#include “conio.h”
class Base
{
public:
void display()
{
cout << "display base"; } virtual void show() { cout << "\n show base"; } }; class Derived:public Base { public: void display() { cout << "\n display derived"; } void show() { cout << "\n show derived"; } }; void main() { clrscr(); Base B; Derived D; Base *bptr; cout << "\n bptr points to base \n"; bptr=&B; bptr->display();
bptr->show();
cout << "\n bptr points to derived \n"; bptr=&D; bptr->display();
bptr->show();
getch();
}

Output:

bptr points to base
display base
show base

bptr points to derived
display base
show derived




JAVA PROGRAMS

Page : 1 2 3 4 5


Mark List using array
Searching
Triangle Numbers
Type Conversion

Mark List using array

Student mark list

import java.io.*;

class stud
{
public static void main(String a[])
{
String nam,dep;
int m[]=new int[5];
int tot,avg,r,i;
try
{
int s[]=new int[20];
InputStreamReader ii;
BufferedReader br;
ii=new InputStreamReader(System.in);
br=new BufferedReader(ii);
System.out.println("Enter your name");
nam=br.readLine();
System.out.println("Enter the department name");
dep=br.readLine();
System.out.println("Enter the 3marks");
for(i=1;i < =3;i++) { m[i]=Integer.parseInt(br.readLine()); } tot=0; int t=0; for(i=1;i < =3;i++) { tot +=m[i]; if(m[i]>50)
t=1;
}
avg=tot/3;

System.out.println("Name="+nam);
System.out.println("Department="+dep);
for(i=1;i < =3;i++) System.out.println("M"+i+"="+m[i]); System.out.println("Total="+tot); System.out.println("Average="+avg); if (t==1) System.out.println("Result=Pass"); else System.out.println("Result=Fail"); } catch(IOException as) {} }} Output: Z:\java>java stud
Enter your name
Lakshmi
Enter the department name
MCA
Enter the 3marks
87
68
98
Name=Lakshmi
Department= MCA
M1=87
M2=68
M3=98
Total=253
Average=84
Result=Pass

Searching


import java.io.*;
class so
{
public static void main(String a[])
{
int i,j,k,n;
try
{
int s[]=new int[20];
InputStreamReader ii;
BufferedReader br;

ii=new InputStreamReader(System.in);
br=new BufferedReader(ii);
System.out.println("Enter the n value");
n=Integer.parseInt(br.readLine());
System.out.println("Enter the n number");
for(i=1;i < =n;i++) s[i]=Integer.parseInt(br.readLine()); for(i=1;i < =n;i++) for(j=1;j < =n;j++) if(s[i] < t="s[i];" k="Integer.parseInt(br.readLine());" i="1;i">javac so.java

c:\java>
c:\java>java so
Enter teh n value
5
Enter the n number
5
4
3
2
12
Enter search key
5
The value is found

Triangle Numbers



Triangle

class tr
{
public static void main(String args[])
{
int i,j,s;
s=1;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
System.out.print(s+++"\t");
System.out.println();
}
}
}

Type Conversion

Conversion

class conver
{
public static void main(String args[])
{
byte b;
int i=257;
double d=323.143;
b=(byte)i;
System.out.println("convert from int="+i+" to byte "+b);
i=(int)d;
System.out.println("convert from double="+d+" to int="+i);
b=(byte)d;
System.out.println("convert from double="+d+" to byte= "+b);
}
}

Database Connection



Step – III Connect Database

Step -1

Open Visual Basic 6.0 – Standard EXE Form



Step -2

Select Project from Tool Bar

1. Project

2. Components






Step -3

Select Microsoft ADO Data Control 6.0 (SP4)(OLEDB)

Click On Apply Button from Components Screen

ADODC Components will be Display on the ToolBox Left side on the VB Screen

Just Click On the ADODC Components and Track on the VB Form



Step - 4

Right Click on the ADODC Control and Click On ADODC Properties

Click On the Build Button



Select - Microsoft OLE DB Provider for ODBC Drivers

Click On the Next Button


Select Data Source Name
For example College


Type User Name : Scott

Type Password: Tiger

Click On Allow Saving Password (Check Box) and

Click on the Test Connection Button

Click on OK Button from Microsoft Data Link and

Click on OK Button from Data Link Properties


Data Source will be Connected


Select Record Source from Property Page

Select Command Type – 2 - adCmdTable

Select Table - Table Name ( for example ACCOUNT )

Click On Apply Button and

Click On the OK Button

















Step -II 3



Step 3



Type into Data Source Name Field (Data Source Name is user define Name)

Type into User Name Field (User Name is SCOTT )

Type into Server Field ( Server Name is ORAMCA)

Click On Ok Button

Click On OK Button

Step -II


Step 2


Select - Microsoft ODBC for Oracle

Then

Click On the Finish Button

Step 2


Step – II Do the following steps to Create Data Source

Step 1



Go to Start ,


Control Panel


Administrative Tools

Data Source (ODBC)


Click On Add Button

























Step to Create Database Connectivity

Previous Next


Database Connectivity

Step to create Data Base Connectivity (Visual Basic with Oracle)


Step-I

Create Table in Oracle

Step – II

Create Data Source

Step –III

Connect Database


Step –I Create Table in Oracle

Syntax


CREATE TABLE "table_name"("column 1" "data_type_for_column_1","column 2" "data_type_for_column_2",... )

So, if we are to create the Student table specified as above,

Example

CREATE TABLE student
(Name char(50),
reg_no number(10),
Address char(50),
City char(50),
Country char(25),
Birth_Date date)