Sie sind auf Seite 1von 76

S.

NO PROGRAM NAME
1 Student Average marks
2 Area,Perimeter of Triangle
3 Swap two Numbers
4 Largest of Three Numbers
5 Maximum Among Three Numbers
6 Fibonacci Series
7 String Manipulation
8 Compare,Concatenate,Reverse,Copy the String
9 Quotient and Remainder of TWO Numbers
10 Banking Process
11 Prime Numbers between 1 to 50
12 Matrix Addition and Multiplication
13 Unary Operator Overloading
14 Salesman Average Salary
15 Employee Report
16 Student details Using pointers
17 ASCII value to its equivalent character
18 Function Overloading( Cube,Cylinder,Rectangular box)
19 Maximum of Two Numbers(Template Class)
TABLE OF CONTENTS
C++ OBJECT ORIENTED PROGRAMMING

TABLE OF CONTENTS
INTERNET PROGRAMMING (JAVA)

S.NO PROGRAM NAME


1 Fahreheit into Temperature
2 Student Mark-List preparation
3 Reverse and Sum of digits
4 Fibbonacci series
5 Factorial value
6 Prime Number
7 Ascending and Descending Number
8 Matrix multiplication
9 Roots of a Quadratic Equation
10 Volume of Sphere (Class and Object)
11 Employee salary (Array of Objects)
12 Stack Operation (Constructor)
13 Palindrome checking (Abstract class)
14 Electricity calculation (Implementing Multiple Inheritance)
15 Area of Triangle and Rectangle (Package,Interface)
16 Queue Implementation
17 Multi-Threading
18 Railway Reservation System (IO Streams )
19 Display Graphical component (Graphics class)
20 Display an Image (Getting pixels of an Image)

Ex.No.1

AVERAGE MARK SCORED BY A STUDENT

AIM: Calculate the average mark scored by a student.

ALGORITHM:

1. Start the program


2. Read the Input values (Subject marks & name)
3. Calculate the average marks
4. Print the calculated values
5. Stop the program

PROGRAM
#include<iostream.h>
#include<conio.h>
class student
{
private:
char name[15];
int m1,m2,m3;
float sum,avg;
public:
void getdata()
{
cout<<"\n Enter student name\t";
cin>>name;
cout<<"\n Enter student mark1\t";
cin>>m1;
cout<<"\n Enter student mark2\t";
cin>>m2;
cout<<"\n Enter student mark3\t";
cin>>m3;
}
void calculate()
{
sum=m1+m2+m3;
avg=sum/3;
}
void display()
{
cout<<"\n sum ="<<sum;
cout<<"\n avg ="<<avg;
}
};
void main()
{
clrscr();
student s;
s.getdata();
s.calculate();
s.display();
getch();
}
OUTPUT

Enter student name MUGUNTHAN


Enter student mark1 87
Enter student mark2 90
Enter student mark3 56
sum =233
RESULT:
Thus the above program is successfully executed.

Ex. No. 2

AREA AMD PERIMETER OF CIRCLE AND RECTANGLE

AIM: Calculate the area and Perimeter of a Circle and Rectangle.

ALGORITHM:

1. Start the program


2. Read the value for Radius
3. Calculate Area and Perimeter of circle by using
Area = ? r2
Perimeter = 2 ? r
4. Calculate Area and Perimeter of Rectangle by using
Area = l × b
Perimeter = 2(l + b)
5. Print the Calculated values
6. Stop the program
PROGRAM
#include<iostream.h>
#include<math.h>
#include<conio.h>
void main()
{
float r,pi=3.142,area1,peri1;
float l,b,area2,peri2;
clrscr();
cout<<"\n Enter radius of circle\t";
cin>>r;
area1=pi* pow(r,2);
peri1=2*pi*r;
cout<<"\n Enter length and Breadth";
cin>>l>>b;
area2=l*b;
peri2=2*(l+b);
cout<<"\n ----------------------------------";
cout<<"\n\tCIRCLE \t\tRECTANGLE ";
cout<<"\n-------------------------------------";
cout<<"\n area ="<<area1<<"\t\t"<<area2;
cout<<"\nperimeter="<<peri1<<"\t\t"<<peri2;
getch();
}

OUTPUT:

Enter radius of circle 4


Enter length and Breadth 6 8
---------------------------------------------
CIRCLE RECTANGLE
----------------------------------------------
area =50.271999 48
RESULT:
Thus the above program is successfully executed.
Ex. No. 3
SWAP TWO NUMBERS

AIM: To swap two numbers.

ALGORITHM:

1. Start the program


2. Read the values of two numbers
3. Add the given two numbers and store it in another v
ariable
(c = a + b)
4. Calculate a = c b
5. Calculate b = c - a
6. Print the values.
7. Stop the Program

PROGRAM
#include<iostream.h>
#include<conio.h>
class swap
{
private:
int a,b,c,d;
public:
void getdata()
{
cout<<"\n Enter number a=";
cin>>a;
cout<<"\n Enter number b=";
cin>>b;
}
void swaping()
{
c=a+b;
a=c-a;
b=c-b;
}
void display()
{
cout<<"\n a="<<a;
cout<<"\n b="<<b;
}
};
void main()
{
clrscr();
swap s;
s.getdata();
s.swaping();
s.display();
getch();
}

OUTPUT
Enter number a=25
Enter number b=36

a = 36

RESULT
Thus the above program is successfully executed.
Ex. No. 4
LARGEST OF THREE NUMBERS

AIM: Find the largest of three numbers.

ALGORITHM:

1. Start the program


2. Read the values of three numbers
3. Compare the three numbers
4. Print the biggest number.
5. Stop the Program

PROGRAM:
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"\n Enter first number";
cin>>a;
cout<<"\n Enter second number";
cin>>b;
cout<<"\n Enter third number";
cin>>c;
if(a>b && a>c)
cout<<"\n A is biggest";
else if(b>c)
cout<<"\n B id biggest";
else
cout<<"\n C is biggest";
getch();
}
OUTPUT

Enter first number 45


Enter second number 26
Enter third number 12

(OR)
Enter first number 12
Enter second number 56
Enter third number
23
(OR)
Enter first number 45
Enter second number 89

Enter third number


100
C is biggest

RESULT
Thus the above program is successfully executed.
Ex. No. 5

MAXIMUM OF THREE NUMBERS


AIM: Find the maximum of three numbers.

ALGORITHM:

1. Start the program


2. Read the values of three numbers
3. Compare the three numbers
4. Print the biggest number.
5. Stop the Program
PROGRAM
#include<iostream.h>
#include<conio.h>
void main()
{
int a[3],i,max;
clrscr();
for(i=0;i<3;i++)
{
cout<<"\n Enter No a["<<i<<"]";
cin>>a[i];
}
max=a[0];
for(i=0;i<3;i++)
{
if(max < a[i+1])
max=a[i+1];
}
cout<<"\n maximum number is "<<max;
getch();
}
OUTPUT
Enter No a[0] 89
Enter No a[1]5 6
Enter No a[2] 125
RESULT
Thus the above program is successfully executed.
Ex. No. 6

FIBONACCI SERIES

AIM: Print the Fibonacci series.

ALGORITHM:

1. Start the program


2. Read the limit value.
3. Assign the value of f1 = 0, f2 = 1
4.Calculate the value f3 = f1 + f2.
5. Print the counter value f2
6. f1 = f2
f2 = f3
7. Stop the Program.

PROGRAM

#include<iostream.h>
#include<conio.h>
void main()
{
int f1=-1,f2=1,f3,n,i;
clrscr();
cout<<"\n Enter How many Terms";
cin>>n;
cout<<"\n Fibbonacci series is \n";
for(i=1;i<=n;i++)
{
f3=f1+f2;
cout<<"\t"<<f3;
f1=f2;
f2=f3;
}
getch();
}
OUTPUT
Enter How many Terms 10
Fibbonacci series is

0
1
1
2
3
5

RESULT
Thus the above program is successfully executed.
Ex. No. 7
STRING MANIPULATION

AIM: Prefer string manipulation

ALGORITHM:

1. Start the program


