You are on page 1of 27

EXPERIMENT 01

NUMBER
DATE DAY MON YEAR
LINKED LIST WITH MEMBER FUNCTIONS
TH

AIM : To Write a C++ program to create a class called LIST (linked list)
with member functions to insert an element at the front of
the list as well as to delete an element from the front of the
list. Demonstrate all the functions after creating a list object.
COMPONENTS REQUIREMENT:

APPLICATION SOFTWARE
REQUIREMENT
S.N QUANTIT
SOFTWARE
O. Y
1 Turbo C++ 3.0(32bit) 1 nos
SYSTEM SOFTWRAE REQUIREMENT
S.N QUANTIT
OPERATING SYSTEM
O. Y
1 Windows XP Service Pack 2 1 nos
HARDWARE REQUIREMENT
S.N QUANTIT
DEVICE
O. Y
Running PC with Windows
1 1 nos
XP

PROGRAM:

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
class LIST
{
private:int x;
LIST *link,*start;
public: LIST(int&data)
{
x=data;
link=0;
}
LIST()
{
start=NULL;
}
void insert_item();
int delete_item();

1
void display();
};
void LIST:: insert_item()
{
int num;
LIST *temp;
cout<<"\nEnter the Number:";
cin>>num;
temp=new LIST(num);
if(start==NULL)
{
start=temp;
}
else
{
temp->link=start;
start=temp;
}
}
int LIST::delete_item()
{
int d;
if(start==NULL)
{
return-1;
}
else
{
d=start->x;
start=start->link;
return(d);
}
}
void LIST::display()
{
LIST*temp;
cout<<"ROOT->";
for(temp=start;temp!=NULL;temp=temp->link)
cout<<temp->x<<"->";
cout<<"NULL"<<endl;
}
void main ()
{
int choice=0,num;
LIST my_list;
clrscr();
cout<<"***LINKED LIST WITH MEMBER FUNCTION***\n";
while(choice!=3)
{
clrscr();
cout<<"\n1:To Inseart an Element.\n";
cout<<"\n2:To Delete an Element.\n";
cout<<"\n3:Exit\n";
cout<<"\nEnter your Choice:";
cin>>choice;

2
switch(choice)
{
case 1:my_list.insert_item();
cout<<"\nThe List:";
my_list.display();
break;
case 2:num=my_list.delete_item();
if(num==-1)
cout<<"\nEmpty List \n";
else
{
cout<<"\nThe Deleted Item:"<<num<<endl;
cout<<"\nThe List:";
my_list.display();
}
break;
case 3:exit(0);
}
getch();
}
}

RESULT:

Thus we have created a C++ program using class called LIST (linked list) with
member functions to insert an element at the front of the list as well as to delete an
element from the front of the list. Demonstrate all the functions after creating a list object.

3
EXPERIMENT 02
NUMBER
DATE DAY MON YEAR
BANKING SYSTEM
TH

AIM : To Write a C++ program on BANKING SYSTEM that has account


class with data members like account number, name,
deposit, withdraw amount and type of account. A
customer can deposit and withdraw amount in his
account. User can create, modify and delete account.
COMPONENTS REQUIREMENT:
APPLICATION SOFTWARE
REQUIREMENT
S.N
SOFTWARE QUANTITY
O.
1 Turbo C++ 3.0(32bit) 1 nos
SYSTEM SOFTWRAE REQUIREMENT
S.N
OPERATING SYSTEM QUANTITY
O.
Windows XP Service Pack
1 1 nos
2
HARDWARE REQUIREMENT
S.N
DEVICE QUANTITY
O.
Running PC with Windows
1 1 nos
XP

PROGRAM:

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class bank
{
private:
int ac_no,account;
float balance;
char name[20];
public:
void open(void);
void deposite(int);
void withdraw(int);
void search(int);
void display(void);
};
void bank::open(void)

