Beruflich Dokumente
Kultur Dokumente
TOPIC
.
N
o.
1. Implementation of
Polymorphism
2.
Implementation of:
3.
4.
5.
6.
7.
8.
9.
10
.
11
.
a)
Single inheritance
b)
Multiple inheritance
c)
Multilevel
inheritance
d)
Hierarchical
inheritance
Addition of matrices
Multiplication of matrices
Insertion operation of an
array
Deletion operation of an
array
Sequential search in an
array
Binary search in an array
Sort an array using bubble
sort
Sort an array using
selection sort
Sort an array using
insertion sort
1
DAT TEACH
E
ERs
SIGN
Uppercase letters
Lowercase letters
Digits
Special symbols
14
Read text file and copy
.
data in two text files
simultaneously on the
basis of :
15
.
16
.
17
.
18
.
a)
All the uppercase
letters and digits in the
text file
b)
All the lowercase
letters and special
symbols
Operate all data file
handling operations for a
binary file
Perform push and pop
operation in linear stack
Perform push and pop
operation in linked stack
Perform insertion and
deletion operation in linear
queue
19 Perform insertion and
.
deletion operation in
linked queue
20 SQL Queries
.
1. Implementation of polymorphism
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#define pi 3.14
class fn
{
public:
void area(int); //circle
void area(int,int); //rectangle
void area(float ,int,int); //triangle
void area();
};
void fn::area(int a)
{cout<<"Area of Circle:"<<pi*a*a;
//Function 1}
//Function 2}
//Function 4
{cout<<"\n1.Rectangle=l*b\n2.Cuboid=2*(l*h+h*b+b*l)\n3.Circle=3.14*r2";
}
void main()
{ int ch;
int a,b,r;
char ch1='y';
clrscr();
fn obj;
cout<<"\n\t\tFunction Overloading";
cout<<"\n1.Area of Circle\n2.Area of Rectangle\n3.Area of
Cuboid\n4.Formulas\n";
while(ch1=='y'||ch1=='Y')
{cout<<"Enter your Choice:";
cin>>ch;
switch(ch)
{ case 1: cout<<"Enter Radius of the Circle:";
cin>>r;
obj.area(r);
//Calls Function 1
break;
case 2: Cout<<"Enter Sides of the Rectangle:";
cin>>a>>b;
obj.area(a,b);
//Calls Function 2
break;
case 3: cout<<"Enter Sides of the Cuboid:";
cin>>a>>b;
obj.area(0.5,a,b);
//Calls Function 3
break;
case 4: cout<<"Formulas:";
obj.area();
//Calls Function 4
break;
}
cout<<"\t\tWant to enter more???";
cin>>ch1;
}
getch();}
Output
//Base class
{
int a1,a2;
public:
void getdata()
{
cout<<"\nEnter value of a1 and a2\n";
cin>>a1>>a2;
}
void putdata()
{
cout<<"a1"<<a1<<"a2"<<a2<<endl;
}};
class A1
//Base class
int a11,a21;
public:
void getdata1()
{
cout<<"\nEnter value of a11 and a21\n";
cin>>a11>>a21;
}
void putdata1()
{
cout<<"\na11"<<a11<<"a21"<<a21<<endl;
}};
class B: public A
{
int b1,b2;
public:
void indata()
{
cout<<"\n";
cin>>b1>>b2;
}
void outdata()
{
cout<<"\nb1"<<b1<<"b2"<<b2<<endl;
}};
class C: public B
{
int c1,c2;
public:
void input()
{
cout<<"\nEnter the value of c1 and c2\n";
cin>>c1>>c2;
}
void output()
{
cout<<"c1"<<c1<<"c2"<<c2;
}};
class D: public A
{
int d1,d2;
public:
D()
{
d1=0;
d2=0;
}};
//Multiple Inheritance
//Multilevel Inheritance
int i;
cout<<"1.Single inheritance\n";
cout<<"2.Multiple inheritance\n";
cout<<"3.Multilevel inheritance\n";
cout<<"4.Hierarchial inheritance\n";
cin>>i;
switch(i)
{
10
break;
case 2:cout<<"\nAccessing class A and A1(Base classes) by object of E\n";
obj1.getdata();
obj1.getdata1();
obj1.putdata();
obj1.putdata1();
break;
case 3:cout<<"Accessing Base class A by object of C";
obj3.getdata();
cout<<"\nAccessing subclass B by object of C";
obj3.indata();
cout<<"\nThe values of class A and B are:\n";
obj3.putdata();
obj3.outdata();
break;
case 4:cout<<"Accessing class A by object of its suclass B\n";
obj3.getdata();
obj3.putdata();
cout<<"\nAccessing class A by object of its subclass D\n";
obj2.getdata();
11
obj2.putdata();
cout<<"\nAccessing class A by object of its subclass E\n";
obj1.getdata();
obj1.putdata();
break; }
getch();
}
OUTPUT
12
13
3. Addition of matrices
#include<iostream.h>
#include<conio.h>
void main()
{ int a[5][5],b[5][5],c[5][5],i,k,j,l,n;
cout<<"enter the two arrays:";
cout<<"enter size of arrays:";
cin>>n;
cout<<"1.:";
for(i=0;i<n;++i)
{ for(j=0;j<n;++j)
{cin>>a[i][j];
}
}
cout<<"2.:";
for(i=0;i<n;++i)
{ for(j=0;j<n;++j)
{cin>>b[i][j];
}
}
cout<<"Addition of matrices:";
for(k=0;k<n;++k)
{ for(l=0;l<n;++l)
14
{ c[k][l]=a[k][l] + b[k][l];
}
}
cout<<"Result:\n";
for(i=0;i<n;++i)
{ for(j=0;j<n;++j)
{cout<<c[i][j];
cout<<"\t";
}
cout<<"\n"
}
getch(); }
4. Multiplication of matrices
15
#include<iostream.h>
#include<conio.h>
void main()
{ int a[10][10] , b[10][10] ,c[10][10],m,n,n1,m1,i,j,i1;
16
for(i=0;i<m1;i++)
{ for(j=0;j<n1;j++)
{ cin>>b[i][j];
};
};
for(i=0;i<m;++i)
for(j=0;j<n1;++j)
{ for(i1=0;i1<m1;++i1)
{ c[i][j]=c[i][j]+(a[i][i1]*b[i1][j]);
cout<<"\t"; }
cout<<"\n"; }
cout<<" the product of the two matrix :";
for(i=0;i<m;i++)
{ cout<<"\n";
for(j=0;j<n1;j++)
{ cout<<c[i][j];
cout<<"\t"; }}
getch();}
17
18
19
}
++n;
a[s]=x;
cout<<"Want to insert more??";
cin>>ch;
}
cout<<"The array now is:";
for(i=0;i<n;++i)
{ cout<<a[i]<<"\t";
}
getch();
}
int insert(int b[],int size,int item)
{ int p,i;
if(item<b[0])
p=0;
else
{for(i=0;i<size-1;++i)
{ if(b[i]<=item&&b[i+1]>item)
{p=i+1;
break;
}
}
20
if(i==size-1)
p=size;
}
return p;
}
21
#include<conio.h>
int search(int[], int,int);
void main()
{ int a[15],n,x,i,s;
cout<<"Enter the size of array :";
cin>>n;
cout<<"Enter the array:";
for(i=0;i<n;++i)
{ cin>>a[i]; }
char ch='y';
while(ch=='y'||ch=='Y')
{ cout<<"Enter the item to be deleted :";
cin>>x;
s=search(a,n,x);
if(s==-1)
{cout<<"Item not found...";
}
else
for(i=s;i<n;i++)
{a[i]=a[i+1];}
n-=1;
cout<<"Want to delete more items???";
cin>>ch;}
22
23
24
25
for(i=0;i<n;++i)
{cin>>a[i];
}
cout<<"Enter the element to be searched for:";
cin>>x;
s=search(a,n,x);
if(s==-1)
{ cout<<"The element could not be found !!!!";
}
cout<<"The element is at this position:"<<s;
getch();
}
int search(int b[],int size , int item)
{int i;
for(i=0;i<size;++i)
{ if(b[i]==item)
return i;}
return -1;
}
26
27
28
29
cin>>n;
cout<<"Enter the array:";
for(i=0;i<n;++i)
{cin>>a[i];
}
bsort(a,n);
cout<<"The sorted array is:";
for(i=0;i<n;++i)
{ cout<<a[i];
}
getch();
}
void bsort(int b[],int size)
{int i,j,t,c=0,m;
for(i=0;i<size;++i)
{ for(j=0;j<(size-1);++j)
{ if(b[j]>b[j+1])
{ t=b[j+1];
b[j+1]=b[j];
b[j]=t;
}
}
cout<<"Array after iteration "<<++c<<"\t";
30
for(m=0;m<size;++m)
{cout<<b[m];
}
cout<<"\n";
}
}
10.
#include<iostream.h>
#include<conio.h>
void selsort(int[],int);
void main()
{
clrscr();
int ar[50],item,n,index;
31
int small,tmp,pos;
for(int i=0;i<size;i++)
{
small=ar[i];
for(int j=i+1;j<size;j++)
{
if(ar[j]<small)
{
small= ar[j];
pos=j;
}
}
32
tmp=ar[i];
ar[i]=ar[pos];
ar[pos]=tmp;
}
cout<<endl;
}
11.
#include<iostream.h>
#include<conio.h>
#include<limits.h>
void inssort(int[],int);
void main()
{
clrscr();
33
int ar[50],item,n,index;
cout<<"How many elements do you want to create array with?
(max.50)...";
cin >>n;
cout<<"\nEnter array elements...\n";
for(int i=1;i<=n;i++)
cin >>ar[i];
inssort(ar,n);
cout<<"\n\nThe sorted array is as shown below...\n";
for(i=1;i<=n;i++)
cout<<ar[i]<<" ";
cout<<endl;
getch();
}
void inssort(int ar[],int size)
{
int tmp,j;
ar[0]=INT_MIN;
for(int i=1;i<=size;i++)
{
tmp=ar[i];
j=i-1;
while(tmp<ar[j])
{
ar[j+1]=ar[j];
j--;
34
}
ar[j+1]=tmp;
cout<<endl;
}
}
35
12.
#include<iostream.h>
#include<conio.h>
void merge(int[],int,int[],int,int[]);
void main()
{
clrscr();
int A[50],B[50],C[50],MN=0,M,N;
cin >>A[i];}
cin >>B[i];}
merge(A,M,B,N,C);
cout<<"\n\nThe merged array is as shown below...\n";
for(i=0;i<MN;i++)
36
cout<<C[i]<<" ";}
cout<<endl;
getch();
}
void merge(int A[], int M, int B[], int N, int C[])
{
int a,b,c;
for(a=0,b=N-1,c=0 ; a<M && b>=0;)
{
if(A[a]<=B[b])
{
C[c++]=A[a++];
}
else
{
C[c++]=B[b--];}
}
if(a<M)
{
while(a<M)
{
C[c++]=A[a++];}}
else
{
while(b>=0)
{
C[c++]=B[b--];}}}
37
38
13.
a)
b)
c)
d)
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<ctype.h>
void main()
{
clrscr();
char ch;
ofstream of("text1.txt");
for(int i=1;i<=5;i++)
{
}
of.close();
ifstream if1("text1.txt");
int u=0,l=0,d=0,s=0;
if1.seekg(0);
cout<<"\n";
for(i=1;i<=5;i++)
39
if1.get(ch);
if(isupper(ch))
u++;
else if(islower(ch))
l++;
else if(isdigit(ch))
d++;
else
s++;
cout<<"Character "<<i<<" = "<<ch;
cout<<"\n";
}
if1.close();
cout<<"Total Upper value = "<<u;
cout<<"\nTotal lower value = "<<l;
cout<<"\nTotal digit value = "<<d;
cout<<"\nTotal special symbol value = "<<s;
getch();}
40
41
14. Read a text file and copy the data in text files simultaneously
on the basis of:
a) All the uppercase letters and digits in the text file
b) All the lowercase letters and special symbols
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<ctype.h>
void main()
{
clrscr();
char ch;
ofstream of("text1.txt");
for(int i=1;i<=7;i++)
{
}
of.close();
ifstream if1("text1.txt");
ofstream of1("ud.txt");
ofstream of2("ls.txt");
int u=0,l=0;
if1.seekg(0);
42
cout<<"\n";
for(i=1;i<=7;i++)
{
if1.get(ch);
if(isupper(ch)||isdigit(ch))
{
of1<<ch;
u++;
}
else
{
of2<<ch;
l++;
}
cout<<"Character "<<i<<" = "<<ch;
cout<<"\n";
}
if1.close();
of1.close();
of2.close();
cout<<"total upper and digit value = "<<u;
cout<<"\nTotal lower and special symbol value = "<<l;
ifstream if2("ud.txt");
ifstream if3("ls.txt");
cout<<"\n\nContents of the file1\n";
43
for(i=1;i<=u;i++)
{
if2.get(ch);
cout<<"\t"<<ch;}
if3.get(ch);
cout<<"\t"<<ch;}
getch();}
15.
44
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
int wcnt=0;
class student
{
public:
char name[80];
int rno;
void getdata()
{
cout<<"Enter the roll no.";
cin>>rno;
cout<<"\nEnter the name: ";
gets(name);
}
void putdata()
{
cout<<"\n\nRoll no: "<<rno;
cout<<"\nName: "<<name;
}
}s;
45
void main()
{
void rfile();
void afile();
void mfile();
void dfile();
char ans='y';
int choice=0;
while(ans=='y')
{
clrscr();
cout<<"Enter your choice"<<"\n";
cout<<"\n1.read file";
cout<<"\n2.append file";
cout<<"\n3.modify in file";
cout<<"\n4.delete from file";
cout<<"\nEnter your choice: ";
cin>>choice;
if(choice==1)
rfile();
if(choice==2)
afile();
if(choice==3)
46
mfile();
if(choice==4)
dfile();
cout<<"\n\nDo you want to continue? ";
cin>>ans;
}
getch();
}
void rfile()
{
ifstream fr;
fr.open("temp",ios::in|ios::binary);
while(fr)
{
fr.read((char*)&s,sizeof(s));
s.putdata();
}
fr.close();
}
void afile()
{
ofstream fr;
47
fr.open("temp",ios::app|ios::binary);
s.getdata();
fr.write((char*)&s,sizeof(s));
fr.close();
cout<<"Record added successfuly";
}
void mfile()
{
fstream fr;
fr.open("temp",ios::in|ios::out|ios::binary);
int item;
cout<<"Enter searching rollno: ";
cin>>item;
int record=0;
fr.seekg(0);
while(fr)
{
fr.read((char*)&s,sizeof(s));
record++;
if(item==s.rno)
{
s.putdata();
cout<<"\nEnter the modified data: ";
48
s.getdata();
fr.seekp((record-1)*sizeof(s),ios::beg);
getch();
fr.write((char*)&s,sizeof(s));
}
}
fr.close();
}
void dfile()
{ fstream fr,f2;
fr.open("temp",ios::in|ios::out|ios::binary);
f2.open("try",ios::out|ios::binary);
int item;
cout<<"Enter the roll number to be deleted: ";
cin>>item;
while(fr)
{
fr.read((char*)&s,sizeof(s));
if(item==s.rno);
else
f2.write((char*)&s,sizeof(s));
}
fr.close();
49
f2.close();
remove("temp");
rename("try","temp");
}
50
16.
#include<iostream.h>
#include<conio.h>
#include<process.h>
int p(int [],int&,int);
int pop(int [],int&);
void d(int [],int);
51
52
exit(1);
}
cout<<"The element which is deleted is:"<<res;
cout<<"\nThe stack is:";
d(s,t);
cout<<"\nWant to delete more elements??";
cin>>ch1;}
getch();
}
int p(int a[],int & top,int e)
{ if(top==size-1)
{ return -1;
}
else
{ top++;
a[top]=e;
return 0;}
}
int pop(int a[],int&top)
{int f;
if(f==size-1)
{return -1;}
else
53
{ f=a[top];
top--;
return f;}}
void d(int a[], int top)
{ if(top==-1) return;
cout<<a[top]<<"-";
for(int i=top-1;i>=0;i--)
cout<<"\n"<<a[i];}
54
17.
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct Node {
int info ;
Node * next ;
top = NULL ;
int inf ;
char ch = 'y' ;
55
}
Push( newptr ) ;
cout << "\n Press Y to enter more nodes, N to exit...";
cin >> ch ;
}
clrscr( ) ;
do
{
getch( ) ;
56
save = top ;
top = np ;
}
void Display( Node* np )
{
while ( np !=NULL )
{
57
58
18.
#include<iostream.h>
#include<conio.h>
#include<process.h>
int Remove(int []) ;
int Insert(int [], int) ;
void Display(int [], int, int) ;
const int size = 50 ;
int Queue[size], front = -1, rear = -1 ;
void main()
{
59
res = Remove(Queue) ;
if (res == -1 )
{ cout << "UNDERFLOW!!! Aborting!! \n" ;
exit(1) ; }
else
{
front = rear = 0 ;
Queue[rear] = ele ;
}
else
{
rear++ ;
60
Queue[rear] = ele ;
}
return 0 ;
}
int Remove( int Queue[] )
{
int ret ;
if ( front == -1 ) return -1 ;
else
{
ret = Queue[front] ;
if ( front == rear) front = rear = -1 ;
else front++ ;}
return ret ;}
void Display(int Queue[], int front, int rear)
{
if ( front == -1 ) return ;
for( int i = front ; i < rear ; i++)
cout << Queue[i] << " <- \t" ;
cout << Queue[rear] << endl ;
61
62
19.
#include<iostream.h>
#include<process.h>
#include<conio.h>
struct Node
int info ;
Node * next ;
} *front, *newptr, *save, *ptr, *rear ;
Node * Create_New_Node( int ) ;
void Insert( Node* ) ;
void Display( Node* ) ;
void delNode_Q( ) ;
void main( )
{
exit(1) ; }
Insert ( newptr) ;
63
return ptr ;
}
void Insert( Node* np)
{
rear = np ; }
64
void delNode_Q( )
{
ptr = front ;
front = front -> next ;
delete ptr ;
}
}
void Display( Node* np )
{
while ( np != NULL )
{
}
cout << "!!!\n" ;
}
65
66
20.
SQL Queries
67
68
69
70