2. Read the string.
3. Convert the string as upper case letters, if it is
given in lower case
letters
and viceversa
4. Print the string.
5. Stop the Program.
PROGRAM
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<conio.h>
void main() {
char name1,name,line[100];
int c;
c=0;
clrscr();
cout<<"Enter a String press <return> at end";
do {
name=getchar();
line[c]=name;
c++;
}while(name!='\n');
c=c-1;
line[c]='\0';
printf("\n %s\n",line);
cout<<"\n Enter a character";
name1=getchar();
if(islower(name1))
putchar(toupper(name1));
else
putchar(tolower(name1));
getch();
}
OUTPUT
Enter a String press <return> at end mugunthan jothi aravinth rajkumar
mugunthan jothi aravinth rajkumar
Enter a character q

RESULT
Thus the above program is successfully executed.

Ex. No. 8

LENGTH, COMPARE,CONCATENATE, REVERSE AND COPY THE STRING

AIM: Program to Compare, Length, Concatenate, Reverse and copy the given string
.

ALGORITHM:

1. Start the program


2. Read two strings.
3. Find the Length of the given string
4. Concatenate the two string by using str
ing function.
Concatenate (str1,str2).
5. Copy the string by using string function. Copy (str1
,str2).
6. Print the string.
7. Stop the Program

PROGRAM
#include<iostream.h>
#include<string.h>
#include<conio.h>
class string
{
private:
char s1[15],s2[15];
int l1,l2,x;
public:
void getstring();
void length();
void compare();
void concatenate();
void copy();
void reverse();
void display();
};
void string::getstring()
{
cout<<"\n enter first string\t";
cin>>s1;
cout<<"\n Enter second string\t";
cin>>s2;
}
void string::length()
{
l1=strlen(s1);
l2=strlen(s2);
}
void string::display()
{
cout<<"\n String1 =\t"<<s1;
cout<<"\n String2 =\t"<<s2;
cout<<"\n Length of the first string =\t"<<l1;
cout<<"\n Length of the second string =\t"<<l2;
}
void string::compare()
{
x=strcmp(s1,s2);
if(x!=0)
cout<<"\n Strings are not equal\n";
else
cout<<"\n Strings are equal\n";
}
void string::concatenate()
{
strcat(s1,s2);
cout<<"\n concatenation of two strings is =\t"<<s1;
}
void string::copy()
{
strcpy(s1,s2);
cout<<"\n copy of strings =\t"<<s1;
}
void string::reverse()
{
int i,j;
cout<<"\n REVERSE OF FIRST AND SECOND STRING\n";
for(i=l1;i>=0;i--)
cout<<s1[i];
cout<<"\t";
for(j=l2;j>=0;j--)
cout<<s2[j];
}
void main()
{
string s;
clrscr();
s.getstring();
s.length();
cout<<"\n-------------------";
cout<<"\n Given string ";
cout<<"\n ------------------";
s.display();
s.compare();
s.reverse();
s.concatenate();
s.copy();
getch();
}
OUTPUT
Enter first string mugu
Enter second string nthan
-------------------------------------------------------------------------
Given string
--------------------------------------
String1 = mugu
String2 = nthan
Length of the first string = 4
Length of the second string = 5
Strings are not equal
REVERSE OF FIRST AND SECOND STRING
ugum nahtn
concatenation of two strings is = mugunthan
RESULT
Thus the above program is successfully executed.
Ex. No. 9
QUOTIENT AND REMAINDER OF THE NUMBER

AIM: Find the quotient and Remainder of the Number..


ALGORITHM:

1. Start the program


2. Read a number n .
3. Find the quotient and remainder by using Q
= n / 10;
R = n % 10
4. Print quotient and Remainder
5. Stop the Program
PROGRAM
#include<iostream.h>
#include<conio.h>
void main()
{
int n1,n2,q1,q2;
float r1,r2;
clrscr();
cout<<"\n Enter first Number";
cin>>n1;
cout<<"\n Enter second Number";
cin>>n2;
q1=n1/10;
r1=n1%10;
q2=n2/10;
r2=n2%10;
cout<<"\n Quotient of first No. ="<<q1;
cout<<"\n Remainder of first No.="<<r1;
cout<<"\n Quotient of Second No. ="<<q2;
cout<<"\n Remainder of second No.="<<r2;
getch();
}
OUTPUT

Enter first Number 21


Enter second Number 89
Quotient of first No. =2
Remainder of first No.=1
Quotient of Second No. =8
RESULT
Thus the above program is successfully executed.

Ex. No. 10
BANKING INFORMATION SYSTEM

AIM: Create the user account and manipulate it.

ALGORITHM:
1. Start the program
2. Create the menu for Bank as
a. Deposit Money
b. Withdraw Money
c. Calculate Interest
d. Check the total balance
3. Read the values
4. Process the values by using functions
.
5. Print the calculated values.
6.Stop the Program
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
struct account
{
char name[30];
int acc_no;
char type[20];
float bala;
};
class bank
{
account *acct[20];
int size;
int search(int);
public:
bank(void){size=0;}
void create();
void deposit();
void withdraw();
void calculate();
void display();
};
int menu()
{
cout<<"\n C->Create an Account";
cout<<"\n D->Deposit an Account";
cout<<"\n W->Withdraw an Account";
cout<<"\n I->Calculate an Account";
cout<<"\n S->Show an Account";
cout<<"\n Q->Quit program";
cout<<"\n Enter Your option please?";
return toupper(getche());
}
int bank::search(int num) {
int pos=-1;
for(int i=0;i<size;++i)
if(acct[i]->acc_no==num)
pos=i;
return pos;
}
void bank::create()
{ int i;
acct[size]=new account;
i=size++;
cout<<"\n Enter name of the Depositor";
cin>>acct[i]->name;
cout<<"\n Enter Account Number";
cin>>acct[i]->acc_no;
cout<<"\n Enter Account Type";
cin>>acct[i]->type;
cout<<"\n Enter Deposit Amount";
cin>>acct[i]->bala;
cout<<"\n CREATED: Press any key.....";getch();
}
void bank::deposit() {
int p,num;
cout<<"\n -----DEPOSIT ACCOUNT--------\n";
cout<<"\n Enter Account Number?";
cin>>num;
int pos=search(num);
if(pos<0)
cout<<"\n Account number not found";
else {
int amt1;
cout<<"\n Enter Deposite amount?";
cin>>amt1;
acct[pos]->bala+=amt1;
}
cout<<"\n Press any key....";
getch();
}
void bank::withdraw() {
int num,p;
cout<<"\n ------WITHDRAW ACCOUNT-----------";
cout<<"\n Enter Account Number?";
cin>>num;
int pos=search(num);
if(pos<0)
cout<<"\n Account number not found";
else
{
int amt1;
cout<<"\n Enter Withdraw amount?";
cin>>amt1;
if(acct[pos]->bala-amt1<100)
cout<<"\n can not withdraw balance < 100\n";
else
acct[pos]->bala-=amt1;
}
cout<<"\n Press any key....";
getch();
}
void bank::calculate()
{
int num;
float amt;
cout<<"\n ------CALCULATE ACCOUNT-----\n";
cout<<"\n Enter account no to calculate?";
cin>>num;
int pos=search(num);
if(pos<0)
cout<<"\n Account number not found";
else
acct[pos]->bala+=(acct[pos]->bala*10/100);
cout<<"\n Press any key...";
getch();
}
void bank::display()
{
int num;
cout<<"\n Enter account number?";
cin>>num;
int pos=search(num);
if(pos<0)
cout<<"\n Account Number not found";
else
{
cout<<"\n-------- ACCOUNT HOLDER DETAILS------";
cout<<"\n Depositor Name\t :"<<acct[pos]->name;
cout<<"\n Depositor account number :"<<acct[pos]->acc_no;
cout<<"\n Depositor account type\t :"<<acct[pos]->type;
cout<<"\n Depositor balance :"<<acct[pos]->bala;
}
cout<<"\n Press any key.....";
getch();
}
void main() {
bank b;
int opt,num;
clrscr();
do
{ opt=menu();
switch(opt)
{
case'C':
b.create();
break;
case'D':
b.deposit();
break;
case'W':
b.withdraw();
break;
case'I':
b.calculate();
break;
case'S':
b.display();
break;
}
}while(opt!='Q');
}
OUTPUT
C->Create an Account
D->Deposit an Account
W->Withdraw an Account
I->Calculate an Account
S->Show an Account
Q->Quit program
Enter Your option please?c
Enter name of the Depositormugu
Enter Account Number1234
Enter Account Type savings
Enter Deposit Amount 20000
CREATED: Press any key.....
C->Create an Account
D->Deposit an Account
W->Withdraw an Account
I->Calculate an Account
S->Show an Account
Q->Quit program
Enter Your option please?i
------CALCULATE ACCOUNT-----
Enter account no to calculate?1234