No
{
cout<<"ENTER YOUR NAME : ";
cin>>name;
cout<<"ENTER YOUR ACCOUNT NUMBER : ";
cin>>account;
cout<<"ENTER THE AMOUNT OF MONEY : BDT ";
cin>>balance;
}
void bank::deposite(int j)
{
int bnc;

if(account==j)
{
cout<<"ENTER THE AMOUNT OF MONEY : BDT ";
cin>>bnc;
balance=balance+bnc;
cout<<"\n\n\tJOB HAS DONE WELL !!! \n";
}
}
void bank::withdraw(int k)
{
int blnc,p;

if(account==k)

{
cout<<"YOUR CURRENT ACCOUNT BALANCE IS BDT "<<balance<<"\n"<<"THE
AMOUNT OF MONEY YOU WANT TO WITHDRAW IS BDT ";
cin>>blnc;
p=balance-blnc;
{ if(p<0)
cout<<"SORRY !!! THERE IS NOT ENOUGH MONEY IN YOUR ACCOUNT\n";
else if(p>=0)
{
cout<<"\n\tYOUR REQUEST TO WITHDRAW MONEY HAS DONE\n\n";
balance=p;
}

}
}

}
void bank::display(void)
{ cout<<"\n\nNAME : "<<name<<"\n\nACCOUNT NO. "<<account<<"\n\nBALANCE :
BDT "<<balance<<"\n\n";
}
void bank::search(int m)
{
if(account==m)
{
cout<<"\n\n*******Account Holder's INFO*******";
cout<<"\n\nNAME : "<<name<<"\n\nACCOUNT NO. "<<account<<"\n\nBALANCE :
BDT "<<balance<<"\n\n";
cout<<"\n***************************************\n\n";

5
}
}
void main()
{
int i,j,k,m,l,y=0;
bank b[20];
int index;
textcolor(0);
textbackground(4);
clrscr();
do
{
cout<<"\a\nPRESS 1 TO OPEN ACCOUNT\n\n"<<"PRESS 2 TO DEPOSITE
AMOUNT\n\n"<<"PRESS 3 TO WITHDRAW MONEY \n\n"<<"PRESS 4 TO DISPLAY
\n\n"<<"PRESS 5 TO SEARCH \n\n"<<"PRESS 6 TO EXIT \n\n\t\n";
cout<<"Your option......";
cin>>index;
switch(index)
{
case 1:
cout<<"\nHOW MANY ACCOUNT YOU WANT TO OPEN?\n"; //opening account
cin>>y;
for(i=0;i<y;i++)
b[i].open();
break;
case 2:
cout<<"\nENTER YOUR ACCOUNT NO. "; //deposite amount
cin>>j;
for(i=0;i<y;i++)
{
b[i].deposite(j);
}
break;
case 3:
cout<<"\nENTER YOUR ACCOUNT NO. "; //withdraw money
cin>>k;
for(i=0;i<y;i++)
{
b[i].withdraw(k);
}
break;
case 4:
for(i=0;i<y;i++)
{ //display option
b[i].display();
}
break;
case 5:
cout<<"\nENTER YOUR ACCOUNT NO. "; //search option
cin>>m;
for(i=0;i<y;i++)
{
b[i].search(m);
}
break;

6
case 6:
break;
default:cout<<"\nYOU HAVE PRESSED THE WRONG KEY. PLEASE TRY AGAIN. \n\n\n";
break;
}
} while(index!=6);
}

RESULT:

Thus we have created a C++ program on BANKING SYSTEM that has account class
with data members like account number, name, deposit, withdraw amount and type of
account. A customer can deposit and withdraw amount in his account. User can create,
modify and delete account.

7
EXPERIMENT 03
NUMBER
DATE DAY MON YEAR COMPUTING NET SALARY
TH

AIM : To Write a C++ program to read the data of N employee and compute Net
salary of each employee (DA=52% of Basic and Income Tax (IT) =30%
of the gross salary).

