Sunteți pe pagina 1din 111

INDEX

C++
EX.NO

DATE

EXPERIMENT NAME

Program to illustrate working with objects

Program to illustrate working with array


objects

Program to illustrate function overloading

Program to illustrate constuctor and destructor

Program to illustrate default arguments

Program to illustrate dynamic memory


allocation

Program to illustrate reference parameters

Program to illustrate templates using genetic


sort

Program to illustrate operator overloading

10

Program to illustrate private inheritance

11

Program to illustrate object slicing

12

Program to illustrate virtual destructor

13

Program to illustrate function overriding

14

Program to illustrate read and write in a file

15

Program to illustrate mathematical operation

16

Program to illustrate static data members

17

Program to illustrate friend function

18

Program to illustrate number to word


convertion

PAGE NO.

SIGNATURE

19

Program to illustrate public inheritance

20

Program to illustrate copy constructor

21

Program to illustrate graphics

22

Program to illustrate abstract class

23

Program to illustrate generation of calendar

24

Program to illustrate standard template library

25

Program to illustrate exception handling

26

Program to illustrate counting number of


words in a given file

JAVA
EX.NO

DATE

EXPERIMENT NAME

27

Program to illustrate simple class design in


java

28

Program to illustrate interface

29

Program to illustrate single inheritance

30

Program to illustrate multilevel inheritance

31

Program to illustrate packages design

32

Program to illustrate writing to a file

33

Program to illustrate reading from a file

34

Program to illustrate multithreaded program

35

Program to illustrate final keyword

PAGE NO.

SIGNATURE

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE WORKING WITH OBJECTS

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:1

[]*/

/*[]===============================================================[]*/