Press any key...


C->Create an Account
D->Deposit an Account
W->Withdraw an Account
I->Calculate an Account
S->Show an Account
Q->Quit program
Enter Your option please?s
Enter account number?1234
-------- ACCOUNT HOLDER DETAILS------
Depositor Name :mugu
Depositor account number :1234
Depositor account type :savings
Depositor balance :22000
Press any key.....
RESULT
Thus the above program is successfully executed.

Ex. No. 11
PRIME NUMBERS

AIM: Program to print Number between 1 to and 50

ALGORITHM:

1. Start the program


2. Create a loop between 1 and 50
3. Create a counter value as zero
4. Check the number if it is divisible by
one and itself.
5. If the above 4th step is true, Increase the counter
as two.
6. Print the values.
7. Stop the Program

PROGRAM
#include<iostream.h>
#include<conio.h>
void main()
{
int flag,i,j;
clrscr();
cout<<"\n PRIME NUMBERS BETWEEN 1 TO 50\n";
for(j=1;j<=50;j++)
{
i=1;
flag=0;
while(i<=j)
{
if(j%i==0)
flag++;
i++;
}
if(flag==2)
cout<<j<<"\tis a prime number\n";
else
continue;
}
getch();
}
OUTPUT
PRIME NUMBERS BETWEEN 1 TO 50
2 is a prime number
3 is a prime number
5 is a prime number
7 is a prime number

11 is a prime number
13 is a prime number
17 is a prime number
19 is a prime number
23 is a prime number
29 is a prime number
31 is a prime number
37 is a prime number
41 is a prime number
43 is a prime number
47 is a prime number

RESULT
Thus the above program is successfully executed.
Ex. No. 12
MATRIX ADDITION AND MULTIPLICATION.

AIM: Program to add and multiply the matrices

ALGORITHM:

1. Start the program


2. Define the sizes of the matrices.
3. Read the values for matrices
4. Add the matrices as C [i] [j] = a[i]
[j] + b[i] [j]
5. Multiply the matrices as c[i] [j] = a[i] [k] + b[k]
[j]
6. Print the matrices.
7. Stop the Program.
PROGRAM
#include<iostream.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],d[3][3];
int i,j,k;
clrscr();
cout<<"\n First matrix\n";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
cout<<"a["<<i<<"]["<<j<<"]";
cin>>a[i][j];
}
cout<<"\n Second matrix\n";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
cout<<"b["<<i<<"]["<<j<<"]";
cin>>b[i][j];
}
//ADDITION
for(i=0;i<3;i++)
for(j=0;j<3;j++)
c[i][j]=a[i][j]+b[i][j];
cout<<"\n Addition matrix\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<"\t"<<c[i][j];
cout<<endl;
}
//MULTIPLICATION
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
d[i][j]=0;
for(k=0;k<3;k++)
d[i][j]=d[i][j]+(a[i][k] * b[k][j]);
}
cout<<"\n Multiplication matrix\n";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<"\t"<<d[i][j];
cout<<endl;
}
getch();
}
OUTPUT
First matrix Second matrix

a[0][0] 1 b[0][0] 1

a[0][1] 2 b[0][1] 2
a[0][2] 3 b[0][2]
3
a[1][0] 4 b[1][0] 4

a[1][1] 5 b[1][1]
5
a[1][2] 6 b[1][2] 6

a[2][0] 7 b[2][0] 7
a[2][1] 8 b[2][1] 8

a[2][2] 9 b[2][2]
9

Addition matrix
2 4 6
8 10 12
14 16 18
Multiplication matrix
30 36 42
66 81 96
102 126 150

RESULT
Thus the above program is successfully executed.
Ex. No. 13
OVERLOADING.

AIM: Program to over load unary minus operator

ALGORITHM:

1. Start the program


2. Read the values.
3. Overload the minus operator in main function sectio
n.
4. Print the values.
5. Stop the Program.
.

PROGRAM
#include<iostream.h>
#include<conio.h>
class ope
{
private:
int a,b;
public:
ope(int x,int y)
{ a=x;
b=y;
}
int operator --() {
return a+b;
}
void display() {
cout<<"\n A="<<a;
cout<<"\n B="<<b;
}
};
void main() {
clrscr();
int a,b,c;
cout<<"\n Enter first number";
cin>>a;
cout<<"\n Enter second number";
cin>>b;
ope o(a,b);
c=--o;
o.display();
cout<<"\n sum is =\t"<<c;
getch();
}
OUTPUT
Enter first number 45
Enter second number 89

A=45
B=89

RESULT
Thus the above program is successfully executed.
Ex. No. 14
SALESMAN HISTORY.
AIM: Program to calculate total sales and average sales made by a salesman

ALGORITHM:

1. Start the program


2. Read the salesman sales in textiles shop.
3. Calculate total sales amount and total quantity.
4. Print the values.
5. Stop the Program.

PROGRAM
#include<iostream.h>
#include<conio.h>
class salesman
{
private:
float sre[100],shi[100],pnt[100];
float bst[100],scr[100];
float tot,avg;
int s,sh,p,b,sc,qty;
float st,sht,pt,bt,sct;
public:
salesman()
{
st=sht=pt=bt=sct=0;
}
void getdata();
void calculate();
void display();
};
void salesman::getdata()
{
int i;
cout<<"\n -----------SAREES----------";
cout<<"\n Enter Total Number of Sarees";
cin>>s;
for(i=1;i<=s;i++)
{
cout<<"\n Enter Saree amount for one by one saree["<<i<<"]";
cin>>sre[i];
st+=sre[i];
}
cout<<"\n -----------SHIRTS----------";
cout<<"\n Enter Total Number of Shirts";
cin>>sh;
for(i=1;i<=sh;i++)
{
cout<<"\n Enter Shirt amount for one by one shirt["<<i<<"]";
cin>>shi[i];
sht+=shi[i];
}
cout<<"\n -----------PANTS----------";
cout<<"\n Enter Total Number of Pants";
cin>>p;
for(i=1;i<=p;i++)
{
cout<<"\n Enter Pant amount for one by one pant["<<i<<"]";
cin>>pnt[i];
pt+=pnt[i];
}
cout<<"\n -----------BED-SHEETS----------";
cout<<"\n Enter Total Number of Bed sheets";
cin>>b;
for(i=1;i<=b;i++)
{
cout<<"\n Enter Bed sheet amount for one by one b_sheet["<<i<<"]";
cin>>bst[i];
bt+=bst[i];
}
cout<<"\n -----------SCREEN CLOTHS----------";
cout<<"\n Enter Total Number of Screen cloths";
cin>>sc;
for(i=1;i<=sc;i++)
{
cout<<"\n Enter Screen cloth amount for one by one cloth["<<i<<"]";
cin>>scr[i];
sct+=scr[i];
}
}
void salesman::calculate()
{
qty=s+sh+p+b+sc;
tot=st+sht+pt+bt+sct;
avg=tot/qty;
}
void salesman::display()
{
cout<<"\n---------------------------------";
cout<<"\n SALES MAN SALES HISTORY";
cout<<"\n --------------------------------";
cout<<"\n Total No.of Qty\t="<<qty;
cout<<"\n Total amount\t\t="<<tot;
cout<<"\n Average sales\t\t="<<avg;
}
void main() {
salesman s;
clrscr();
s.getdata();
s.calculate();
s.display();
getch();
}
OUTPUT
-----------SAREES----------
Enter Total Number of Sarees 2
Enter Saree amount for one by one saree[1] 225.30
Enter Saree amount for one by one saree[2] 230.89
-----------SHIRTS----------
Enter Total Number of Shirts 1
Enter Shirt amount for one by one shirt[1] 123
-----------PANTS----------
Enter Total Number of Pants 1
Enter Pant amount for one by one pant[1] 500
-----------BED-SHEETS----------
Enter Total Number of Bed sheets 1
Enter Bed sheet amount for one by one b_sheet[1] 560
-----------SCREEN CLOTHS----------
Enter Total Number of Screen cloths 1
Enter Screen cloth amount for one by one cloth[1] 263
---------------------------------
SALES MAN SALES HISTORY
--------------------------------
Total No.of Qty =6
Total amount =1902.189941
Average sales =317.031647
RESULT
Thus the above program is successfully executed.