COMPONENTS REQUIREMENT:
APPLICATION SOFTWARE
REQUIREMENT
S.N
SOFTWARE QUANTITY
O.
1 Turbo C++ 3.0(32bit) 1 nos
SYSTEM SOFTWRAE REQUIREMENT
S.N
OPERATING SYSTEM QUANTITY
O.
Windows XP Service Pack
1 1 nos
2
HARDWARE REQUIREMENT
S.N
DEVICE QUANTITY
O.
Running PC with Windows
1 1 nos
XP
PROGRAM:-
#include<iostream.h>
#include<conio.h>
class employee
{
private :
intempno;
char name[20];
float basic,da,it,net_sal,gross_sal;
public :
void readdata();
void cal();
void putdata();
};
void employee :: readdata()
{
cout<<"Enter the Emp_No. :";
cin>>empno;
cout<<"Enter the Employee Name :";

8
cin>>name;
cout<<"Enter the Basic Pay :";
cin>>basic;
}
void employee :: cal()
{
da=basic*0.52;
gross_sal=basic+da;
it=gross_sal*0.30;
net_sal=gross_sal-it;
}
void employee :: putdata()
{
cout<<"Emp_No :"<<empno<<"\n";
cout<<"Name :"<<name<<"\n";
cout<<"Basic :"<<basic<<"\n";
cout<<"Emp_Da(52%) :"<<da<<"\n";
cout<<"Gross salary :"<<gross_sal<<"\n";
cout<<"Income Tax(30%) :"<<it<<"\n";
cout<<"Net salary :"<<net_sal<<"\n";
}
void main()
{
employee emp[20];
inti,n;
clrscr();
cout<<"**EMPLOYEES DETAILS**\n";
cout<<"Enter the Number of Employee :";
cin>>n;
for(i=1;i<=n;i++)
{
emp[i].readdata();
cout<<"\n";
}
for(i=1;i<=n;i++)
{
emp[i].cal();
}
for(i=1;i<=n;i++)
{
cout<<"\nInfo of "<<i<<" Employee\n";
emp[i].putdata();
getch();
}
}

RESULT:

Thus we have created a C++ program to read the data of N employee and compute
Net salary of each employee (DA=52% of Basic and Income Tax (IT) =30% of the
gross salary)

9
EXPERIMENT 04
NUMBER
DATE DAY MON YEAR
ADDING COMPLEX NUMBERS
TH

AIM : To Write a C++ program to create a class called COMPLEX and


implement the following overloading functions ADD that return a
COMPLEX number.
ADD(a, s2)-where a is an integer part (real part) and s2 is a
complex number.
ADD(s1, s2)-where s1 and s2 are complex numbers.
COMPONENTS REQUIREMENT:
APPLICATION SOFTWARE
REQUIREMENT
S.N
SOFTWARE QUANTITY
O.
1 Turbo C++ 3.0(32bit) 1 nos
SYSTEM SOFTWRAE REQUIREMENT
S.N
OPERATING SYSTEM QUANTITY
O.
Windows XP Service Pack
1 1 nos
2
HARDWARE REQUIREMENT
S.N
DEVICE QUANTITY
O.
Running PC with Windows
1 1 nos
XP

PROGRAM:

#include<iostream.h>
#include<conio.h>
class Complex
{
floatreal,imag;

public:
void read()
{
cout<<"\nEnter real and imaginary part:\n";
cin>>real>>imag;

10
}
friend Complex ADD(Complex,Complex);
friend Complex ADD(int,Complex);
friendostream& operator<<(ostream&,Complex);
};
ostream& operator<<(ostream&out,Complex c)
{
out<<c.real<<" + i "<<c.imag;
return(out);
}
Complex ADD(Complex c1,Complex c2)
{
Complex c3;
c3.real=c1.real+c2.real;
c3.imag=c1.imag+c2.imag;
return(c3);
}
Complex ADD(inta,Complex c2)
{
Complex c3;
c3.real=a+c2.real;
c3.imag=c2.imag;
return(c3);
}
int main()
{
Complex s1,s2,s3,s4;
int a;
clrscr();
cout<<"\nEnter 1st complex number:\n";
s1.read();
cout<<"\nEnter 2nd complex number:\n";
s2.read();
s3=ADD(s1,s2); // s3.ADD(s1,s2);
cout<<"\nAddition of "<<s1<<" and "<<s2<<" is "<<s3<<endl;
cout<<"\nEnter an integer number, to be added with complex number
"<<s2<<endl;
cin>>a;
s4=ADD(a,s2); // s4.ADD(a,s2);
cout<<"Addition of "<<a<<" and "<<s2<<" is "<<s4<<endl;
getch();
return 0;
}

