Professional Documents
Culture Documents
2.CLASS EMPLOYEE
AIM:
To calculate the net salary of an employee using constructors.
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class employee
{
int empno;
char ename[20];
float basic,da,hra,ded,netsal;
public:
employee()
{empno=100;
strcpy(ename,"ram");
basic=5000;
da=1000;
}
void input()
{
cout<<"\n Enter employee number: ";
cin>>empno;
cout<<"\n Enter employee name: ";
gets(ename);
cout<<"\n Enter basic,da,hra ";
cin>>basic>>da>>hra;
cout<<"\n Enter deduction: ";
cin>>ded;
}
void calculate()
{
netsal=(basic+da+hra)-ded;
}
void output()
{
cout<<"\n Employee details";
cout<<"\n Employee number: "<<empno;
cout<<"\n Employee name: "<<ename;
cout<<"\n Basic: "<<basic<<"\n Da:"<<da<<"\n Hra:"<<hra<<"\n Ded:"<<ded;
cout<<"\n Net salary:"<<netsal;
}};
void main()
{
clrscr();
employee e1;
e1.input();
e1.calculate();
e1.output();
getch();
}
3.INHERITANCE
AIM:
To implement multiple inheritance.
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class person
{
public:
char name[20];
char address[80];
void input()
{
cout<<"\n Enter name: ";
gets(name);
cout<<"\n Enter address: ";
gets(address);
}
void output()
{
cout<<"\n Name: "<<name;
cout<<"\n Address: "<<address;
}
};
class student
{
public:
int Class;
int total;
void enter()
{
cout<<"\n Enter class:";
cin>>Class;
cout<<"\nEnter the total marks";
cin>>total;
}
void display()
{cout<<"\n Student belongs to"<<Class;
cout<<"\nThe total is"<<total;
}
};
class details:public person,public student
{
char grade;
public:
void assign()
{
if (total>=90)
grade='A';
else if(total>=80 && total<90)
grade='B';
else if(total>=70 && total<80)
grade='C';
else
grade='D';
cout<<"\n The Grade is"<<grade;
}
};
void main()
{
clrscr();
details d;
d.input();
d.enter();
cout<<"\n Student details";
d.output();
d.display();
d.assign();
getch();
}
}
8.LINEAR SEARCH
AIM:
To search for a particular element in an array using linear search technique
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a[20],n,ele,i,p,flag=0;
cout<<"\n Enter the size of the array:";
cin>> n;
cout<<"\n Enter the array elements:";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"\n Enter the elements to be searched for:";
cin>>ele;
for(i=0;i<n;i++)
{
if(a[i]==ele)
{
cout<<"\n Element found at “<<i+1;
flag=1;
break;
}
}
if(flag==0)
cout<<"\n Element not found ";
getch();}
9.BINARY SEARCH
AIM:
To search for a particular element in an array using Binary search technique
Source code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a[20],ele,n,i,p,flag=0, beg,mid,end;
cout<<"\n Enter the size of array:";
cin>>n;
cout<<"\n Enter array elements:";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"\n Enter the element to search :";
cin>>ele;
beg=0;
end=n-1;
while(beg<=end)
{
mid=(beg+end)/2;
if(a[mid]==ele)
{
cout<<"Element found"<<mid+1;
flag=1;
break;
}
else if(ele>a[mid])
beg=mid+1;
else
end=mid-1;
}
if(flag==0)
cout<<"\n Element not found";
getch();
}
10.ARRAY INSERTION
AIM:
To add a new element at a specific loctation in a 1-D array
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10],i,m,n,loc,ele,pos;
cout<<"\n Enter the array size:";
cin>>n;
cout<<"\n Enter the array elements";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"\n Enter the location where the element need to be inserted\n";
cin>>loc;
cout<<"\n Enter the element to be added";
cin>>ele;
loc=loc-1;
m=n;
while(loc<m)
{
a[m]=a[m-1];
m--;
}
a[loc]=ele;
n=n+1;
cout<<" \n Array after insertion is ";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
getch();
}
11.ARRAY DELETION
AIM:
To delete an element from specific location in a 1-D array
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10],i,n,loc;
cout<<"\n Enter the array size:";
cin>>n;
cout<<"\n Enter the array elements";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"\n Enter the location of the element need to be deleted";
cin>>loc;
loc=loc-1;
while(loc<n-1)
{
a[loc]=a[loc+1];
loc++;
}
n=n-1;
cout<<" \n Array after deletion is ";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
getch();
}
12.BUBBLE SORT
AIM:
To arrange array element in ascending order using bubble sort.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a[50],i,size,j,temp;
cout<<"\n Enter the array size:";
cin>>size;
cout<<"\n Enter the array elements";
for(i=0;i<size;i++)
cin>>a[i];
for(i=0;i<size;i++)
for(j=0;j<size-1;j++)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
cout<<" The sorted array is ";
for(i=0;i<size;i++)
cout<<a[i]<<" ";
getch();
}
SOURCE CODE:
13.MERGE SORT
AIM:To merge two increasingly arranged arrays into the third array in ascending
order
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a[10],b[10],c[20];
int m,n,i,j,k;
cout<<"\n Enter the size of 1st array(max10)=";
cin>>m;
cout<<"\n Enter the size of 2nd array(max10) ";
cin>>n;
cout<<"\n Enter the first array elements in ascending order ";
for(i=0;i<m;i++)
cin>>a[i];
cout<<"\n Enter the second array elements in ascending order ";
for(j=0;j<n;j++)
cin>>b[j];
i=j=k=0;
while(i<m&&j<n)
{
if(a[i]<b[j])
{
c[k]=a[i];
i++;
k++;
}
else
{
c[k]=b[j];
k++;
j++;
}
}
while (i<m)
{
c[k]=a[i];
k++;
i++;
}
while(j<n)
{
c[k]=b[j];
k++;
j++;
}
cout<<"\n The merged array is :";
for(i=0;i<m+n;i++)
cout<<c[i]<<" ";
getch();
}
if(top==-1)
cout<<"\n Stack is empty cant display";
for(int i=top;i>=0;i--)
cout<<a[i]<<"\t";
break;
case 4:
exit(0);
break;
default: cout<<"\n Invalid input";
}
cout<<"\nEnter y/Y to continue";
cin>>ch;
}while(ch=='y'||ch=='Y');
getch();
}
18.LINEAR QUEUE
AIM:
To Implement push,pop and display operations in an array queue.
SOURCE CODE:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
const int size=25;
void main()
{
clrscr();
int a[50];
int front,rear,ele,result;
front=-1;
rear=-1;
char ch='Y';
int choice;
do
{
cout<<"\nMENU\n 1.INSERT \n 2.DELETE \n 3.DISPLAY \n 4.EXIT";
cout<<"\n Enter your choice ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter the element :";
cin>>ele;
if(rear==size-1)
cout<<"\n Queue full.Cannot insert";
else
{
if(rear==-1)
front=rear=0;
else
rear++;
a[rear]=ele;
}
break;
case 2:
if(front==-1)
cout<<"Empty";
else
{
cout<<"\nDeleted Element is " <<a[front];
if(front==rear)
front=rear=-1;
else
front++;
}
break;
case 3:
if(front==-1)
cout<<"Empty";
else
{
cout<<"\n Elements are ";
for(int i=front;i<=rear;i++)
cout<<a[i]<<"\t";
}
break;
case 4:
exit(0);
break;
default:
cout<<"\n Invalid input";
}
cout<<"\n Enter y/Y to continue";
cin>>ch;
}while(ch=='y' || ch=='Y');
getch();
}
19.LINKED STACK
AIM:
To Implement push,pop and display operations in a linked stack.
SOURCE CODE:
#include<iostream.h>
#include<process.h>
#include<stdio.h>
#include<conio.h>
struct node
{
int data;
node *link;
};
node *temp,*top;
void main()
{
clrscr();
int result;
char ch='Y';
int choice;
do
{
cout<<"MENU\n1.PUSH\n2.POP\n3.DISPLAY\n4.EXIT";
cout<<"\nEnter your choice";
cin>>choice;
switch(choice)
{
case 1:
temp=new node;
cout<<"Enter the value";
cin>>temp->data;
temp->link=NULL;
if(top==NULL)
top=temp;
else
{
temp->link=top;
top=temp;
}
break;
case 2:
if(top==NULL)
cout<<"\n Empty";
else
{
temp=top;
cout<<"Deleted value is"<<temp->data;
top=top->link;
delete temp;
}
break;
case 3:
if(top==NULL)
cout<<"\nEmpty";
else
{
temp=top;
cout<<"\n The values are";
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->link;
}
}
break;
case 4:
exit(0);
break;
default:
cout<<"\nInvalid input";
}
cout<<"\nPress y/Y to continue";
cin>>ch;
}while(ch=='y' || ch=='Y');
getch();
}
20.LINKED QUEUE
AIM:
To Implement push,pop and display operations in a linked queue
SOURCE CODE:
#include<iostream.h>
#include<process.h>
#include<stdio.h>
#include<conio.h>
struct node
{
int data;
node *link;
};
node *temp,*rear,*front;
void main()
{
clrscr();
int result;
char ch='Y';
int choice;
do
{
cout<<"MENU \n1.INSERT\n2.DELETE\n3.DISPLAY\n4.EXIT";
cout<<"\nEnter your choice";
cin>>choice;
switch(choice)
{
case 1:
temp=new node;
cout<<"Enter the value";
cin>>temp->data;
temp->link=NULL;
if(rear==NULL)
front=rear=temp;
else
{
rear->link=temp;
rear=temp;
}
break;
case 2:
if(front==NULL)
cout<<"\nEmpty";
else
{
temp=front;
cout<<"\nDeleted value is "<<temp->data;
front=front->link;
delete temp;
}
break;
case 3:
if(front==NULL)
cout<<"\nEmpty";
else
{
temp=front;
cout<<"\n The values are";
while(temp!=NULL)
{
cout<<temp->data<<" " ;
temp=temp->link;
}
}
break;
case 4:
exit(0);
break;
default:
cout<<"\nInvalid input";
}
cout<<"\nPress y/Y to continue";
cin>>ch;
}while(ch=='y' || ch=='Y');
getch();
}
Ex:No:21
SQL Command - I
(b) To list the names of female student who are in Hindi department.
(c) To list the names of all students with their date of admission in ascending order.
TABLE : STUDENT
Answers:
(b) SELECT Name FROM student WHERE SEX = ‘F’ AND department = ‘Hindi’;
NAME
Shikha
NAME
Sanjay
Pankaj
Surya
Rakesh
Shikha
Shalini
Shakeel
Sudha
(d) SELECT Name, FEE, Age from student WHERE SEX = ‘M’;
(e) SELECT count (*) FROM students WHERE Age < 23;
Count(*)
3
------------
Ex:No:22
SQL Command - II
(b) To display the details of all dress which have READYDATE in between 05-Dec-
07 and 20-Jan-08.
(c) To display the average PRICE of all the dress which is made up of material with
MCODE as M003.
(d) To display material wise highest and lowest price of dresses from DRESS table.
(e) To display the DESCRIPTION and TYPE from tables Dress and material.
TABLE : DRESS
TABLE : MATERIAL
MCODE TYPE
M001 Terelene
M002 Cotton
M003 Silk
M004 Polyesters
Answers :
DCODE DESCRIPTION
10001 Formal shirt
10007 Formal pant
10009 Informal shirt
10012 Informa lshirt
10019 Evenin gown
10020 Frock
10023 Pencil shirt
10024 Baby top
10089 Slacks
10090 Tulip shirt
(b) Select * from dress where READYDATE between ‘05-DEC-07’ and ’20-Jun-08’;
DCODE DESCRIPTION PRICE MCODE READYDATE
10001 Formal Shirt 250 M001 12-Jan-08
(c) Select avg(PRICE) from dress where MCODE = ‘M003’;
AVG(Price)
753.33
TYPE
DESCRIPTION
Formal shirt Terelene
Frock Polyesters
Informal shirt Cotton
Evening gown Cotton
Tulip shirt Silk
Pencil shirt Cotton
Slacks Silk
Formal pant Terelene
Informal shirt Cotton
Baby top Silk
------
Ex:No:23
(a) To display the details of those candidates consumers whose address in Delhi.
(b) To display the details of stationery. Whose price is in the range of 8 to 15.
(c) To display the consumer name, address from table consumer and company and
price from table
stationary with their corresponding matching SID.
(e) Add a new record in consumer table with the following details (17, ‘Fast Writer’;
‘Mumbai’, ‘GPOI’).
TABLE : STATIONERY
Answers :
C. S_ID = S.S_ID;
(e) INSERT INTO Consumer VALUES (17, ‘fast writer’, ‘mumbai’, GP01);