Ex. No. 15
EMPLOYEE REPORT.

AIM: Program to display Employee Report by using single Inheritance.

ALGORITHM:

1. Start the program


2. Create a base class with values
3. Create a derived class with values.
4. Calculate the values of Employee
5. Print the matrices.
6. Stop the Program.
PROGRAM
#include<iostream.h>
#include<conio.h>
class emp
{
public:
char name[40];
float d_hrs,tot_hrs,w_days,pay;
double netpay;
public:
emp()
{
d_hrs=w_days=0;
}
};
class dis:public emp
{
public:
void getdata();
void calculate();
void display();
};

void dis::getdata()
{
cout<<"\n ENTER THE FOLLOWING DETAILS";
cout<<"\n Enter Employee name";
cin>>name;
cout<<"\n Enter No.of daily working Hours";
cin>>d_hrs;
cout<<"\n Enter No.of working days";
cin>>w_days;
cout<<"\n Enter Wages per day";
cin>>pay;
}
void dis::calculate()
{
tot_hrs=d_hrs*w_days;
netpay=tot_hrs *pay;
}
void dis::display()
{
cout<<"\n PAY BILL OF EMPLOYEE FOR A WEEK";
cout<<"\n--------------------------------------";
cout<<"\n NAME \t\t:"<<name;
cout<<"\n TOTAL HOURS WORKED\t:"<<tot_hrs;
cout<<"\n NETPAY\t\t\t:"<<netpay;
}
void main()
{
dis e[10];
char op='y';
int i=1;
clrscr();
while(op=='y')
{
e[i].getdata();
e[i].calculate();
i++;
cout<<"\n DO YOU WANT TO ADD ONE MORE EMPLOYEE'S";
cout<<"DETAIL(y/n)?:";
cin>>op;
}
i=i-1;
for(int j=1;j<=i;j++)
{
e[j].display();
getch();
}
}
OUTPUT
ENTER THE FOLLOWING DETAILS
Enter Employee name MUGUNTHAN

Enter No.of daily working Hours 8


Enter No.of working days 6
Enter Wages per day 99.80
DO YOU WANT TO ADD ONE MORE EMPLOYE
E'SDETAIL(y/n)? :N
PAY BILL OF EMPLOYEE FOR A WEEK
--------------------------------------
NAME : MUGUNTHAN
TOTAL HOURS WORKED : 48
RESULT
Thus the above program is successfully executed.
Ex. No. 16
STUDENT DETAIL.

AIM: Program to display the student details by using pointers.

ALGORITHM:

1. Start the program


2. Dectare pointer variable
3. Read the values.
4. Calculate the values
5. Print the details.
6. Stop the Program.

PROGRAM
#include<iostream.h>
#include<conio.h>
const int MAX=50;
struct details
{
char name[20];
int rno;
int age;
char sex;
float ht;
float wt;
};
class student
{
public:
details * d;
void getdata();
void putdata();
};
void student::getdata()
{
cout<<"Enter Name"<<endl;
cin>>d->name;
cout<<"Enter Roll Number"<<endl;
cin>>d->rno;
cout<<"Enter Age"<<endl;
cin>>d->age;
cout<<"Enter Sex"<<endl;
cin>>d->sex;
cout<<"Enter Height"<<endl;
cin>>d->ht;
cout<<"Enter Weight"<<endl;
cin>>d->wt;
cout<<endl;
}
void student::putdata() {
cout<<"\n------STUDENT DETAILS-------------\n";
cout<< Name = <<d->name<<endl;
cout<<"ROLL NO="<<d->rno<<endl;
cout<<"AGE ="<<d->age<<endl;
cout<<"SEX ="<<d->sex<<endl;
cout<<"HEIGHT ="<<d->ht<<endl;
cout<<"WEIGHT ="<<d->wt<<endl;
cout<<"\n----------------------------------";
}
void main()
{
student s[MAX];
int i,n=0;
char opt;
clrscr();
while(1)
{
s[n].getdata();
n++;
cout<<"\n Continue (y/n):";
cin>>opt;
if(opt=='n')
break;
}
for(i=0;i<n;i++)
s[i].putdata();
getch();
}
OUTPUT
Enter Name aravinth
Enter Roll Number 145
Enter Age 28
Enter Sex m
Enter Height 5.3
Enter Weight 100
Continue (y/n): n
------STUDENT DETAILS-------------
Name = aravinth
ROLL NO = 145
AGE = 28
SEX = m
HEIGHT = 5.3
WEIGHT = 100
----------------------------------
RESULT
Thus the above program is successfully executed.
Ex. No. 17
ASCII VALUE TO CHARACTER.
AIM: Program to Convert ASCII value to character

ALGORITHM:

1. Start the program


2. Read the ASCII value as A .
3. Convert the ASCII to character by using C = A+32
4. Print the character variable C
5. Stop the Program.

PROGRAM
#include<iostream.h>
#include<conio.h>
void main()
{
char c;
int as;
clrscr();
cout<<"\n Enter an ASCII value";
cin>>as;
c=as+32;
cout<<"\n ASCII ="<<c;
getch();
}
OUTPUT
Enter an ASCII value 33
RESULT
Thus the above program is successfully executed.
Ex. No. 18
VOLUME OF CUBE, CYLINDER, RECTANGLE.
AIM: Program to write over loading and find the volume of cube, cylinder, Rectan
gle.

ALGORITHM:

1. Start the program


2. Read the value of a,l,b,h.
3. Calculate the volume for cube by using volume = a
*a*a
4. Calculate the volume for cylinder by u
sing volume = b*h
5. Calculate the volume for Rectangle by using volume =
l*b*h.
6. Print the values.
7. Stop the Program.
PROGRAM
#include<iostream.h>
#include<conio.h>
#include<math.h>
void calc(float a)
{
cout<<"\n Volume of Cube ="<<pow(a,3);
}
void calc(float l,float b,float h)
{
cout<<"\n Volume of Rectangular box="<<l*b*h;
}
void calc(float b,float h)
{
cout<<"\n Volume of Cylinder="<<b*h;
}
void main()
{
float a,l,b,h,b1,h1;
clrscr();
cout<<"\n Enter a side of cube";
cin>>a;
calc(a);
cout<<"\n Enter length,breadth and height of rectangular";
cin>>l>>b>>h;
calc(l,b,h);
cout<<"\n Enter breadth and height of Cylinder";
cin>>b>>h;
calc(b,h);
getch();
}
OUTPUT
Enter a side of cube 4
Volume of Cube =
64
Enter length,breadth and height of rectangular 4 6 8
Volume of Rectangular box= 192
Enter breadth and height of Cylinder 3 9

RESULT
Thus the above program is successfully executed.

Ex. No. 19
MAXIMUM OF TWO NUMBERS
AIM: Program to find the maximum of two numbers by using Template class..

ALGORITHM:
1. Start the program
2. Define the class Template
3. Create a function as max ( T &X, T &Y)
NOTE: T is known as Template class.
4. Read the values.
5. Call the template function.
6. Print the values.
7. Stop the Program

PROGRAM
#include<iostream.h>
#include<conio.h>
template <class T> void max(T &x,T &y)
{
if(x>y)
cout<<x<<"is Big Number"<<endl;
else
cout<<y<<"is big Number"<<endl;
}
void main()
{
int a,b;
clrscr();
cout<<"\n Enter any Two Integers";
cin>>a>>b;
max(a,b);
float c,d;
cout<<"\n Enter any Two float Nos";
cin>>c>>d;
max(c,d);
getch();
}
OUTPUT
Enter any Two Integers 2 6
6is big Number
Enter any Two float Nos 23.21 56.23
56.23is big Number

RESULT
Thus the above program is successfully executed.
Ex.No.1
FAHRENHEIT INTO CELSIUS