RESULT:

Thus we have created a C++ program to create a class called COMPLEX and implement
the following overloading functions ADD that return a COMPLEX number.

11
ADD(a, s2)-where a is an integer part (real part) and s2 is a
complex number.
ADD(s1, s2)-where s1 and s2 are complex numbers

EXPERIMENT 05
NUMBER
DATE DAY MON YEAR
HIERARCHICAL INHERITANCE
TH

AIM : To write C++ Program using Hierarchical Inheritance with base as


vehicle and derived class as two wheeler, four wheeler,
scooter and car with required data member.
COMPONENTS REQUIREMENT:
APPLICATION SOFTWARE REQUIREMENT
S.N
SOFTWARE QUANTITY
O.
1 Turbo C++ 3.0(32bit) 1 nos
SYSTEM SOFTWRAE REQUIREMENT
S.N
OPERATING SYSTEM QUANTITY
O.
1 Windows XP Service Pack 2 1 nos
HARDWARE REQUIREMENT
S.N
DEVICE QUANTITY
O.
Running PC with Windows
1 1 nos
XP
PROGRAM

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<process.h>
class LIST
{
private:int x;
LIST *link,*start;
public: LIST(int&data)

12
{
x=data;
link=0;
}
LIST()
{
start=NULL;
}
void insert_item();
int delete_item();
void display();
};
void LIST:: insert_item()
{
int num;
LIST *temp;
cout<<"\nEnter the Number:";
cin>>num;
temp=new LIST(num);
if(start==NULL)
{
start=temp;
}
else
{
temp->link=start;
start=temp;
}
}
int LIST::delete_item()
{
int d;
if(start==NULL)
{
return-1;
}
else

13
{
d=start->x;
start=start->link;
return(d);
}
}
void LIST::display()
{
LIST*temp;
cout<<"ROOT->";
for(temp=start;temp!=NULL;temp=temp->link)
cout<<temp->x<<"->";
cout<<"NULL"<<endl;
}
void main()
{
int choice=0,num;
LIST my_list;
clrscr();
cout<<"***LINKED LIST WITH MEMBER FUNCTION***\n";
while(choice!=3)
{
clrscr();
cout<<"\n1:To Inseart an Element.\n";
cout<<"\n2:To Delete an Element.\n";
cout<<"\n3:Exit\n";
cout<<"\nEnter your Choice:";
cin>>choice;
switch(choice)
{
case 1:my_list.insert_item();
cout<<"\nThe List:";
my_list.display();
break;
case 2:num=my_list.delete_item();
if(num==-1)
cout<<"\nEmpty List \n";

14
else
{
cout<<"\nThe Deleted Item:"<<num<<endl;
cout<<"\nThe List:";
my_list.display();
}
break;
case 3:exit(0);
}
getch();
}
}

RESULT:

Thus we have created C++ Program using Hierarchical Inheritance with base as
vehicle and derived class as two wheeler, four wheeler, scooter and car with
required data member.

15
EXPERIMENT 06
NUMBER
DATE DAY MON YEAR
FAHRENHEIT TO CELSIUS CONVERSION
TH

AIM : To write a program such that it involves all the operators and its
functions and to Convert Fahrenheit to Celsius using java.

COMPONENTS REQUIREMENT:
APPLICATION SOFTWARE REQUIREMENT
S.N
SOFTWARE QUANTITY
O.
1 JDK 1.6 1 nos
SYSTEM SOFTWRAE REQUIREMENT
S.N
OPERATING SYSTEM QUANTITY
O.
1 Windows XP Service Pack 2 1 nos
HARDWARE REQUIREMENT
S.N
DEVICE QUANTITY
O.
Running PC with Windows
1 1 nos
XP