#include<iostream.h>
#include<conio.h>
class studinfo
{
private:
long int regno;
char name[5];
int m1,m2,m3,m4,m5,tot;
float avg;
char res;
public:
void getstudinfo(void)
{
cout<<"Enter Register number:";
cin>>regno;
cout<<"Enter Name:";
cin>>name;
cout<<"Enter mark 1:";
cin>>m1;
cout<<"Enter mark 2:";
cin>>m2;
cout<<"Enter mark 3:";
cin>>m3;
cout<<"Enter mark 4:";
cin>>m4;
cout<<"Enter mark 5:";

cin>>m5;
}
void findresult(void)
{
tot=m1+m2+m3+m4+m5;
avg=tot/5;
if(m1>=50 && m2>=50 && m3>=50 && m4>=50 && m5>=50)
res='p';
else
res='f';
}
void showresult(void)
{
cout<<"Reg.No. Name"<<"\tM1\tM2\tM3\tM4\tM5\tTotal\tAverage\tResult"<<endl;
cout<<"===============================================================
==========="<<endl;
cout<<regno<<"\t"<<name<<"\t"<<m1<<"\t"<<m2<<"\t"<<m3<<"\t"<<m4<<"\t"
<<m5<<"\t"<<tot<<"\t"<<avg<<"\t"<<res;
}};
void main()
{
studinfo a;
clrscr();
a.getstudinfo();
a.findresult();
a.showresult();
getch();
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

WORKING WITH ARRAY OBJECTS

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:2

[]*/

/*[]===============================================================[]*/
#include<iostream.h>
#include<conio.h>
class studinfo
{
private:
long int regno;
char name[5];
int m1,m2,m3,m4,m5,tot;
float avg;
char res;
public:
void getstudinfo(void)
{
cout<<"\nEnter Register number:";
cin>>regno;
cout<<"Enter name:";
cin>>name;
cout<<"Enter mark 1:";
cin>>m1;
cout<<"Enter mark 2:";
cin>>m2;
cout<<"Enter mark 3:";
cin>>m3;
cout<<"Enter mark 4:";
cin>>m4;
cout<<"Enter mark 5:";

cin>>m5;
}
void findresult(void)
{
tot=m1+m2+m3+m4+m5;
avg=tot/5;
if(m1>=50&&m2>=50&&m3>=50&&m4>=50&&m5>=50)
res='P';
else
res='F';
}
void showresult1(void)
{
cout<<"Reg#\tname\tm1\tm2\tm3\tm4\tm5\ttot\tavg\tresult\n";
cout<<"===============================================================
============\n";
}
void showresult2(void)
{
cout<<regno<<"\t"<<name<<"\t"<<m1<<"\t"<<m2<<"\t"<<m3<<"\t"
<<m4<<"\t"<<m5<<"\t"<<tot<<"\t"<<avg<<"\t";
if(res=='P')
cout<<"PASS\n";
else
cout<<"FAIL\n";
}
};
void main()
{
studinfo a[3];
clrscr();
for(int i=0;i<3;i++)

{
a[i].getstudinfo();
a[i].findresult();
}
a[1].showresult1();
for(i=0;i<3;i++)
a[i].showresult2();
getch();
}

OUTPUT:

RESULT:

/*[]================================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE FUNCTION OVERLOADING

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:3

[]*/

/*[]================================================================[]*/
#include<iostream.h>
#include<conio.h>
int add(int x,int y)
{
cout<<"I am in int,int\t\t";
return x+y;
}
float add(float x,int y)
{
cout<<"I am in float,int\t";
return x+y;
}
float add(int x,float y)
{
cout<<"I am in int,float\t";
return x+y;
}
float add(float x,float y)
{
cout<<"I am in float,float\t";
return x+y;
}

void main(void)
{
clrscr();
cout<<add(10,23)<<endl;
cout<<add(3.5f,34)<<endl;
cout<<add(3,4.6f)<<endl;
cout<<add(5.6f,7.2f)<<endl;
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE CONSTUCTOR AND DESTRUCTOR

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:4

[]*/

/*[]===============================================================[]*/
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
class consdesc
{
private:
int *x;
int size;
public:
consdesc()
{
size=3;
x=(int*)malloc(sizeof(int)*size);
cout<<"I am in default constructor"<<endl;
}
consdesc(int s)
{
size=s;
x=(int *)malloc(sizeof(int)*size);
cout<<"I am in parameterised constructor"<<endl;
}
~consdesc()
{
free(x);

cout<<"I am in destructor"<<endl;
}
void readvalue(void)
{
for(int i=0;i<size;i++)
{
cout<<"Enter value [ "<<i+1<<" ]=";
cin>>x[i];
}
}

void dispvalue(void)
{
for(int i=0;i<size;i++)
{
cout<<"value [ "<<i+1<<" ]="<<x[i]<<endl;
}
}
};
void main(void)
{
clrscr();
consdesc x,y(5);
x.readvalue();
y.readvalue();
x.dispvalue();
y.dispvalue();
getch();
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE DEFAULT CONSTRUCTOR

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:5

[]*/

/*[]===============================================================[]*/

#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
class defaug
{
private:
int *x;
int size;
public:
defaug(int s=5)
{
size=s;
x=(int*)malloc(sizeof(int)*size*size);
}
~defaug()
{
free(x);
}
void genmagic()
{
int r,c;
r=1;
c=size/2;

for(int i=1;i<=(size*size);i++)
{
x[(r-1)*size+c]=i;
if(i%size==0)
r++;
else
{
r--;
c--;
if(r<1) r=size;
if(c<0) c=size-1;
}
}
}
void display()
{
int r,c;
for(r=1;r<=size;r++)
{
for(c=0;c<size;c++)
cout<<x[(r-1)*size+c]<<"\t";
cout<<endl;
}
}
};
void main()
{
clrscr();
defaug x(7),y;
cout<<"Magic square generated by normal argument method:"<<endl;

x.genmagic();
x.display();
cout<<endl<<endl;
cout<<"Magic square generated by default argument method:"<<endl;
y.genmagic();
y.display();
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE DYNAMIC MEMORY ALLOCATION

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.no.:6

[]*/

/*[]===============================================================[]*/
#include<iostream.h>
#include<conio.h>
class defaug
{
private:
int *x,size;
public:
defaug(int s=5)
{
size=s;
x=new int[s*s];
}
~defaug()
{
delete x;
}
void generate(void)
{
int r,c;
r=1;
c=size/2;
for(int i=1;i<=(size*size);i++)
{
x[(r-1)*size+c]=i;

if(i%size==0)
r++;
else
{
r--;
c--;
if(r<1) r=size;
if(c<0) c=size-1;
}
}
}
void display()
{
int r,c;
for(r=1;r<=size;r++)
{
for(c=0;c<size;c++)
cout<<x[(r-1)*size+c]<<"\t";
cout<<endl;
}
}
};
void main()
{
clrscr();
defaug x,y(9);
cout<<"Magic square generated by default arguments method"<<endl;
x.generate();
x.display();
cout<<endl<<"-----------------------------------------------------------"<<endl;

cout<<endl<<"Magic square generated by normal argument method"<<endl;


y.generate();
y.display();
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE REFERENCE PARAMETERS

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:7

[]*/

/*[]===============================================================[]*/
#include<iostream.h>
#include<conio.h>
class nav
{
public:
int a,b,c,d;
void getval(void)
{
cout<<"\nEnter the value of a:";
cin>>a;
cout<<"\nEnter the value of b:";
cin>>b;
cout<<"\nEnter the value of c:";
cin>>c;
cout<<"\nEnter the value of d:";
cin>>d;
}
void display(void)
{
cout<<"\na="<<a<<" ; b="<<b<<endl;
cout<<"\nc="<<c<<" ; d="<<d<<endl;
}
void swap(int &x,int &y)
{
int t;

t=x;
x=y;
y=t;
}
};
void main()
{
nav a;
clrscr();
a.getval();
a.display();
cout<<"\n\n\nSwaping a & b"<<endl;
a.swap(a.a,a.b);
cout<<"\nSwaping c & d"<<endl;
a.swap(a.c,a.d);
a.display();
getch();
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE TEMPLATES USING GENETIC SORT

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:8

[]*/

/*[]===============================================================[]*/
#include<iostream.h>
#include<conio.h>
template <class x> void bubble(x *items,int count)
{
register int a,b;
x t;
for(a=1;a<count;a++)
for(b=count-1;b>=a;b--)
if(items[b-1]>items[b])
{
t=items[b-1];
items[b-1]=items[b];
items[b]=t;
}
}
int main()
{
int iarray[7]={7,5,4,9,8,6};
double darray[5]={4.3,3.5,-0.9,100.2,3.0};
int i;
clrscr();
cout<<"Here is unsorted integer array:";

for(i=0;i<7;i++)
cout<<iarray[i]<<' ';
cout<<endl;
cout<<"Here is unsorted double array:";
for(i=0;i<5;i++)
cout<<darray[i]<<' ';
cout<<endl;
bubble(iarray,7);
bubble(darray,5);
cout<<"Here is sorted integer array:";
for(i=0;i<7;i++)
cout<<iarray[i]<<' ';
cout<<endl;
cout<<"Here is sorted double array:";
for(i=0;i<5;i++)
cout<<darray[i]<<' ';
cout<<endl;
getch();
return 0;
}

OUTPUT:

RESULT:

/*[]================================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE OPERATOR OVERLOADING

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:9

[]*/

/*[]================================================================[]*/
#include<iostream.h>
#include<conio.h>
#define SIZE 3
class Matrix
{
int matrix[SIZE][SIZE];
public:
void show();
Matrix();
Matrix operator+(Matrix t);
void operator=(Matrix t);
void get_data();
};
void Matrix::Matrix()
{
for(int i=0;i<SIZE;i++)
for(int j=0;j<SIZE;j++)
matrix[i][j]=0;
}
void Matrix::get_data()
{
for(int i=0;i<SIZE;i++)
for(int j=0;j<SIZE;j++)

cin>>matrix[i][j];
}
Matrix Matrix::operator+(Matrix t)
{
Matrix temp;
for(int i=0;i<SIZE;i++)
for(int j=0;j<SIZE;j++)
temp.matrix[i][j]=this->matrix[i][j]+t.matrix[i][j];
return temp;
}
void Matrix::show()
{
for(int i=0;i<SIZE;i++)
{
for(int j=0;j<SIZE;j++)
{
cout<<"\t"<<matrix[i][j];
}
cout<<"\n";
}
}
void Matrix ::operator=(Matrix c)
{
for(int i=0;i<SIZE;i++)
for(int j=0;j<SIZE;j++)
this->matrix[i][j]=c.matrix[i][j];
}
void main(void)
{
clrscr();
Matrix a,b,c;

cout<<"Enter matrix A:\n";


a.get_data();
cout<<"Enter matrix B:\n";
b.get_data();
cout<<"Matrix A is:\n";
a.show();
cout<<"Matrix B is:\n";
b.show();
c=a+b;
cout<<"Resultant Matrix C is:\n";
c.show();
getch();
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE PRIVATE INHERITANCE

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:10

[]*/

/*[]===============================================================[]*/
#include<iostream.h>
#include<conio.h>
class rectangle
{
private:
float length;
public:
float breadth;
void enter_lb(void)
{
cout<<"\nEnter the length of rectangle:";
cin>>length;
cout<<"\nEnter the breadth of rectangle:";
cin>>breadth;
}
float enter_l(void)
{
return length;
}
};
class Rectangle:private rectangle
{
float area;
public:

void rec_area(void)
{
enter_lb();
area=enter_l()*breadth;
}
void display(void)
{
cout<<"\nLength ="<<enter_l();
cout<<"\nBreadth="<<breadth;
cout<<"\nArea ="<<area;
}
};
void main(void)
{
Rectangle a;
a.rec_area();
a.display();
getch();
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE OBJECT SLICING

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:11

[]*/

/*[]===============================================================[]*/
#include<iostream.h>
#include<conio.h>
class B
{
public:
int i;
};
class D:public B
{
public:
int j;
};
void main(void)
{
B B1;
D D1;
clrscr();
B1.i=20;
cout<<B1.i<<endl;
D1.i=40;
cout<<D1.i<<endl;
B1=D1;
cout<<B1.i<<endl;
getch();
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE VIRTUAL DESTRUCTOR

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:12

[]*/

/*[]===============================================================[]*/
#include<iostream.h>
#include<conio.h>
class base
{
public:
base()
{
cout<<"Constructing base"<<endl;
}
virtual ~base()
{
cout<<"Destroying base"<<endl;
}
};
class derived:public base
{
public:
derived()
{
cout<<"constructing derived"<<endl;
}
~derived()
{
cout<<"Destroying derived"<<endl;

}
};
void main()
{
clrscr();
base *baseptr=new derived();
delete baseptr;
getch();
}

OUTPUT:

RESULT:

/*[]================================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE FUNCTION OVERRIDING

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No :13

[]*/

/*[]================================================================[]*/
#include<iostream.h>
#include<conio.h>
class base
{
public:
virtual void who(void)
{
cout<<"\nBase";
}
};
class first_d:public base
{
public:
void who(void)
{
cout<<"\nFirst derivative";
}
};
class second_d:public base
{
public:
void who(void)
{
cout<<"\nSecond derivative";

}
};
void main(void)
{
clrscr();
base base_obj;
base *p;
first_d first_obj;
second_d second_obj;
p=&base_obj;
p->who();
p=&first_obj;
p->who();
p=&second_obj;
p->who();
getch();
}

OUTPUT:

RESULT:

/*[]==============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE READ AND WRITE IN A FILE

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:14`

[]*/

/*[]==============================================================[]*/
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<string.h>
void main(void)
{
clrscr();
int n;
while(1)
{
cout<<"FILE HANDLING"<<endl;
cout<<"1.Create and Write in a file"<<endl;
cout<<"2.Read the file"<<endl;
cout<<"3.Exit"<<endl;
cout<<"Enter your option<#>:";
cin>>n;
if(n>3 || n<0)
cout<<"The entered option is irrelevant"<<"\nPlease enter a right option\n\n\n";
if(n==3)return;
if(n==1)
{
char str[80];
ofstream wfile("c:\\sample.txt",ios::out);
while(1)

{
cout<<"Enter string: ";
cin>>str;
if(!strcmpi(str,"end"))break;
wfile<<str<<endl;
}
wfile.close();
}
if(n==2)
{
char str[80];
ifstream myfile("c:\\sample.txt",ios::in);
if(!myfile.good())
cout<<"'Error:nothing to read in file'";
else
while(myfile.good())
{
myfile.getline(str,80,'\n');
cout<<str<<endl;
}
myfile.close();
}
}
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE MATHEMATICAL OPERATION

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:15

[]*/

/*[]===============================================================[]*/
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class calc
{
public:
int exp(int a,int b);
unsigned long fact(int c);
void prime(int d);
int gcd(int e,int f);
};
unsigned long calc::fact(int c)
{
unsigned long result=1;
while(c>0)
{
result=result*c;
c=c-1;
}
return result;
}
int calc::exp(int a,int b)
{
int result;

result=1;
while(b!=0)
{
result=result*a;
b=b-1;
}
return result;
}
void calc::prime(int d)
{
int count=2,f=1;
while(count<=(d/2))
{
if(d%count==0)
{
f=0;
break;
}count++;
}
if(f) cout<<d<<" is prime";
else cout<<d<<" is not prime";
}

int calc::gcd(int e,int f)


{
int temp;
while(f!=0)
{
temp=e%f;
e=f;

f=temp;
}
return e;
}
void main(void)
{
calc n;
int i;
char c;
clrscr();
while(1)
{
cout<<"\nMATHEMATICAL CALCULATION";
cout<<"\n1.Exponential";
cout<<"\n2.Factorial";
cout<<"\n3.Check Prime";
cout<<"\n4.GCD";
cout<<"\n5.Exit\n";
cout<<"Enter your option<#>:";
cin>>i;
if(i>5 || i<1)
cout<<"Your option is irrelevant!!!!!\nPlease enter right option\n\n";
int x,y;
switch(i)
{
case 1:
cout<<"Exponential was Selected:\n";
cout<<"Enter x value:";
cin>>x;
cout<<"Enter y value:";
cin>>y;

cout<<x<<"^"<<y<<" is "<<n.exp(x,y);
break;
case 2:
cout<<"Factorial was Selected\n";
cout<<"Enter x value:";
cin>>x;
cout<<"x!="<<n.fact(x);
break;
case 3:
cout<<"Prime Number Checking was Selected\n";
cout<<"Enter x value:";
cin>>x;
n.prime(x);
break;
case 4:
cout<<"GCD was Selected\n";
cout<<"Enter x value:";
cin>>x;
cout<<"Enter y value:";
cin>>y;
cout<<"GCD of x="<<x<<" and y="<<y<<" is "<<n.gcd(x,y);
break;
case 5:
exit(0);
}}}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE STATIC DATA MEMBERS

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:16

[]*/

/*[]===============================================================[]*/
#include<iostream.h>
#include<conio.h>
class stat
{
public:
static int x;
float length;
};
int stat::x=0;
void main(void)
{
stat a,b,c;
a.x=23;
a.length=10;
b.x=45;
b.length=20;
c.length=30;
cout<<"static x:"<<a.x<<endl;
cout<<"length "<<a.length<<endl;
cout<<"static x:"<<b.x<<endl;
cout<<"length "<<b.length<<endl;

cout<<"static x:"<<c.x<<endl;
cout<<"length "<<c.length<<endl;
getch();
}

OUTPUT:

RESULT:

/*[]==============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE FRIEND FUNCTION

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:17

[]*/

/*[]==============================================================[]*/
#include<iostream.h>
#include<conio.h>
class counting
{
int num,no_of_1,no_of_0,cont_1,cont_0;
unsigned long bin;
public:
counting (int a)
{
num=a;
}
void count()
{
no_of_1=no_of_0=cont_1=cont_0=0;
int x=0,temp1=0,temp0=0;
unsigned long bt=bin;
for(;bt>0;bt/=10)
{
x=bt%10;
if(x==1)
{
no_of_1++;
temp1++;
if(temp1>cont_1) cont_1=temp1;
temp0=0;
}
else
{

no_of_0++;
temp0++;
if(temp0>cont_0) cont_0=temp0;
temp1=0;
}
}
}
void disp()
{
cout<<"Binary Number is: "<<bin<<endl;
cout<<"No. of 1: "<<no_of_1<<endl;
cout<<"Max no. of continuous 1: "<<cont_1<<endl;
cout<<"No. of 0: "<<no_of_0<<endl;
cout<<"Max no. of continuous 0: "<<cont_0<<endl;
}
friend void dec_to_bin(counting &c);
};
void dec_to_bin(counting &c)
{
unsigned long x=1;
c.bin=0;
for(;c.num>0;c.num/=2)
{
c.bin+=(c.num%2)*x;
x*= 10;
}
}
void main()
{
clrscr();
int a;
cout<<"Enter a num:";
cin>>a;

counting no(a);
dec_to_bin(no);
no.count();
no.disp();
getch();
}

OUTPUT:

RESULT:

/*[]==============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE NUMBER TO WORD CONVERTION

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:18

[]*/

/*[]==============================================================[]*/
#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
class word
{
unsigned long ru;
int pa;
public:
void get();
void find();
void dig(int a, char d[]);
};
void word::get()
{
cout<<" Enter Number:";
char a[15],c[15];
int i=0,j;
gets(a);
for( ; a[i]!='.'&&a[i]!='\0'; i++)
c[i]=a[i];
ru=atol(c);
for(j=0; j<15; c[j++]=' ');
for(j=i+1; j<i+3&&a[j]!='\0'; j++)
c[j-i-1]=a[j];
pa=atoi(c);

}
void word::find()
{
int cr,lak,tho,hun;
cr=ru/10000000;
lak=(ru/100000)%100;
tho=(ru/1000)%100;
hun=ru%1000;
char ans[250]="";
dig(cr,ans);
if(cr) strcat(ans," Crore(s) ");
dig(lak,ans);
if(lak) strcat(ans," Lakh(s) ");
dig(tho,ans);
if(tho) strcat(ans," Thousand ");
dig(hun,ans);
if(ru==0&&pa==0) strcat(ans," Zero Rupees");
if(ru)strcat(ans," Rupee(s) ");
if(pa)
{
if(ru)strcat(ans,"And ");
dig(pa,ans);
strcat(ans," Paise" );
}
cout<<"\n"<<ans;
}
void word::dig(int a, char di[])
{
char *si[]={"","One","Two","Three","Four","Five","Six","Seven",
"Eight","Nine",

"Ten","Eleven","Tweleve","Thirteen","Forteen",

"Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
char *dou[]={" "," ","Twenty","Thirty","Forty","Fifty",
"Sixty","Seventy","Eighty","Ninety"};

int h;
h=a/100;
if(h)
{
strcat(di,si[h]);
strcat(di," Hundred ");
if(a%100)strcat(di,"And ");
}
h=a%100;
if(h>19)
{
int b;
b=h/10;
strcat(di,dou[b]);
b=h%10;
if(b)

strcat(di," ");

strcat(di, si[b]);
}
else

strcat(di, si[h]);

}
void main()
{
word a;
clrscr();
a.get();
a.find();
getch();
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE PUBLIC INHERITANCE

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:19

[]*/

/*[]===============================================================[]*/
#include<iostream.h>
#include<conio.h>
class rectangle
{
private:
float length;
public:
float breadth;
void enter_lb(void)
{
cout<<"\nEnter the length of rectangle:";
cin>>length;
cout<<"\nEnter the breadth of rectangle:";
cin>>breadth;
}
float enter_l(void)
{
return length;
}
};
class Rectangle:public rectangle
{
private:
float area;

public:
void rec_area(void)
{
area=enter_l()*breadth;
}
void display(void)
{
cout<<"\nLength ="<<enter_l();
cout<<"\nBreadth="<<breadth;
cout<<"\nArea ="<<area;
}
};
void main(void)
{
Rectangle a;
a.enter_lb();
a.rec_area();
a.display();
getch();
}

OUTPUT:

RESULT:

/*[]==============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE COPY CONSTRUCTOR

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:20

[]*/

/*[]==============================================================[]*/
#include<iostream.h>
#include<conio.h>
class line
{
public:
//int getlength();
line(int len);
void display();
line(const line &obj);
~line();
private:
int *ptr;
};
line::line(int len)
{
cout<<"Normal constructor allocating ptr"<<endl;
ptr=new int;
*ptr=len;
}
line::line(const line &obj)
{
cout<<"copy constructor allocating ptr"<<endl;
ptr=new int;
*ptr=*obj.ptr;

}
line::~line(void)
{
cout<<"Freeing member"<<endl;
delete ptr;
}
void line::display()
{
cout<<"length of line:"<<*ptr;
cout<<endl;
}
/*int line::getlength()
{
return *ptr;
}*/
void main()
{
clrscr();
line line1(10);
line line2=line1;
line1.display();
line2.display();
getch();
}

OUTPUT:

RESULT:

/*[]==============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE GRAPHICS

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:21

[]*/

/*[]==============================================================[]*/
#include<iostream.h>
#include<dos.h>
#include<conio.h>
class graph
{
int a[10][3];
char far *scr;
public:
void init()
{
union REGS regs;
scr=(char far*)0XA0000000;
regs.h.ah=0;
regs.h.al=0X13;
int86(0X10,&regs,&regs);
diamond();
regs.h.ah=0X0;
regs.h.al=0X3;
int86(0X10,&regs,&regs);
}
void diamond();
graph();
};
void graph::diamond()
{
int i,j,k,l,c,cl;
for(cl=0;cl<=255;cl++)

{
if(kbhit())break;
for(l=0,c=cl;l<200;l+=20)
{
for(k=0;k<320;k+=20,c++)
{
for(i=0;i<10;i++)
for(j=a[i][1];j<=a[i][2];j++)
*(scr+(l*320)+(a[i][0]-1)*320+j+k-1)=c;
for(i=9;i>=0;i--)
for(j=a[i][1];j<=a[i][2];j++)
*(scr+(l*320)+((10-a[i][0]-1)+10)*320+j+k-1)=c;
}
}
}
getch();
}
graph::graph()
{
for(int i=0;i<10;i++)
{
a[i][0]=i+1;
a[i][1]=10-i;
a[i][2]=11+i;
}
}
void main()
{
graph G;
G.init();
G.diamond();
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE ABSTRACT CLASS

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:22

[]*/

/*[]===============================================================[]*/
#include<iostream.h>
#include<conio.h>
class Figure
{
protected:double x, y;
public:
void set(double i, double j)
{
x=i;y=j;
}
virtual void area()=0;
};
class tri:public Figure
{
public:
void area()
{
cout<<"\nTriangle with Height= "<<x<<" and Base= ";
cout<<y<<" has Area= "<<x*0.5*y;
}
};
class rec:public Figure
{
public:
void area()
{
cout<<"\nRectangle with Length= "<<x<<" and Breadth= ";
cout<<y<<" has Area= "<<x*y;

}
};
void main()
{
Figure *p;
tri t;
rec r;
p=&t;
p->set(10.0,5.0);
p->area();
p=&r;
p->set(10.0,5.0);
p->area();
getch();
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE GENERATION OF CALENDAR

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:23

[]*/

/*[]Date :26/09/2012

[]*/

/*[]===============================================================[]*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int mon[]={31,28,31,30,31,30,31,31,30,31,30,31};
char *mont[]={"January","February","March","April","May","June",
"July","August","September","October","November","December"};
class calendar
{
long year;int month;
public:
void getdate(char a[]);
void print();
};
void calendar::getdate(char a[]="2012")
{
char y[15];
for(int i=0;a[i]!=' '&&a[i]!='\0';i++)
y[i]=a[i];
year=atol(y);
for(int j=0;j<15;y[j++]='\0');
month=0;
for(j=i+1;a[j]!='\0';j++)
y[j-i-1]=a[j];
month=atoi(y);

if((year%4==0&&year%100!=0)||!(year%400))
mon[1]=29;
}
void calendar::print()
{
int X=5,Y=4,x,y,nol,ye,odd_day;
ye=(year-1)%400;
nol=ye/4-ye/100;
odd_day=nol*2+(ye-nol)+1;
if(month)
{
for(int i=0;i<month-1;odd_day+=mon[i++]);
}
odd_day%=7;
int c=(month)?month+1:13;
X=month?15:5;
clrscr();
if(month)cout<<"\n\tCalender of Year "<<year<<" and Month "<<month;
else

cout<<"\n\t\t\tCalender of Year "<<year;

for(int j=month;j<c;j++)
{
if(!j)j++;
gotoxy(X,Y);
cout<<"

"<<mont[j-1];

gotoxy(X,Y+2);
cout<<"Su Mo Tu We Th Fr Sa";
x=X+odd_day*3;
y=Y+3;
for(int i=1;i<=mon[j-1];i++)
{
gotoxy(x,y);
cout<<i;
x+=3;

if((odd_day+i)%7==0)
{
x=X; y++;
}
}
odd_day=(odd_day+i-1)%7;
X+=26;
if(j%3==0)
{
X=5; Y+=11;
}
}
}
void main()
{
clrscr();
char d[15]=" ";
cout<<"\n \t Calendar of Year And Month:";
gets(d);
calendar a;
if(d[0]=='0'||!isdigit(d[0]))
a.getdate();
else
a.getdate(d);
a.print();
getch();
}

OUTPUT:

RESULT:

/*[]================================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE STANDARD TEMPLATE LIBRARY

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:24

[]*/

/*[]================================================================[]*/
#include<iostream>
#include<vector>
using namespace std;
main()
{
vector<int> ss;
ss.push_back(10);
ss.push_back(7);
ss.push_back(1);
cout<<"Loop by index:"<<endl;
int i;
for(i=0;i<ss.size();i++)
cout<<ss[i]<<endl;
cout<<endl<<"Constant Iterator:"<<endl;
vector<int>::const_iterator ci;
for(ci=ss.begin();ci!=ss.end();ci++)
cout<<*ci<<endl;
while(1);
}

OUTPUT:

RESULT:

/*[]================================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE EXCEPTION HANDLING

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:25

[]*/

/*[]================================================================[]*/
#include<iostream.>
using namespace std;
int main()
{
try
{
throw 20;
}
catch (int a)
{
cout<<"An integer exception occured"
}
catch(...)
{
cout<<"General error occured";
}
return 1;
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[[]PROGRAM TO ILLUSTRATE COUNTING NUMBER OF WORDS IN A FILE

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:26

[]*/

/*[]===============================================================[]*/
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<ctype.h>
class FH
{
int no_cha,no_wor,no_alp,no_num,no_spe,no_lin;
public:
void _char(ifstream &a);
void display(ifstream &a);
};
void FH::display(ifstream &a)
{
_char(a);
cout<<"\nNo. of Characters = "<<no_cha;
cout<<"\nNo. of Words

= "<<no_wor;

cout<<"\nNo. of Lines

= "<<no_lin;

cout<<"\nNo. of Alphabets = "<<no_alp;


cout<<"\nNo. of Numerals = "<<no_num;
cout<<"\nNo. of Special Characters = "<<no_spe;
}
void FH::_char(ifstream &a)
{
char ch[2];
no_cha=no_wor=no_alp=no_num=no_lin=0;
ch[0]=' ';
cout<<"\nFile is\n";

while(a.good())
{
a.get(ch[1]);
cout<<ch[1];
if(ch[1]==' '||ch[1]=='\t'||ch[1]=='\n')
if(ch[0]!=' '&&ch[0]!='\t'&&ch[0]!='\n')
no_wor++;
if(ch[1]=='\n'&&ch[0]!='\n')
no_lin++;
if(!(ch[1]==' '||ch[1]=='\t'||ch[1]=='\n'))
no_cha++;
ch[0]=ch[1];
if(isalpha(ch[1]))no_alp++;
if(isdigit(ch[1]))no_num++;
}
no_cha--;
no_wor++;no_lin++;
no_spe=no_cha-no_alp-no_num;
}
void main()
{
clrscr();
ifstream my("C:\\viv.txt",ios::in);
FH a;
a.display(my);
my.close();
getch();
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]PROGRAM TO ILLUSTRATESIMPLE CLASS DESIGN IN JAVA

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:27

[]*/

/*[]===============================================================[]*/
import java.lang.*;
public class Circle
{
public float r;
public float circumference()
{
return 2*3.14f*r;
}
public float area()
{
return 3.14f*r*r;
}
public static void main(String args[])
{
Circle c=new Circle();
c.r=5;
System.out.println("Circumference:"+c.circumference());
System.out.println("Area
}
}

:"+c.area());

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE INTEFRACE

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:28

[]*/

/*[]===============================================================[]*/
import java.io.*;
interface biodata
{
void name(String name);
void age(int age);
void address(String address);
void quali(String quali);
}
public class Resume implements biodata
{
public void name(String name)
{
System.out.println("name

:"+name);

}
public void age(int age)
{
System.out.println("age

:"+age);

}
public void address(String address)
{
System.out.println("Address
}
public void quali(String quali)

:"+address);

{
System.out.println("Qualification:"+quali);
}
public static void main(String args[])
{
Resume r1=new Resume();
r1.name("Naveen.S");
r1.age(19);
r1.address("Vaniyambadi,vellore.");
r1.quali("BE EEE");
}
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE SINGLE INHERITANCE

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:29

[]*/

/*[]===============================================================[]*/
import java.lang.*;
class A
{
int i;
int j;
void showij()
{
System.out.println("i="+i);
System.out.println("j="+j);
}
}
class B extends A
{
int k;
void showk()
{
System.out.println("k="+k);
}
void sum()
{
System.out.println("(i+j+k)="+(i+j+k));
}

}
class SimpleInheri
{
public static void main(String args[])
{
A superOb=new A();
B subOb=new B();
superOb.i=10;
superOb.j=20;
System.out.println("Contents of superOb:");
superOb.showij();
System.out.println();
subOb.i=5;
subOb.j=10;
subOb.k=15;
System.out.println("Contents of subOb:");
subOb.showij();
subOb.showk();
System.out.println();
System.out.println("Sum of i,j,k in subObj:");
subOb.sum();
}
}

OUTPUT:

RESULT

/*[]===============================================================[]*/
/*[]PROGRAM TO ILLUSTRATE MULTILEVEL INHERITANCE AND JAVA DOC

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:30

[]*/

/*[]===============================================================[]*/
import java.lang.*;
class box
{
double width;
double height;
double depth;
box(box ob)
{
width=ob.width;
height=ob.height;
depth=ob.depth;
}
box(double w,double h,double d)
{
width=w;
height=h;
depth=d;
}
box()
{
width=-1;
height=-1;
depth=-1;
}

box(double len)
{
width=height=depth=len;
}
double volume()
{
return width*height*depth;
}
}
class boxweight extends box
{
double weight;
boxweight(boxweight ob)
{
super(ob);
weight=ob.weight;
}
boxweight(double w,double h,double d,double m)
{
super(w,h,d);
weight=m;
}
boxweight()
{
super();
weight=-1;
}

boxweight(double len,double m)
{
super(len);
weight=m;
}
}
class shipment extends boxweight
{
double cost;
shipment(shipment ob)
{
super(ob);
cost=ob.cost;
}
shipment(double w,double h,double d,double m,double c)
{
super(w,h,d,m);
cost=c;
}
shipment()
{
super();
cost=-1;
}
shipment(double len,double m,double c)
{
super(len,m);
cost=c;

}
}
class DemoShipment
{
public static void main(String args[])
{
shipment shipment1=new shipment(10,20,15,10,3.14);
shipment shipment2=new shipment();
shipment shipment3=new shipment(10,3,0.98);
double vol;
vol=shipment1.volume();
System.out.println("Volume of shipment1 is

="+vol);

System.out.println("Weight of shipment1 is

="+shipment1.weight);

System.out.println("Shipment cost of shipment1 is="+shipment1.cost);

vol=shipment2.volume();
System.out.println("Volume of shipment1 is

="+vol);

System.out.println("Weight of shipment1 is

="+shipment2.weight);

System.out.println("Shipment cost of shipment1 is="+shipment2.cost);

vol=shipment3.volume();
System.out.println("Volume of shipment1 is

="+vol);

System.out.println("Weight of shipment1 is

="+shipment3.weight);

System.out.println("Shipment cost of shipment1 is="+shipment3.cost);


}
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE PACKAGES DESIGN

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:31

[]*/

/*[]===============================================================[]*/
package mypack;
class balance
{
String name;
double bal;
balance(String n,double b)
{
name=n;
bal=b;
}
void show()
{
if (bal<0)
System.out.println("-->");
System.out.println(name+":$" +bal);
}
}
class AccountBalance
{
public static void main(String args[])
{
balance current[]=new balance[3];
current[0]=new balance("Newton",133.32);

current[1]=new balance("Einstein",324.33);
current[2]=new balance("Edison",214.33);
for(int i=0;i<3;i++)
current[i].show();
}
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE WRITING A FILE

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:32

[]*/

/*[]===============================================================[]*/
import java.io.*;
public class Filewrite
{
public static void main(String args[])
{
String filename="temp.txt";
try
{
FileWriter fw=new FileWriter(filename);
BufferedWriter bw=new BufferedWriter(fw);
bw.write("India is our country");
bw.newLine();
bw.write("I am in UCEK");
System.out.println("File has been sucessfully written");
bw.close();
fw.close();
}
catch(IOException ex)
{
System.out.println("Error writing to file:'"+filename+"'");
}
}
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE READING A FILE

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:33

[]*/

/*[]===============================================================[]*/
import java.io.*;

public class Fileread


{
public static void main(String args[])
{
String filename="temp.txt";
String line=null;
try
{
FileReader fr=new FileReader(filename);
BufferedReader br=new BufferedReader(fr);
while((line=br.readLine())!=null)
System.out.println(line);
br.close();
fr.close();
}
catch(FileNotFoundException ex)
{
System.out.println("unable to open file:'"+filename+"'");
}
catch(IOException ex)
{
System.out.println("Error reading from file:'"+filename+"'");
}
}
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE MULTITHREADED PROGRAM

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:34

[]*/

/*[]===============================================================[]*/
import java.lang.*;
class NewThread implements Runnable
{
String name;
Thread t;
NewThread(String threadname)
{
name=threadname;
t=new Thread(this,name);
System.out.println("New thread:"+t);
t.start();
}
public void run()
{
try
{
for(int i=5;i>0;i--)
{
System.out.println(name+ " :" + i);
Thread.sleep(1000);
}
}
catch(InterruptedException e)

{
System.out.println(name+"Interupted");
}
System.out.println(name+"exiting.");
}
}
class MultiThreadDemo
{
public static void main(String args[])
{
new NewThread("One ");
new NewThread("Two ");
new NewThread("Three");
try
{
Thread.sleep(10000);
}
catch(InterruptedException e)
{
System.out.println("Main thread interrupted");
}
System.out.println("Main thread exiting");
}
}

OUTPUT:

RESULT:

/*[]===============================================================[]*/
/*[]

PROGRAM TO ILLUSTRATE FINAL KEYWORD

[]*/

/*[]Author:S.Naveen

[]*/

/*[]Ex.No.:35

[]*/

/*[]===============================================================[]*/
import java.lang.*;
final class A
{
final int const=1;
final void meth()
{
System.out.println("This is final method");
}
}
public class Final extends A
{
void meth()
{
System.out.println("sucessfully overridden");
}
public static void main(String args[])
{
B b=new B();
b.meth();
}
}

OUTPUT:

RESULT:

S-ar putea să vă placă și