AIM: Program to convert Fahrenheit into Celsius conversion.

ALGORITHM:
1. Start the program
2. Read the temperature value for Fahrenheit
3. Calculate the value by using Celsius=(fht-32)*5/9
4. Print the Celsius value
5. Stop the program.
PROGRAM

import java.io.*;
class prog1
{
public static void main(String args[])throws IOException
{
float cent,fht;
System.out.println("Enter Fahrenheit value");
DataInputStream in = new DataInputStream(System.in);
fht=Float.parseFloat(in.readLine());
cent=(fht-32)*5/9;
System.out.println("The Centigrade Equivalent of"+fht+"is ="+cent+"C");
}
}

OUTPUT

C:\j2sdk1.4.0\bin>java prog1
Enter Fahrenheit value
23.56
The Centigrade Equivalent of 23.56 is = -4.6888895C

RESULT
Thus the above program is successfully executed.
Ex.No.2
STUDENT MARK LIST

AIM: Program to prepare the Student mark list

ALGORITHM:
1. Start the program
2. Read the temperature value for Fahrenheit
3. Calculate the value by using Celsius=(fht-32)*5/9
4. Print the Celsius value
5. Stop the program.
PROGRAM
import java.io.*;
import java.lang.*;
class prog2
{
public static void main(String args[])throws IOException
{
String name;
int rno,t,e,m,s,ss,tot;
float avg;
DataInputStream in =new DataInputStream(System.in);
System.out.println("Enter the register number");
rno=Integer.parseInt(in.readLine());
System.out.println("Enter the name");
name=in.readLine();
System.out.println("Enter Tamil mark");
t=Integer.parseInt(in.readLine());
System.out.println("Enter English mark");
e=Integer.parseInt(in.readLine());
System.out.println("Enter Maths mark");
m=Integer.parseInt(in.readLine());
System.out.println("Enter Science mark");
s=Integer.parseInt(in.readLine());
System.out.println("Enter Social mark");
ss=Integer.parseInt(in.readLine());
tot=t+e+m+s+ss;
avg=tot/5;
System.out.println("STUDENT MARKI DETAILS");
System.out.println("**********************");
System.out.println("REGISTER NUMBER:"+rno);
System.out.println("NAME :"+name);
System.out.println("TAMIL :"+t);
System.out.println("ENGLISH :"+e);
System.out.println("MATHS :"+m);
System.out.println("SCIENCE :"+s);
System.out.println("SOCIAL :"+ss);
System.out.println("TOTAL :"+tot);
System.out.println("AVERAGE :"+avg);
}
}

OUTPUT
C:\j2sdk1.4.0\bin>java prog2
Enter the register number
123
Enter the name
mugunthan
Enter Tamil mark
89
Enter English mark
56
Enter Maths mark
74
Enter Science mark
88
Enter Social mark
98
STUDENT MARK DETAILS *
*********************
REGISTER NUMBER : 123
NAME : mugunthan
TAMIL : 89
ENGLISH : 56
MATHS : 74
SCIENCE : 88
SOCIAL : 98
TOTAL : 405
AVERAGE : 81.0

RESULT
Thus the above program is successfully executed.
Ex.No.3
SUM OF DIGITS

AIM: Program to find the sum of individual digits.

ALGORITHM:
1. Start the program
2. Read an Integer
3. Find remainder value
4. Add the Remainder
5. Find the Quotient value
6. If the Quotient is not equal to zero, continue the steps 3 to 6
7. If the Quotient is zero, Print the Sum of digits.
8. Stop the program.

PROGRAM
import java.io.*;
class prog3
{
public static void main(String args[])throws IOException
{
int n,gn;
int r,sum=0,rev=0;
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter Any Integer Number");
n=Integer.parseInt(in.readLine());
gn=n;
while(n!=0)
{
r=n%10;
sum=sum+r;
rev=(rev*10)+r;
n=n/10;
}
System.out.println("Sum of\t"+gn+"\tis ="+sum);
System.out.println("Sum of\t"+gn+"\tis ="+rev);
}
}
OUTPUT
C:\J2SDK1~1.0\bin>java prog3
Enter Any Integer Number 123
Sum of
123 is = 6
Reverse of 123 is = 321

RESULT
Thus the above program is successfully executed.
Ex.No.4

FIBONACCI SERIES

AIM: Program to print the Fibonacci series.

ALGORITHM:

1. Start the program


2. Read an Integer as n
3. Assign th avalue f1=0,f2=1
4. Print the value f1
5. if (f2<n)
6. Add f3=f1+f2
7. Interchange them
f1=f2
f2=f3
8. Print the value f2
9. Stop the program.

PROGRAM
import java.io.*;
class prog4
{
public static void main(String args[])throws IOException
{
int f1=0;
int f2=1;
int f3,n;
DataInputStream in = new DataInputStream(System.in);
System.out.println("Enter an Integer to Generate the value");
n=Integer.parseInt(in.readLine());
System.out.println("Fibbonacci series is......");
System.out.println(f1);
while(f2<=n)
{
System.out.println(f2);
f3=f1+f2;
f1=f2;
f2=f3;
}
}
}

OUTPUT
C:\J2SDK1~1.0\bin>java prog4
Enter an Integer to Generate the value 10
Fibbonacci series is......
0
1
1
2
3
5
8

RESULT
Thus the above program is successfully executed.
Ex.No.5
FACTORIAL

AIM: Program to print the Factorial value of an Integer

ALGORITHM:
1. Start the program
2. Read an Integer Value as n
3. Calculate f= f*n and n=n-1
4. Repeat the above process until n equl to 1.
5. Print the Factorial value
6. Stop the program
PROGRAM
import java.io.*;
class prog5
{
public static void main(String args[])throws IOException
{
int n;
long f=1;
DataInputStream in =new DataInputStream(System.in);
System.out.println("Enter an Integer value");
n=Integer.parseInt(in.readLine());
for(int i=n;i>0;i--)
f*=i;
System.out.println("The Factorial Value of the Number"+n+"is ="+f);
}
}

OUTPUT
C:\J2SDK1~1.0\bin>java prog5
Enter an Integer value
5
The Factorial Value of the Number 5 is = 120
RESULT
Thus the above program is successfully executed.
Ex.No.6
PRIME NUMBER
AIM: Program to find whether a given number is prime or not.

ALGORITHM:
1. Start the program
2. Read an Integer Number
3. Check the Number, If it is divisible by One and Itself.
4. The above 3rd step is true, the given Number is prime otherwise the give
n number is not prime.
5. Print the Number
6. Stop the program

PROGRAM
import java.io.*;
class prog6
{
public static void main(String args[])throws IOException
{
int n,i,flag;
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter Any Integer Number");
n=Integer.parseInt(in.readLine());
flag=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
flag++;
}
if(flag==2)
System.out.println(n+"is a PRIME number");
else
System.out.println(n+"is not a PRIME number");
}
}
OUTPUT
C:\j2sdk1.4.0\bin>java prog6
Enter Any Integer Number
45
45 is not a PRIME number
C:\j2sdk1.4.0\bin>java prog6
Enter Any Integer Number
17
17 is a PRIME number

RESULT
Thus the above program is successfully executed.
Ex.No.7
SORTING
AIM: Program to sort the given numbers in Ascending and Descending order.

ALGORITHM:
1. Start the Program
2. create the class
3. Read the Values to sort by using array variable
4. By using for loop Arrange the Numbers in Ascending Order
5. By using for loop Arrange the Numbers in Descending Order
6. Print the Ascending Order
7. Print the Descending Order
8. Stop the program