PROGRAM

import java.util.Scanner;
public class Test {
public static void main(String [] args)
{
Scanner scan = new Scanner(System.in);
String tempScale = "";
System.out.print("Enter the current outside temperature: ");
double temps = scan.nextDouble();
System.out.println("Celsius or Fahrenheight (C or F): ");
int input = scan.nextInt();
if (input == F) {

16
// convert F to C
temps = (temps-32) * 5/9.0;
tempScale = "Celsius.";
} else if (input == 'C') {
// convert C to F
temps = (temps * 9/5.0) +32;
tempScale = "Fahrenheit.";
}//end if/else

RESULT:

Thus we have created a program such that it involves all the operators and its
functions and to Convert Fahrenheit to Celsius using java.

17
EXPERIMENT 07
NUMBER
DATE DAY MON YEAR
LARGEST NUMBERS
TH

AIM : To write a java to find the largest numbers using if else statement
and to sort the given numbers using Arrays.
COMPONENTS REQUIREMENT:
APPLICATION SOFTWARE REQUIREMENT
S.N
SOFTWARE QUANTITY
O.
1 JDK 1.6 1 nos
SYSTEM SOFTWRAE REQUIREMENT
S.N
OPERATING SYSTEM QUANTITY
O.
1 Windows XP Service Pack 2 1 nos
HARDWARE REQUIREMENT
S.N
DEVICE QUANTITY
O.
Running PC with Windows
1 1 nos
XP

PROGRAM
import java.util.Scanner;
class LargestOfThreeNumbers
{
public static void main(String args[])
{
int x, y, z;
System.out.println("Enter three integers ");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
z = in.nextInt();
if ( x > y && x > z )
System.out.println("First number is largest.");
else if ( y > x && y > z )
System.out.println("Second number is largest.");

18
else if ( z > x && z > y )
System.out.println("Third number is largest.");
else
System.out.println("Entered numbers are not distinct.");
}
}

RESULT:

Thus we have created a java to find the largest numbers using if else
statement and to sort the given numbers using Arrays.

19
EXPERIMENT 08
NUMBER
DATE DAY MON YEAR
INHERITANCE
TH

AIM : To write a java program to implements inheritance.

COMPONENTS REQUIREMENT:
APPLICATION SOFTWARE REQUIREMENT
S.N
SOFTWARE QUANTITY
O.
1 JDK 1.6 1 nos
SYSTEM SOFTWRAE REQUIREMENT
S.N
OPERATING SYSTEM QUANTITY
O.
1 Windows XP Service Pack 2 1 nos
HARDWARE REQUIREMENT
S.N
DEVICE QUANTITY
O.
Running PC with Windows
1 1 nos
XP

PROGRAM
class Box {

double width;
double height;
double depth;
Box() {
}
Box(double w, double h, double d) {
width = w;
height = h;
depth = d;
}
void getVolume() {
System.out.println("Volume is : " + width * height * depth);
}
}

20
public class MatchBox extends Box {

double weight;
MatchBox() {
}
MatchBox(double w, double h, double d, double m) {
super(w, h, d);
weight = m;
}
public static void main(String args[]) {
MatchBox mb1 = new MatchBox(10, 10, 10, 10);
mb1.getVolume();
System.out.println("width of MatchBox 1 is " + mb1.width);
System.out.println("height of MatchBox 1 is " + mb1.height);
System.out.println("depth of MatchBox 1 is " + mb1.depth);
System.out.println("weight of MatchBox 1 is " + mb1.weight);
}
}

RESULT:

Thus we have created a java program to implements inheritance.

EXPERIMENT 09 MULTITHREAD PROGRAMMING

NUMBER

21
DATE DAY MON YEAR
TH

AIM : To Write a java program to implements multithread programming.

COMPONENTS REQUIREMENT:
APPLICATION SOFTWARE REQUIREMENT
S.N
SOFTWARE QUANTITY
O.
1 JDK 1.6 1 nos
SYSTEM SOFTWRAE REQUIREMENT
S.N
OPERATING SYSTEM QUANTITY
O.
1 Windows XP Service Pack 2 1 nos
HARDWARE REQUIREMENT
S.N
DEVICE QUANTITY
O.
Running PC with Windows
1 1 nos
XP
PROGRAM
/* MathThreads.java: A program with multiple threads performing concurrent
operations. */
import java.lang.Math;
class MathSin extends Thread {
public double deg;
public double res;
public MathSin(int degree) {
deg = degree;
}
public void run() {
System.out.println(Executing sin of +deg);
double Deg2Rad = Math.toRadians(deg);
res = Math.sin(Deg2Rad);
System.out.println(Exit from MathSin. Res = +res);
}
}
class MathCos extends Thread {
public double deg;
public double res;
public MathCos(int degree) {

22
deg = degree;
}
public void run() {
System.out.println(Executing cos of +deg);
double Deg2Rad = Math.toRadians(deg);
res = Math.cos(Deg2Rad);
System.out.println(Exit from MathCos. Res = +res);
}
}
class MathTan extends Thread {
public double deg;
public double res;
public MathTan(int degree) {
deg = degree;
}
public void run() {
System.out.println(Executing tan of +deg);
double Deg2Rad = Math.toRadians(deg);
res = Math.tan(Deg2Rad);
System.out.println(Exit from MathTan. Res = +res);
}
}
class MathThreads {
public static void main(String args[]) {
MathSin st = new MathSin(45);
MathCos ct = new MathCos(60);
MathTan tt = new MathTan(30);
st.start();
ct.start();
tt.start();
try { // wait for completion of all thread and then sum
st.join();
ct.join(); //wait for completion of MathCos object
tt.join();
double z = st.res + ct.res + tt.res;
System.out.println(Sum of sin, cos, tan = +z);
}

23
catch(InterruptedException IntExp) {
}
}

RESULT:

Thus we have created a java program to implements multithread programming.

EXPERIMENT 10
NUMBER
SERVER AND CLIENT
DATE DAY MON YEAR
TH

AIM : To write a java program to establishes connection between server and client.

24
COMPONENTS REQUIREMENT:
APPLICATION SOFTWARE REQUIREMENT
S.N
SOFTWARE QUANTITY
O.
1 JDK 1.6 1 nos
SYSTEM SOFTWRAE REQUIREMENT
S.N
OPERATING SYSTEM QUANTITY
O.
1 Windows XP Service Pack 2 1 nos
HARDWARE REQUIREMENT
S.N
DEVICE QUANTITY
O.
Running PC with Windows
1 1 nos
XP
PROGRAM
Server.java:
import java.net.*;
import java.io.*;
import java.util.*;

class server
{
public static void main(String args[])
{
ServerSocket ss;
Socket s;
PrintStream ps;
DataInputStream dis;
String inet;
try
{
ss=new ServerSocket(8020);
while(true)
{
s=ss.accept();
ps=new PrintStream(s.getOutputStream());
Date d=new Date();
ps.println(d);
dis=new DataInputStream(s.getInputStream());

25
inet=dis.readLine();
System.out.println(" The client system address is : " +inet);
}
}
catch(IOException e)
{
System.out.println("The Exception is :" +e);
}
}
}

Client.java
import java.net.*;
import java.io.*;
class client
{
public static void main(String args[]) throws Exception
{
Socket soc;
DataInputStream dis;
String sdate;
PrintStream os;
InetAddress ia=InetAddress.getLocalHost();
soc=new Socket(ia,8020);
dis=new DataInputStream(soc.getInputStream());
sdate=dis.readLine();
System.out.println("The date in the server is :"+sdate);
ps=new PrintStream(soc.getOutputStream());
ps.println(ia);
}
}

26
RESULT:

Thus we have created a java program to establishes connection between server and client

27

You might also like