PROGRAM
import java.io.*;
class sort
{ int a[]=new int[100];
int i,j,temp,n;
void getdata()
{
DataInputStream in = new DataInputStream(System.in);
try
{
System.out.println("Enter How many Values to Sort");
n=Integer.parseInt(in.readLine());
for(i=0;i<n;i++)
{
System.out.println("Enter the value a["+ i +"]");
a[i]=Integer.parseInt(in.readLine());
}
}
catch(Exception e){}
}
void ascend()
{
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{ if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
void descend()
{ for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
void display()
{ for(i=0;i<n;i++)
System.out.println(a[i]);
}
}
class prog7
{
public static void main(String args[])throws IOException
{ sort s=new sort();
s.getdata();
s.ascend();
System.out.println("ASCENDING ORDER");
s.display();
s.descend();
System.out.println("DESCENDING ORDER");
s.display();
}
}
OUTPUT
C:\j2sdk1.4.0\bin>java prog7
Enter How many Values to Sort 5
Enter the v
alue a[0] 23
Enter the v
alue a[1] 56
Enter the v
alue a[2] 1
Enter the v
alue a[3] 0
Enter the v
alue a[4] 100
ASCENDING O
RDER
0
1
23
56
100
DESCENDING ORDER
100
56
23
1
0

RESULT
Thus the above program is successfully executed.
Ex.No.8
MATRIX MULTIPLICATION
AIM: Program to Multiply the matrix.
ALGORITHM:
1. Start the program
2. Read the values of matrix A
3. Read the values of matrix B
4. Multiply the matrix A and B , and store it in a matrix C
By using c[i][j]=a[i][k] * b[k][j]
5. Print the matrix
6. Stop the Program

PROGRAM
import java.io.*;
class matrix
{
int a[][]=new int[3][3];
int b[][]=new int[3][3];
int c[][]=new int[3][3];
int i,j,k;
void get_matrix()
{
DataInputStream in = new DataInputStream(System.in);
System.out.println("Enter First Matrix");
try{
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
System.out.println("Enter the value a["+i+"]["+j+"]");
a[i][j]=Integer.parseInt(in.readLine());
}
System.out.println("Enter Second Matrix");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
System.out.println("Enter the value b["+i+"]["+j+"]");
b[i][j]=Integer.parseInt(in.readLine());
}
}
catch(Exception e){}
}
void calculate()
{
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
c[i][j]=0;
for(k=0;k<3;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
void display()
{
System.out.println("Multiplication matrix is");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
System.out.print(c[i][j]+"\t");
System.out.print("\n");
}
}
}
class prog8
{
public static void main(String args[])throws IOException
{
matrix m =new matrix();
m.get_matrix();
m.calculate();
m.display();
}
}
OUTPUT
C:\J2SDK1~1.0\bin>java prog8
Enter First Matrix
1 2 3

4 5 6

7 8 9

Enter Second Ma
trix
1 2 3
4 5 6
7 8 9
Multiplication ma
trix is
30 36 42
66 81 96
102 126 150

RESULT
Thus the above program is successfully executed.
Ex.No.9
QUADRATIC EQUATION

AIM: Program to Find the roots of the Quadratic equation

ALGORITHM:

1. Start the program


2. Read the values of a, b and c
3. Calculate s=b2 4 * a * c
4. calculate r1 = -b + sqrt(s) / 2*a
5. Calculate r2 = -b - sqrt(s) / 2 * a
6. Print the Roots and Descriptions
7. Stop the Program
PROGRAM
import java.io.*;
class prog9
{
public static void main(String args[])throws IOException
{
int a,b,c;
int sq;
double r1,r2;
DataInputStream in =new DataInputStream(System.in);
System.out.println("Enter Values of a,b,c(Quadratic Equation)");
a=Integer.parseInt(in.readLine());
b=Integer.parseInt(in.readLine());
c=Integer.parseInt(in.readLine());
sq=b*b-(4*a*c);
r1=-b+ Math.sqrt(sq)/(2*a);
r2=-b- Math.sqrt(sq)/(2*a);
if(sq>0)
System.out.println("ROOTS ARE REAL AND IMAGINARY");
else if(sq<0)
System.out.println("ROOTS ARE IMAGINARY");
else
System.out.println("ROOTS ARE REAL AND EQUAL");
System.out.println("Root1 is ="+r1);
System.out.println("Root2 is ="+r2);
}
}

OUTPUT
C:\J2SDK1~1.0\bin>java prog9
Enter Values of a,b,c(Quadratic Equation)
3 5 6
ROOTS ARE IMAGINARY
Root1 is =NaN
Root2 is =NaN
----------------------------------------------------------------------
C:\J2SDK1~1.0\bin>java prog9
Enter Values of a,b,c(Quadratic Equation)
2 12 3
ROOTS ARE REAL AND IMAGINARY
Root1 is =-9.261387212474169
Root2 is =-14.738612787525831
--------------------------------------------------------------------------
C:\j2sdk1.4.0\bin>java prog9
Enter Values of a,b,c(Quadratic Equation)
3 6 3
ROOTS ARE REAL AND EQUAL
Root1 is =-6.0
Root2 is =-6.0

RESULT
Thus the above program is successfully executed.
Ex.No.10
VOLUME OF SPHERE

AIM: Program to find volume of sphere.

ALGORITHM:

1. Start the program


2. Create class and object
3. Read the radius value of sphere
4. Calculate the volume of sphere by using 4/3 * ?* r3
5. Print the volume of sphere value
6. Stop the program
PROGRAM
import java.io.*;
class sphere
{ double r,v,pi=3.143;
void getdata()
{
try {
DataInputStream in =new DataInputStream(System.in);
System.out.println("Enter radious for sphere");
r=Integer.parseInt(in.readLine());
}
catch(Exception e){}
}
void calculate()
{
v=4/3*pi*r*r*r;
}
void display()
{
System.out.println("Given radious value is ="+r);
System.out.println("Volume of Sphere is ="+v);
}
}
class prog10
{
public static void main(String args[])
{ sphere s= new sphere();
s.getdata();
s.calculate();
s.display();
}
}
OUTPUT
C:\J2SDK1~1.0\bin>java prog10
Enter radious for sphere 3.10
Given radious value is
= 3.1

RESULT
Thus the above program is successfully executed.
Ex.No.11
ARRAY OF OBJECT
AIM:
Program to calculate Employee salary report using Array of object
ALGORITHM:
1. Start the program
2. Create a class and get the employee number, employee name and
employee basic pay
3. Create a interface and set percentage for HRA,PF and DA
4. Create a method to get the employee number, employee name and
employee basic pay
5. Create a method to calculate the employee salary
6. Create a method to show the employee salary detail
7. Create a main class and create array of object for the class
8. Create a separate array of object for each subscript and pass the
employee number, employee name and employee basic pay values in each array subsc
ript object
9. Stop the program
PROGRAM
import java.io.*;
interface salary
{
int hra=10;
int pf=15;
int da=6;
}
class employee implements salary {
private
int eno;
String ename;
int bp;
int np;
employee(int no,String name,int pay) {
eno=no;
ename=name;
bp=pay;
np=bp+((bp*hra)/100)+((bp*pf)/100)+((bp*da)/100);
}
public void put() {
System.out.println("Employee Number="+eno);
System.out.println("Employee Name ="+ename);
System.out.println("Basic Pay="+bp);
System.out.println("Basic Pay="+np);
}
}
class empss {
public static void main(String args[]) {
int i,n;
employee e[]= new employee [3];
e[0] = new employee(1000,"Raj",10000);
e[1] = new employee(1001,"Ram",8000);
e[2] = new employee(1002,"Ravi",7000);
for(i=0;i<3;i++) {
e[i].put();
}
}
}
OUTPUT
1)Save the file as empss.java
2)Compile> javac empss.java
3)Run> java empss
C:\J2SDK1~1.0\bin>java empss
Employee Number=1000
Employee Name =Raj
Basic Pay=10000
Basic Pay=13100
Employee Number=1001
Employee Name =Ram
Basic Pay=8000
Basic Pay=10480
Employee Number=1002
Employee Name =Ravi
Basic Pay=7000
Basic Pay=9170

RESULT
Thus the above program is successfully executed.
Ex.No.12
STACK
AIM:
Program to write stack operation.

ALGORITHM:
1. Start the program
2. Declare and Initialize the array variable
3. Use the operation Push, Pop and Display
4. Insert the value until the Array is full
5. Delete the value until the Array is empty
6. Display the array values for each and every push and
pop
7. Stop the Program

PROGRAM
import java.io.*;
class stack
{
int array[]=new int[4];
int top,c;
stack()
{
top=-1;
}
int isempty() {
return top=-1;
}
void push(int x) {
if(top==3)
System.out.println("STACK FULL");
else
array[++top]=x;
}
void pop() {
if(isempty()==-1)
System.out.println("STACK EMPTY");
else
top--;
}
void display() {
int i;
for(i=top;i>=0;i--)
System.out.println(array[i]);
}
}
class prog12
{
public static void main(String args[])throws IOException
{
stack s= new stack();
int x,opt;
DataInputStream in=new DataInputStream(System.in);
do
{
System.out.println("1->PUSH");
System.out.println("2->POP");
System.out.println("3->DISPLAY");
System.out.println("Enter Your Option");
opt=Integer.parseInt(in.readLine());
if(opt==1)
{
System.out.println("Enter an Element to insert");
x=Integer.parseInt(in.readLine());
s.push(x);
}
if(opt==2)
s.pop();
if(opt==3)
s.display();
}while(opt<4);
}
}

OUTPUT
1->PUSH
2->POP
3->DISPLAY
Enter Your Option
1
Enter an Element to insert 10
1->
PUSH
2->POP
3->DISPLAY
Enter Your Option
1
Enter an Element to insert 9
1-
>PUSH
2->POP
3->DISPLAY
Enter Your Option
1

Enter an Element to insert 8


1->PUSH
2->POP
3->DISPLAY
Enter Your Option
1
Enter an Element to insert
7
1->PUSH
2->POP
3->DISPLAY
Enter Your Option 1
Enter an Elemen
t to insert 6
STACK FULL
1->PUSH
2->POP
3->DISPLAY
Enter Your Option
3
7
8
9
10
1->PUSH
2->POP
3->DISPLAY
Enter Your Option
2
1->PUSH
2->POP
3->DISPLAY
Enter Your Option
2
1->PUSH
2->POP
3->DISPLAY
Enter Your Option
2
1->PUSH
2->POP
3->DISPLAY
Enter Your Option
2

STACK EMPTY

1->PUSH
2->POP
3->DISPLAY
Enter Your Option
3
1->PUSH
2->POP
3->DISPLAY
Enter Your Option
4
c:\j2sdk1.4.0\bin\-

RESULT
Thus the above program is successfully executed
Ex.No.13
PALINDROME
AIM:
Program to check whether the given number is palindrome or not using Abstract cl
ass

ALGORITHM:

1. Start the program


2. Create a base class base and use get method to get the value from the in
put device
3. Create a derived class deriv and extends or inherit the base class metho
d by the super class inside the derived class
4. Create a method to calculate and check whether the given number is pali
ndrome or not
5. Create a main class and create object for the derived class
6. Invoke all the base class method from the derived class object without c
reating object for base class
7. Stop the program

PROGRAM
import java.io.*;
class base
{
protected int n,t,h;
public void get() throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Number=");
n=Integer.parseInt(br.readLine());
t=n;
}
}
class deriv extends base
{
void calculate() throws IOException
{
super.get();
while(n>0)
{
h=h*10+(n % 10);
n=n/10;
}
}
void put()
{
if (h==t)
{
System.out.println("n="+n);
System.out.println("h="+h);
System.out.println("Polindrome");
}
else
{
System.out.println("n="+n);
System.out.println("h="+h);
System.out.println("It is Not Polindrome");
}
}
}
class poli
{
public static void main(String args[]) throws IOException
{
deriv d = new deriv();
d.calculate();
d.put();
}
}

OUTPUT

Enter Number = 456


h
= 654
It is Not Polindrome
Enter Number = 323
h
= 323
RESULT
Thus the above program is successfully executed
Ex.No.14
MULTIPLE INHERITANCE

AIM:
Program to calculate Electricity bill using multiple Inheritance (Interface)

ALGORITHM:
1. Start the program
2. Create a two interface customer and reading declare the methods in the inte
rface
3. Create a class and implements customer and reading interface
4. Get the customer number , customer name , previous reading and
current reading
5. Calculate the bill from readings and show the bill amount in a
method
6. Create a main class and create a object for the class
7. Invoke class methods by the object inside the main function
8. Stop the Program.

PROGRAM
interface customer
{
void getcus(int no,String cname);
}
interface reading
{
void get(int p,int c);
void calculate();
void put();
}
class bill implements customer,reading
{
private int sno;
private String name;
private int cr,pr;
private double r,n,n1;
public void getcus(int no,String cname)
{
sno=no;
name=cname;
}
public void get(int p,int c)
{
pr = p;
cr = c; }
public void calculate()
{
r=(pr-cr);
if (r<200)
n=r*0.50;
else if(r<400)
n=100+(r*0.65);
}
public void put()
{
System.out.println("Cutomer Number="+sno);
System.out.println("Cutomer Name ="+name);
System.out.println("Previous Reading="+pr);
System.out.println("Current Reading="+cr);
System.out.println("Reading="+r);
System.out.println("Reading Rate="+n);
}
}
class exam
{
public static void main(String args[])
{
bill b = new bill();
b.getcus(1000,"Rajkumar");
b.get(400,160);
b.calculate();
b.put();
}
}
OUTPUT
Customer Number = 1000
Customer Name = Rajkumar
Previous Reading = 400
Current Reading = 160
Reading = 240.0
Reading Rate = 256.0

RESULT
Thus the above program is successfully executed
Ex.No.15
PACKAGE, INTERFACE

AIM:
Program to create a calculate area of the triangle and volume of the Sph
ere

ALGORITHM:
1. Start the program
2. Create a new directory mugu in root directory in e:\
3. Create a package with the package name pack in the e:\mugu directory
4. Create a interface and declare the variable constant and values for
public class triangle and implements the interface.
5. Create a public class triangle and calculate the area of the triangle
6. Create a interface and declare the variable constant and values for
public class rectangle and implements the interface.
7. Create a package with the package name subpack in the e:\mugu
directory
8. Create a public class and calculate the area of the rectangle
9.Create a main class and import the two package into the main class
10.Create a object for each package class and invoke the method
11.Stop the program

PROGRAM
1)create a new directory mugu in root directory in e:\
2)type the following code and save it in the mugu directory
package pack;
interface tri
{
int base=7;
int height=10;
}
public class triangle implements tri
{
public static void gettri()
{
float area;
area=(base*height)/2;
System.out.println("Area of Triangle="+area);
}
}
Save as triangle.java
package pack.subpack;
interface rec
{
int lenght=4;
int breadth=12;
}
public class rectangle implements rec
{
public static void getrec()
{
float area;
area=lenght*breadth;
System.out.println("Area of Rectangle="+area);
}
}
/*Save as rectangle.java*/

import pack.triangle;
import pack.subpack.rectangle;
class exa
{
public static void main(String args[])
{
triangle t = new triangle();
rectangle r = new rectangle();
t.gettri();
r.getrec();
}
}
Save as exa.java
Compile as follow
D:\jdk1.3\bin>javac d e:\mugu e:\mugu\triangle.java
D:\jdk1.3\bin>javac d e:\mugu e:\mugu\triangle.java
D:\jdk1.3\bin>set CLASSPATH=e:\mugu
D:\jdk1.3\bin>javac d e:\mugu e:\mugu\exa.java
D:\jdk1.3\bin>java triangle

Ex.No.16
EXCEPTION HANDLING, USER DEFINED EXCEPTION

AIM:

Program to create a Queue implementation using Exception Handling and Us


er
defined Exception.

ALGORITHM:
1. Start the program
2. Declare and Initialize the array variable
3. Use the operation Push, Pop and Display
4. Insert the value until the Array is full
5. Delete the value until the Array is empty
6. Display the array values for each and every push and
pop
7. Stop the Program

PROGRAM
import java.io.*;
class queue
{
int array[]=new int[4];
int top,c;
queue()
{
top=-1;
}
int isempty() {
return top=-1;
}
void push(int x) {
try{
if(top==3)
System.out.println("STACK FULL");
else
array[++top]=x;
}
catch(Exception e) { }
}
void pop() {
if(isempty()==-1)
System.out.println("STACK EMPTY");
else
top--;
}

void display() {
int i;
for(i=0;i<top;i++)
System.out.println(array[i]);
}
}
class prog16 {
public static void main(String args[])throws IOException {
queue q= new queue();
int x,opt;
DataInputStream in=new DataInputStream(System.in);
do {
System.out.println("1->PUSH");
System.out.println("2->POP");
System.out.println("3->DISPLAY");
System.out.println("Enter Your Option");
opt=Integer.parseInt(in.readLine());
if(opt==1)
{
System.out.println("Enter an Element to insert");
x=Integer.parseInt(in.readLine());
q.push(x);
}
if(opt==2)
q.pop();
if(opt==3)
q.display();
}while(opt<4);
}
}

OUTPUT
1->PUSH
2->POP
3->DISPLAY
Enter Your Option 1
Enter an Element to insert 100
1->PUSH
2->POP
3->DISPLAY
Enter Your Option 1
Enter an Element to insert 45
1->PUSH
2->POP
3->DISPLAY
Enter Your Option 3
100
45
1->PUSH
2->POP
3->DISPLAY
Enter Your Option 2
1->PUSH
2->POP
3->DISPLAY
Enter Your Option 3
45
1->PUSH
2->POP
3->DISPLAY
Enter Your Option 4
RESULT
Thus the above program is successfully executed
Ex.No.17
MULTI-THREADING

AIM:
Program to demonstrate a multi threading

ALGORITHM:

1. Start the Program


2. Create a class and implements the Runnable method
3. Create a main thread and two child thread
4. Create a run method to run the thread.
5. Create a class and object to invoke all the methods in the main
class
6. Stop the Program.

PROGRAM
class newthread implements Runnable
{
Thread t;
newthread()
{
t= new Thread(this,"Demo Thread");
System.out.println("Child Thread="+t);
t.start();
}
public void run()
{
try
{
for(int i=5;i>0;i--)
{
System.out.println("Child Thread ="+i);
Thread.sleep(600);
}
}
catch(InterruptedException e)
{
System.out.println("Child Interrupted");
}
}
}
class threaddemo
{
public static void main(String args[])
{
new newthread();
try
{
for(int i=5;i>0;i--)
{
System.out.println("Main Thread ="+i);
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
System.out.println("Main Thread Interrupted");
}
System.out.println("Existing Main Thread");
}
}

OUTPUT
Child Thread=Thread[Demo Thread,5,main]
Main Thread =5
Child Thread =5
Child Thread =4
Main Thread =4
Child Thread =3
Child Thread =2
Main Thread =3
Child Thread =1
Main Thread =2
Main Thread =1
Existing Main Thread
RESULT
Thus the above program is successfully executed
Ex.No.18

IO STREAMS: DATA INPUT STREAM & DATA OUTPUT STREAM

AIM:
Program to demonstrate Railway Reservation System using DataInputStream. and Da
taoutput Stream.
ALGORITHM:
1.Start the program
2.Create a class and declare a datainputstream to get the passenger
information in a method.
3.Get the train number, passenger name and age to calculate the adult,
children and old citizen
4.Calculate the total fare
6.Create a main class and create a object for the class
7.Invoke class methods by the object inside the main function
8.Stop the Program
PROGRAM
import java.io.*;
class rail {
private
int pno;
String pname[]=new String[5];
int age[] = new int[5];
int nop,nopp;
int fare;
int a,c,o,i;
int adult,children,totfare;
public void get() throws IOException {
DataInputStream in = new DataInputStream(System.in);
System.out.println("Enter Pno=");
pno=Integer.parseInt(in.readLine());
System.out.println("Enter No of Passenger=");
nop=Integer.parseInt(in.readLine());
nopp=nop;
i=0;
while(nop>0)
{
System.out.println("Enter Name=");
pname[i]=in.readLine();
System.out.println("Enter Age=");
age[i]=Integer.parseInt(in.readLine());
if(age[i]<=5)
c=c+1;
else if(age[i]>=60)
o=o+1;
else
a=a+1;
nop=nop-1;
i++;
}
System.out.println("Enter Fare=");
fare=Integer.parseInt(in.readLine());
totfare = (c*fare/2)+(o*fare/2)+fare*a;
}
void put()
{
System.out.println("Pno ="+pno);
System.out.println("*****************************************");
for(i=0;i<nopp;i++)
{
System.out.println("PName ="+pname[i]+" | "+"Age="+age[i]);
}
System.out.println("*****************************************");
System.out.println("NoOfPassenger="+nopp);
System.out.println("*****************************************");
System.out.println("Children ="+c+" "+"Adult ="+a+" "+"Old Citizene=
"+o);
System.out.println("****************************************");
System.out.println("Total Fare ="+totfare);
System.out.println("*****************************************");
}
}
class railway {
public static void main(String args[]) throws IOException {
rail rs= new rail();
rs.get();
rs.put();
}
}
OUTPUT
Enter Pno 2
Enter No of Passenger=
2
Enter Name=
mugu
Enter Age=
23
Enter Name=
aravinth
Enter Age=
56
Enter Fare=
123
Pno =2
*****************************************
PName =mugu | Age=23
PName =aravinth | Age=56
*****************************************
NoOfPassenger=2
*****************************************
Children =0 Adult =2 Old Citizene=0
****************************************
Total Fare =246
*****************************************
C:\J2SDK1~1.0\bin>
RESULT
Thus the above program is successfully executed
Ex.No.19
GRAPHICS CLASS

AIM:
Program to display the graphical component using Graphics class

ALGORITHM:
1. Start the program
2. import java io , applet and awt tool
3. Create a class and extends the Applet method
4. Create a paint method with the graphics argument
5. Draw the Graphical component with the graphics argument
6. Assign values for polygon and pass the values as the argument
7. Compile the java program a .class file will be created with the class
name.
8. Create applet code by the applet tag and pass the java .class file as
a argument to the code and assign width and height for applet
window
9. Save the file as that of java class name with .html in the java bin
directory
10. Run applet code with the appletviewer it will display all the
component
11.Stop the program

PROGRAM
import java.io.*;
import java.applet.*;
import java.awt.*;
public class drawshape extends Applet
{
int xs[]={40,49,60,70,57,40,35};
int ys[]={260,310,315,280,260,270,265};
int xss[]={140,150,180,200,170,150, 140};
int yss[]={260,310,315,280,260,270,265};
public void paint (Graphics g)
{
g.drawString("Graphical Component",40,20);
g.drawLine(40,30,200,30);
g.drawRect(40,60,70,40);
g.fillRect(140,60,70,40);
g.drawRoundRect(240,60,70,40,10,20);
g.fillRoundRect(240,60,70,40,10,20);
g.draw3DRect(40,120,70,40,true);
g.drawOval(240,120,70,40);
g.fillOval(40,180,70,40);
g.drawArc(140,180,70,40,0,180);
g.fillArc(240,180,70,40,0,-180);
g.drawPolygon(xs,ys,7);
g.fillPolygon(xss,yss,7);
}
}
1)Save the file as drawshape.java
2)Compile javac drawshape.java
Create Applet code
<body>
<applet code="drawshape.class" width=400 height=400>
</applet>
</body>
1)Save the file as drawshape.html in the java\ bin directory
2)Run appletviewer drawshape.html

OUTPUT

RESULT
Thus the above program is successfully executed
Ex.No.20
DISPLAY AN IMAGE
AIM:
Program to display the image from the file location in the applet window

ALGORITHM:

1. Start the program


2. Import java applet and awt tool
3. Create a class and extends the applet method
4. Create the init method and use the getimage method to get the image from
the location in the paint method
5. Create a paint method with the graphics argument and use drawimage compo
nent to dram the image
6. Create applet code by the applet tag and pass the java .class file as a
argument to the code and assign width and height for applet window
7. Save the file as that of java class name with .html in the java bin dir
ectory
8. Run applet code with the appletviewer it will display the image from t
he location
9. Stop the program

PROGRAM
import java.applet.*;
import java.awt.*;
public class imagedemo extends Applet
{
Image img;
public void init()
{
img=getImage(getCodeBase(),"java.gif");
}
public void paint(Graphics g)
{
g.drawImage(img,10, 10,this);
}
}
1)Save the file as imagedemo.java
2)Compile javac imagedemo.java
Create Applet code
<body>
<applet code="imagedemo.class" width=400 height=400>
</applet>
</body>
1)put a picture java.gif or any other .gif file in the java\bin directory
2)Save the file as imagedemo.html in the java bin directory
3)Run appletviewer imagedemo.html
******************
OUTPUT

RESULT
Thus the above program is successfully executed

Das könnte Ihnen auch gefallen