NAME :- PRANAV GHILDIYAL
Class: - XII B

44
INDEX
S. No.
1
2
3
4

pagE No.
01
02
03
07

20(A)
20(B)

program NamE
Fibonacci Series using copy constructor
Largest element of the array
Banking Simulation using inheritance
Program to illustrate the use of this pointer by finding the greater
number among the two entered
Linear Search in Array
Binary Search in Array
Selection Sort in Array
Insertion Sort in Array
Insertion at the beginning of a linked list
Bubble Sort in Array
Merging of two array initially in ASCENDING order and the resultant also
in ASCENDING order
Calculating Area using Function overloading
Program to obtain marks and date of birth of student and print it using
the concept of nested structure
Program to display employee details using array and structure
Program to display Worker’s details using Class and Objects
Program to show working of constructor and destructor
Program to print the address and the respective values of different
numbers using the concept of array pointers
Program to update a data file containing structure objects using data file
handling
Program to perform deletion at beginning of Stack- implemented using
Linked list
Program to push in elements in stack - implemented using Linked list
Program to pop out elements in stack - implemented using Linked list

21
22

Program for Implementation of Linked Queues
Program to implement circular Queue

32
34

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

23
24
29(A)
29(B)

Program to update a data file containing class objects using data file
handling
SQL Commands
Program To push in element in stack implemented using Array
Program To pop out element in stack implemented using Array

FIboNaccI SErIES uSINg copy coNStructor
44

08
09
10
11
12
14
15
17
19
20
21
23
24
25
26
28
30

36
37
39
41
#include<iostream.h>
#include<conio.h>
class fibonacci
{
unsigned long int f0, f1, fib;
public:
fibonacci() { f0=0; f1=1; fib=f0+f1; }
fibonacci (fibonacci &ptr) { f0=ptr.f0; f1=ptr.f1; fib=ptr.fib; }
void increment() { f0=f1;
f1=fib;
fib=f0+f1; }
void display() { cout<<fib<<"nn"; }
}; //end of class
void main()
{ clrscr();
fibonacci number;
cout<<"Fibonacci series:-nn";
for (int i=0; i<=10; i++)
{
number.display(); number.increment(); }
getch();
}

output:-

44
LargESt ELEmENt oF thE array
#include<iostream.h>
#include<conio.h>
int main()
{ clrscr();
float large (float arr[], int n);
char ch; int i = 0; float amount[50], biggest;
for (i = 0; i<50; i++)
{
cout<<"enter element number” <<i+1<<"n"; cin>>amount[i];
cout<<"more elements (Y/N)"; cin>>ch;
if (ch!= 'y') break;
}
if ( i< 50) i++;
biggest = large (amount, i);
cout<<"The largest element of array is "<<biggest;
getch(); return 0;
}
float large (float arr[], int n)
{
float max = arr[0];
for(int j = 0; j<n; j++)
if (arr[j] > max) max = arr[j];
return max;
}

output:-

44
baNkINg SImuLatIoN uSINg INhErItaNcE
#include <iostream.h>
#include <conio.h>
class account
{
char cust_name[20]; int acc_no; char acc_type[20];
public:
void get_accinfo()
{
cout<<"nn Enter Customer Name: - ";
cin>>cust_name;
cout<<"Enter Account Number: - ";
cin>>acc_no;
cout<<"Enter Account Type: - ";
cin>>acc_type;
}
void display_accinfo()
{
cout<<"nn Customer Name: - "<<cust_name;
cout<<"n Account Number: - "<<acc_no;
cout<<"n Account Type: - "<<acc_type;
}
};
class cur_acct : public account
{
static float balance;
public:
void disp_currbal()
{ cout<<"n Balance: - "<<balance; }
void deposit_currbal()
{
float deposit;
cout<<"n Enter amount to Deposit :- ";
cin>>deposit;
balance = balance + deposit;
}
void withdraw_currbal()
{
float penalty, withdraw;
cout<<"nn Balance: - "<<balance;
cout<<"n Enter amount to be withdrawn:-";
cin>>withdraw;
balance=balance-withdraw;
if(balance < 500)
{
penalty= (500-balance)/10;

44
balance=balance-penalty;
cout<<"n Balance after deducting penalty: "<<balance;
}
else if (withdraw > balance)
{
cout<<"nn You have to take permission for Bank Overdraft Facilityn";
balance=balance+withdraw;
}
else
cout<<"n After Withdrawl your Balance revels : "<<balance;
}
};
class sav_acct : public account
{
static float savbal;
public:
void disp_savbal()
{ cout<<"n Balance: - "<<savbal; }
void deposit_savbal()
{
float deposit, interest;
cout<<"n Enter amount to Deposit: - ";
cin>>deposit;
savbal = savbal + deposit;
interest=(savbal*2)/100;
savbal=savbal+interest;
}
void withdraw_savbal()
{
float withdraw;
cout<<"n Balance: - "<<savbal;
cout<<"n Enter amount to be withdrawn:-";
cin>>withdraw;
savbal=savbal-withdraw;
if(withdraw > savbal)
{
cout<<"nn You have to take permission for Bank Overdraft Facilityn";
savbal=savbal+withdraw;
}
else
}
};
float cur_acct :: balance, sav_acct :: savbal;
void main()
{
clrscr();
cur_acct c1; sav_acct s1;

44
cout<<"n Enter S for saving customer and C for current a/c customernn";
char type;
cin>>type;
int choice;
if(type=='s' || type=='S')
{
s1.get_accinfo();
while(1)
{
clrscr();
cout<<"n Choose Your Choicen";
cout<<"1) Depositn";
cout<<"2) Withdrawn";
cout<<"3) Display Balancen";
cout<<"4) Display with full Detailsn";
cout<<"5) Exitn";
cout<<"6) Choose Your choice:-";
cin>>choice;
switch(choice)
{
case 1 : s1.deposit_savbal();
getch();
break;
case 2 : s1.withdraw_savbal();
getch();
break;
case 3 : s1.disp_savbal();
getch();
break;
case 4 : s1.display_accinfo();
s1.disp_savbal();
getch();
break;
case 5 : goto end;
default: cout<<"nn Entered choice is invalid,"TRY AGAIN"";
}
}
}
else
{
{
c1.get_accinfo();
while(1)
{
cout<<"n Choose Your Choicen";
cout<<"1) Depositn";
cout<<"2) Withdrawn";
cout<<"3) Display Balancen";
cout<<"4) Display with full Detailsn";
cout<<"5) Exitn";
cout<<"6) Choose Your choice:-";

44
cin>>choice;
switch(choice)
{
case 1 : c1.deposit_currbal();
getch();
break;
case 2 : c1.withdraw_currbal();
getch();
break;
case 3 : c1.disp_currbal();
getch();
break;
case 4 : c1.display_accinfo();
c1.disp_currbal();
getch();
break;
case 5 : goto end;
default: cout<<"nn Entered choice is invalid,"TRY AGAIN"";
}
}
}
end:
}
}

output:-

44
program to ILLuStratE thE uSE oF thIS poINtEr
by FINDINg thE grEatEr NumbEr amoNg thE two
ENtErED
#include<iostream.h>
#include<conio.h>
class max
{ int a;
public:
void getdata()
{
cout<<"Enter the Value:";
cin>>a;
}
max &greater(max &x)
{
if(x.a>=a)
return x;
else return *this;
}
void display() { cout<<"Maximum No. is : "<<a<<endl;
};
main()
{ clrscr();
max one, two, three;
one.getdata(); two.getdata();
three=one.greater(two);
three.display();
getch();
}

output:-

44

}
44
LINEar SEarch IN array
#include<iostream.h>
#include<conio.h>
int Lsearch(int [ ], int ,int) ; //i.e., Lsearch(the array, its size, search Item)
int main()
{ clrscr();
int AR[50], ITEM, N, index; // array can hold max. 50 elements
cout<< “Enter desired array size (max. 50) ..."; cin>>N ;
cout<<" n Enter Array elementsn";
for(int i = 0; i < N; i++)
{ cin>>AR[i] ; }
cout<<"n Enter Element to be searched for ..."; cin>>ITEM;
index = Lsearch(AR, N, ITEM) ;
if (index == -1)
cout<<" n Sorry!! Given element could not be found.n";
else
cout<<"n Element found at index: "<< index <<" , Position: "<<index + 1<<endl;
getch(); return 0 ;
}
int Lsearch(int AR[ ], int size, int item)
//function to perform linear search
{ for(int i = 0 ; i < size; i++)
{ if (AR[i] == item) return i ; }
// return index of item in case of successful search
return -1 ;
// the control will reach here only when item is not found
}

output:-

44
bINary SEarch IN array
#include<iostream.h>
#include<conio.h>
int Bsearch(int [ ], int ,int) ; //i.e., Bsearch(the array, its size, search Item)
int main()
{ clrscr();
int AR[50], ITEM, N, index; // array can hold max. 50 elements
cout<< "Enter desired array size (max. 50) ...";
cin>>N ;
cout<<" n Enter Array elements ( must be sorted in Ascending order)n";
for(int i = 0; i < N; i++)
{ cin>>AR[i] ; }
cout<<"n Enter Element to be searched for ..."; cin>>ITEM;
index = Bsearch(AR, N, ITEM) ;
if (index == -1) cout<<" n Sorry!! Given element could not be found.n";
else
cout<<"n Element found at index: "<< index <<" , Position: "<<index + 1<<endl;
getch(); return 0 ;
}
int Bsearch(int AR[ ], int size, int item) //function to perform Binary search
{int beg, last, mid;
beg = 0; last = size - 1;
while (beg<= last)
{
mid = (beg + last)/2;
if (item == AR[mid]) return mid;
else if(item > AR[mid]) beg = mid + 1;
else last = mid- 1; }
return -1 ; // the control will reach here only when item is not found
}

output:-

44
44
Selection Sort in ArrAy
#include<iostream.h>
#include<conio.h>
void SelSort(int [], int);
//function for selection sort
int main()
{ clrscr();
int AR[50], ITEM, N, index;
// array can hold max. 50 elements
cout<<" How many elements do U want to create array with? (max. 50) ..." ; cin>>N;
cout<<" n Enter Array elements ... ";
for(int i = 0; i < N ; i++) cin >> AR[i];
SelSort(AR, N);
cout <<" nn The Sorted array is as shown below ... n ";
for(i=0; i<N; i++) cout<<AR[i]<<" "<<endl;
getch(); return 0;
}
void SelSort(int AR[ ], int size)
//function to perform selection sort
{
int small, pos, tmp;
for(int i = 0; i < size ; i++)
{ small = AR[i];
pos = i;
for(int j = i+1 ; j< size; j++)
{ if ( AR[j]< small)
{ small = AR[j]; pos = j;}
}
tmp = AR[i];
AR[i]= AR[pos]; AR[pos] = tmp;
cout<<" n Array after pass - "<< i+1<<"-is :";
for (j= 0; j< size; j++) cout<< AR[j]<<" ";
}
}

oUtPUt:-

44
44
inSertion Sort in ArrAy
#include<iostream.h>
#include<limits.h> // for INT_MIN
#include<conio.h>
void InsSort(int [ ], int) ;
int main()
{ clrscr();
int AR[50], ITEM, N, index;
// array can hold max. 50 elements
cout << " How many elements do U want to create array with? (max. 50) ... " ; cin>>N ;
cout<<" n Enter Array elements ... " ;
for(int i = 1 ; i <= N ; i++) cin >> AR[i] ;
InsSort(AR, N) ;
cout <<" the Sorted array is as shown below ... n";
for(i = 1 ; i <= N ; i++)
cout << AR[i] << " " << endl ;
getch(); return 0;
}
void InsSort (int AR[ ], int size) // function to perform Insertion Sort
{ 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--; }
AR[j+1] = tmp;
cout<<" Array after pass -" <<i<< "- is: " ;
for(int k = 1; k <= size; k++)
cout <<AR[k]<<" " << endl;
}
}

oUtPUt:-

44
inSertion At the beginning of A linked liSt
#include<iostream.h>
#include<process.h>
struct Node { int info ; Node * next; } *start, *newptr, *save, *ptr ;
Node * Create_New_Node(int) ;
void Insert_Beg( Node* ) ;
void Display( Node* ) ;
int main()
{
start = NULL ; int inf; char ch = 'Y' ;
while ( ch == 'Y' || ch == 'Y' )
{
system ( " cls " ) ;
cout<< "n Enter INFOrmation for the new node ... "; cin>>inf ;
cout <<"n Creating New Node!! Press Enter to continue ... " ;
system ( "pause") ;
newptr = Create_New_Node( inf );
if ( newptr != NULL)
{ cout<<"nn New Node Created Successfully. Press Enter to continue ... " ; system ( "pause") ; }
else
{ cout<< "n cannot create new node!!! Aborting !!n" ; system ( "pause") ; exit(1) ; }
cout<<"nn Now inserting this node in the beginning of List ... n" ;
cout<<"Press Enter to continue ... n" ;
system ( "pause") ;
Insert_Beg( newptr ) ;
cout<<"n Now the list is : n" ;
Display( start) ;
cout<<"n Press Y to enter more nodes, N to exit ... n" ; cin>>ch ;
} return 0 ;
}
Node * Create_New_Node( int n )
{ ptr = new Node;
ptr -> info = n ; ptr -> next = NULL;
return ptr ;
}
void Insert_Beg( Node* np)
{ if ( start == NULL)
start = np ;
else
{ save= start ; start = np ; np -> next = save ;
}
}
void Display( Node*np )
// function to Display list
{ while ( np != NULL)
{ cout<<np->info<<" ->"; np = np->next ;
}
cout << "!!!n" ;
}

44
oUtPUt:-

44
bUbble Sort in ArrAy
#include<iostream.h>
#include<conio.h>
void BubbleSort(int [ ], int) ; // function for bubble sort
int main()
{ clrscr();
int AR[50], ITEM, N, index ;
// array can hold max. 50 elements
cout<< " How many elements do U want to create array with? (max. 50) ... "; cin>>N;
cout<<" nEnter Array elements ... n" ;
for(int i = 0 ; i < N ; i++) cin >>AR[i];
BubbleSort(AR, N) ;
cout<<"nThe Sorted array is as shown below ... n" ;
for(i = 0 ; i < N ; i++)
cout<<AR[i] << " "<< endl ;
getch(); return 0;
}
void BubbleSort(int AR[ ], int size)
// function to perform Bubble Sort
{
int tmp, ctr = 0 ;
for(int i = 0; i<size; i++)
{ for (int j = 0; j< (size-1)-i; j++)
{ if (AR[j] > AR[j+1] )
{ tmp = AR[j] ; AR[j] = AR[j+1] ; AR[j+1]= tmp; } }
cout<< "Array after iteration - " << ++ctr<<" - is: ";
for(int k = 0; k < size ; k++)
cout<< AR[k]<<" "<<endl;
} }

oUtPUt:-

44
Merging of two ArrAy initiAlly in AScending
order And the reSUltAnt AlSo in AScending
order
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int a[100],b[100],c[100],n,m,i,j,k,s;
cout<<"nn Enter No. of Elements in First Array : ";
cin>>n;
cout<<"n Enter Elements in Ascending Order:n";
for(i=1;i<=n; i++)
{ cin>>a[i]; }
cout<<"nEnter No. of Elements in Second Array : ";
cin>>m;
cout<<"nEnter Elements in Ascending Order:n";
for(i=1;i<=m;i++)
{ cin>>b[i]; }
i=1,j=1;
for(k=1;k<=n+m;k++)
{
if(a[i]<b[j])
{
c[k]=a[i];
i++;
if(i>n)
goto b;
}
else
{
c[k]=b[j];
j++;
if(j>m)
goto a;
}
}
a:
for(s=i;s<=n;s++)
// Copy the Remaining Elements of Array A to C
{
k++; c[k]=a[s]; }
b:
for(s=j;s<=m;s++)
// Copy the Remaining Elements of Array B to C
{ k++;
c[k]=b[s];
}
cout<<"n nAfter Merging Two Arrays:n";
for(k=1;k<=n+m; k++)
{ cout<<c[k]<<endl; }
getch();
}

44
oUtPUt:-

44
cAlcUlAting AreA USing fUnction overloAding
#include<iostream.h>
#include<conio.h>
#include<math.h>
float area (float a, float b, float c)
{float s, ar;
s = (a + b + c)/ 2;
ar = sqrt(s*(s - a)*(s - b)*(s - c));
return ar;
}
float area (float a, float b)
{
return (a*b);
}
float area (float a)
{
return (a*a);
}
int main ()
{
clrscr ();
int choice, ch;
float s1, s2, s3, ar;
cout<<"n Area menu n";
cout<<"1. Triangle n"<<"2. Square n"<<"3. Rectangle n"<<"4. Exit n";
cout<<"Enter your choice n";
cin>>choice;
switch (choice)
{
case 1: cout<<"Enter the three sides :- ";
cin>>s1>>s2>>s3;
ar = area(s1,s2,s3);
cout<<"the area is "<<ar<<"n";
getch();
break;
case 2: cout<<"Enter the side :- ";
ar = area(s1);
cout<<"the area is "<<ar<<"n";
getch();
break;

cin>>s1;

case 3: cout<<"Enter the two sides :- ";
cin>>s1>>s2;
ar = area(s1,s2);
cout<<"the area is "<<ar<<"n";
getch(); break;
case 4: break;
default: cout<<"n Wrong Choice n";
};
return 0;
}

44
oUtPUt:-

44
ProgrAM to obtAin MArkS And dAte of birth of
StUdent And Print it USing the concePt of neSted
StrUctUre
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
struct dob
{
short day;
short month;
struct student
{
int roll_num;
float marks1, marks2, marks3;
dob D1;
}stu1;

short year; }D1;

cout<<"Enter roll number of the student n";
cin>>stu1.roll_num;
cout<<"Enter marks of the students in the three subjects n";
cin>>stu1.marks1>>stu1.marks2>>stu1.marks3;
cout<<"Enter Date of birth of the student n";
cin>>stu1.D1.day>>stu1.D1.month>>stu1.D1.year;
cout<<"nnn Student details Follow n";
cout<<"roll number n"<<stu1.roll_num<<"n";
cout<<"Marks n"<<stu1.marks1<<" , "<<stu1.marks2<<" , "<<stu1.marks3<<"n";
cout<<"Date of birthn"<<stu1.D1.day<<" , "<<stu1.D1.month<<" , "<<stu1.D1.year<<"n";
getch(); return 0;
}

oUtPUt:-

44
Program to disPlay emPloyee details using array
and structure
#include<iostream.h>
#include<conio.h>
int main()
{ clrscr();
struct employee {
char name[4], desig[10];
int emp_id;
float basic;
}emp1;
cout<<"Enter name of the employee n";
cin.getline(emp1.name,4);
cout<<"Enter employee id of the employee n";
cin>>emp1.emp_id;
cout<<"Enter basic pay of the employee n";
cin>>emp1.basic;
cout<<"nnn Employee Details Follown";
cout<<"Namen";
cout.write(emp1.name,4);
cout<<"n";
cout<<"Employee idn"<<emp1.emp_id<<"n";
cout<<"basic payn"<<emp1.basic;
getch();
return 0;
}

outPut:-

44
Program to disPlay Worker’s details using class
and objects
#include<iostream.h>
#include<conio.h>
class employee
{
int emp_num;
char emp_name[20];
float emp_basic, sal, emp_da, net_sal, emp_it;
public:
void get_details();
void find_net_sal();
void show_emp_details();
};
void employee :: get_details()
{
cout<<"nEnter employee number:n"; cin>>emp_num;
cout<<"nEnter employee name:n"; cin>>emp_name;
cout<<"nEnter employee basic:n";
cin>>emp_basic;
}
void employee :: find_net_sal()
{
emp_da=0.52*emp_basic;
emp_it=0.30*(emp_basic+emp_da);
net_sal=(emp_basic+emp_da)-emp_it;
}
void employee :: show_emp_details()
{
cout<<"nnnDetails of : "<<emp_name;
cout<<"nnEmployee number: "<<emp_num;
cout<<"nBasic salary : "<<emp_basic;
cout<<"nEmployee DA : "<<emp_da;
cout<<"nIncome Tax
: "<<emp_it;
cout<<"nNet Salary
: "<<net_sal;
}
int main()
{
employee emp[10];
int i,num;
clrscr();
cout<<"nEnter number of employee detailsn";
cin>>num;

44
for(i=0;i<num;i++)
{
cout<<"Enter Details For employee number"<<i + 1;
}
for(i=0;i<num;i++)
emp[i].find_net_sal();
for(i=0;i<num;i++)

}

emp[i].show_emp_details();

getch();
return 0;

outPut:-

44

emp[i].get_details();
Program to shoW Working of constructor and
destructor
#include<iostream.h>
#include<conio.h>
class Base
{
public:
Base () { cout<<"Base Class constructor" << endl; }
~Base () { cout<<"Base Class destructor" <<endl; }
};
class Derived : public Base
{
public:
Derived() { cout<<"Derived Class constructor" << endl; }
~Derived() { cout<<"Derived Class destructor" << endl; }
};
void main( )
{
clrscr();
{ Derived x;
getch();
}

for(int i = 0; i< 10 ;i++);

cout<<"object now out of scope n";

outPut:-

44

}
Program to Print the address and the resPective
values of different numbers using the concePt of
array Pointers
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int *ip[5];
// array of 5 int pointers
int f = 65, s = 67, t = 69, fo = 70, fi = 75; // initialization
ip[0] = &f; ip[1] = &s; ip[2] = &t; ip[3] = &fo; ip[4] = &fi;
for (int i = 0; i < 5; i++) cout<< " the pointer ip["<<i<<"] points to" <<*ip[i]<<"n";
cout<<" the base address of array ip of pointers is "<<ip<<"n";
for(i = 0; i< 5; i++) cout<< " the address stored in ip["<<i<<"] is "<<ip[i]<<"n";
getch();
return 0;
}

outPut:-

44
Program to uPdate a data file containing
structure objects using data file handling
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
struct student
{
char name[10];
int roll_num;
float cent_marks;
}stu1;
int main()
{
clrscr();
ofstream fout;
fout.open("Student.dat", ios::app);
cout<<"Enter name of the student n";
cin.getline(stu1.name,10);
cout<<"Enter roll number of the student n"; cin>>stu1.roll_num;
cout<<"Enter percentage marks of the student n"; cin>>stu1.cent_marks;
fout.write((char*) &stu1, sizeof(stu1));
cout<<"Record successfully Updated";
getch(); return 0;
}

outPut:-

44
Program to Perform deletion at beginning of
stack- imPlemented using linked list
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h> // for exit( )
struct Node { int info ; Node * next; } *start, *newptr, *save, *ptr,*rear ;
Node * Create_New_Node(int) ;
void Insert( Node* ) ;
void Display( Node* ) ;
void DelNode();
int main()
{ clrscr();
start = rear = NULL ; // In the beginning list is empty, thus, pointers are NULL
int inf ; char ch = 'Y' ;
while(ch == 'y' || ch == 'Y')
{ system ( " cls " ) ;
cout<<" n Enter INFOrmation for the new node ... " ; cin >> inf ;
newptr = Create_New_Node( inf ) ;
if ( newptr == NULL)
{ cout<<" n cannot create new node!!! Aborting!!n ";
system ( "pause") ; exit(1) ;
}
Insert( newptr );
cout<< " n Press Y to enter more nodes, N to exit... n " ; cin>>ch;
}
system ( " cls " ) ;
do
{ cout<<" n The List now is: n " ;
Display( start);
system ( "pause") ;
cout<<" Want to delete first node? (y/n) ... " ;
cin >> ch ;
if( ch=='y' || ch=='Y' )
DelNode() ;
} while(ch=='y' || ch=='Y') ;
getch();
return 0 ;
}
Node * Create_New_Node( int n )
{ ptr = new Node;
ptr -> info = n ;
ptr -> next = NULL;
return ptr ;
}

44
void Insert( Node* np) // Function to insert node in the list
{ if ( start == NULL)
start = rear = np ;
else
{ rear -> next = np ; rear = np ; } }
void DelNode( ) // function to delete a node from the begining of list
{ if (start == NULL) cout <<"UNDERFLOW CONDITION !!! n";
else
{ ptr = start;
start = start -> next ;
delete ptr ;
}
}
void Display( Node* np )
// function to Display list
{ while ( np != NULL)
{cout<<np->info<<" ->";
np = np->next ; }
cout<< "!!!n" ;
}

outPut:-

44
Program to Push in elements in stack - imPlemented
using linked list
#include<iostream.h>
#include<stdlib.h>
#include<process.h>
struct Node { int info ; Node * next;
} *top, *newptr, *save, *ptr;
Node * Create_New_Node( int ); //prototype
void Push( Node* ); // prototype
void Display( Node* ); // prototype
int main( )
{ int inf ; char ch = 'Y';
while ( ch == 'y' || ch == 'Y' )
{ cout<<" n Enter INFOrmation for the new node ... " ;
cin>> inf;
newptr = Create_New_Node( inf);
if ( newptr == NULL)
{ cout<<" n cannot create new node!!! Aborting!!n ";
exit(1) ;
}
Push( newptr ) ;
cout<<"n now the linked-stack is :n";
Display(top);
cout<<" n Press Y to enter more nodes, N to exit ... " ;
cin>>ch;
}
return 0 ;
}
Node * Create_New_Node( int n )
{ ptr = new Node;
ptr -> info = n ;
ptr -> next = NULL ;
return ptr ;
}
void Push( Node* np)
{ if ( top == NULL) top = np ;
else
{ save= top ;
top = np ;
np -> next = save ;
}
}
void Display( Node* np )
{ while ( np !=NULL )
{ cout<<np -> info<<" ->";np = np -> next; }
cout<<" !!!n" ;
}

44
outPut:-

44
Program to PoP out elements in stack - imPlemented
using linked list
#include<iostream.h>
#include<iostream.h>
#include<stdlib.h>
#include<process.h> // for exit( )
struct Node { int info ; Node * next;
} *top, *newptr, *save, *ptr;
Node * Create_New_Node( int ); //prototype
void Push( Node* ); // prototype
void Display( Node* ); // prototype
void Pop( ); // prototype
int main( )
{ top = NULL ;// In the beginning linked-stack is empty, thus, pointers are NULL
int inf ; char ch = 'Y';
while ( ch == 'Y' || ch == 'Y' )
{ cout<<" n Enter INFOrmation for the new node ... " ;
cin>> inf;
newptr = Create_New_Node( inf);
if ( newptr == NULL)
{ cout<<" n cannot create new node!!! Aborting!!n ";
system ("pause") ;
exit(1) ;
}
Push( newptr ) ;
cout<< " n Press Y to enter more nodes, N to exit ... " ;
cin>>ch;
}
system ( " cls" );
do
{ cout<<" n The Stack now is: n " ;
Display( top) ;
system ( "pause");
cout<<" Want to pop an element? (y/n) ... " ;
cin >> ch;
if ( ch == 'Y' || ch == 'Y' ) Pop( ) ; }
while (ch == 'Y' || ch == 'Y') ;
return 0 ;
}
Node*Create_New_Node(int n)
{ ptr = new Node;
ptr -> info = n ;
ptr -> next = NULL ;
return ptr ;
}
void Push( Node* np)

44
{ if ( top == NULL) top = np ;
else
{ save= top ;
top = np ;
np -> next = save ;
}
}
void Pop( )
{ if (top == NULL) cout<<" UNDERFLOW!!!n";
else
{ ptr = top ;
top= top -> next ;
delete ptr ;
}
}
void Display( Node* np )
{ while ( np !=NULL )
{ cout<<np -> info<<" ->";np = np -> next;
}
cout<<" !!!n" ;
}

outPut:-

44
Program for ImPlementatIon of lInked Queues
#include<iostream.h>
#include<conio.h>
#include<process.h>
struct Node { int info; Node * next; } *front, *newptr, *save, *ptr, *rear ;
Node * Create_New_Node( int) ;
void Insert_End( Node* ) ;
void Display( Node* ) ;
int main( )
{ front = rear = NULL; // In the beginning Queue is empty
int inf; char ch = 'y' ;
while (ch == 'y' || ch == 'Y')
{ cout<<" n Enter INFOrmation for the new node ... " ; cin>>inf ;
newptr = Create_New_Node( inf ) ;
if ( newptr == NULL) { cout<< "ncannot create new node!!! Aborting!!n";
Insert_End( newptr ) ;
cout<< " nNow the Queue ( Front ... to ... Rear) is : n " ; Display( front) ;
cout<< " n Press Y to enter more nodes, N to exit ... " ; cin>>ch;
} return 0 ; }
Node * Create_New_Node( int n )
{ ptr = new Node; ptr -> info = n ; ptr -> next = NULL; return ptr ; }
void Insert_End( Node* np)
{ if (front == NULL) front = rear = np ;
else
{ rear -> next = np ; rear = np; }
}
void Display( Node* np ) // function to Display Queue
{ while ( np != NULL) { cout<< np -> info<<" ->" ; np = np -> next; }
cout<<" !!!n " ; }

44

exit(1); }
outPut:-

44
Program to ImPlement cIrcular Queue
#include<iostream.h>
#include<stdlib.h>
#include<process.h>
int Insert_in_CQ(int [ ], int);
void Display(int [ ], int, int) ;
int Del_in_CQ( int CQueue[ ] );
const int size = 7; int CQueue[size], front= -1, rear = -1;
int main()
{ int Item, res, ch;
do{
system ( " cls " );
cout<<" ttt Circular Queue Menun ";
cout<<" t 1. Insertn"<<" t 2. Deleten "<<" t 3. Displayn "<<" t 4. Exitn ";
cout<<" Enter your choice (1-4) ... "; cin>>ch;
switch(ch)
{ case 1 : cout <<"n Enter ITEM for insertion: "; cin>>Item;
res= Insert_in_CQ(CQueue, Item);
if (res == -1 ) cout<<" OVERFLOW!!! n";
else
{ cout<<" n Now the Cir _Queue is : n "; Display(CQueue, front, rear); }
system( "pause"); break;
case 2: Item = Del_in_CQ( CQueue);
cout<<" Element deleted is : "<<Item<<endl;
Display(CQueue, front, rear);
system ( "pause"); break ;
case 3: Display(CQueue, front, rear) ; system ( "pause"); break ;
case 4: break;
default: cout<<" Valid choices are 1...4 onlyn " ;
system ( "pause") ; break;
}
} while(ch != 4 ) ; return 0 ;
}
int Insert_in_CQ(int CQueue[ ], int ele)
// function to insert element in CIR_Queue
{ if ( (front == 0 && rear == size-1 )|| (front == rear+1 ) )
return -1 ;
else if (rear == -1 ) front = rear = 0 ;
else if ( rear == size -1 ) rear = 0 ;
else rear++ ;
CQueue[rear] = ele ;
return 0 ;
}
void Display(int CQueue[ ], int front, int rear)
{ int i = 0 ;
cout<<" n Cir_Queue is: n " <<" ( Front shown as >>>, Rear as <<< AND free space as - )n " ;

44
if (front == -1 ) return ;
if ( rear >= front)
{
for(i = 0; i < front; i++) cout<< "-";
cout<<">>>";
for(i = front; i < rear; i++) cout << CQueue[i] << " <-" ; cout<<CQueue[rear]<<"<<<"<<endl;
} else
{ for(i = 0; i< rear; i++)cout<<CQueue[i]<<" <-";
cout<<CQueue[rear]<<"<<<" ;
for(;i < front;i++) cout<<"-";
cout<<">>>";
for(i = front; i < size; i++) cout<< CQueue[i]<<" <-" ; cout<<" t ... wrap around ... " ;
}
}
int Del_in_CQ( int CQueue[ ] )
{ int ret;
if ( front == -1 ) return -1 ;
else
{
ret = CQueue[front];
if ( front == rear) front = rear = -1;
else if ( front == size-1)
front = 0; //wrap arol md
else front++;
}
return ret;
}

outPut:-

44
Program to uPdate a data fIle contaInIng class
objects usIng data fIle handlIng
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<fstream.h>
class student
{
char name[10], grade;
float marks;
public:
void getdata( void)
{ char ch;
cin.get(ch);
cout<<"Enter name : " ; cin.getline(name, 10);
cout<<"Enter grade : " ; cin>>grade;
cout<<"Enter marks : " ; cout<<"n"; cin >> marks ;
cout<<"n"; } }arts[1];
// End of Class
int main() {
system ("cls");
fstream fillin;
fillin.open("Student.dat",ios::app);
if (!fillin)
{
cout<<" cannot open file !! n " ; return 1 ;
}
cout<<"Enter details of student to be saved"; arts[1].getdata();
fillin.write((char*) &arts[1], sizeof(arts[1]));
cout<<"Record successfully Updated";
getch(); return 0;
}

44
sQl command for manIPulatIon of two tables=.
workers and desIgnatIon
SELECT * FROM workers W, designation D
WHERE W.WID = D.DID;

sQl command for followIng
I.

to dIsPlay w-Id, fIrst name, address and cIty
of all emPloyees lIvIng In new york from the
workers table

SELECT w-id, first name, address, city FROM WORKERS
WHERE city = ‘New York’;

II.

to dIsPlay the content of workers table In
ascendIng order of lastname

SELECT * FROM WORKERS
GROUP BY lastname;

sQl command for dIsPlayIng all clerks from the
tables workers and desIgnatIon where salary Is
calculated as salary + benefIts
SELECT name, salary + benifits FROM workers W, designation D
WHERE D.Designation = ‘clerk’;

sQl command for dIsPlayIng mInImum salary among
managers and clerks from the table desIgnatIon
SELECT name, MIN(salary) FROM Designation
WHERE( ( designation = MANAGER ) or ( designation = clerk )

44
sQl command for dIsPlayIng detaIls of emPloyees
whose name stat wIth a
SELECT * FROM Employees
WHERE name LIKE ”A%”

44
Program to Push In element In stack ImPlemented
usIng array
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
// for exit( )
int Push(int [], int&, int) ;
//prototype
void Display(int [ ], int) ;
// prototype
const int size = 50 ;
int main()
{ clrscr();
int Stack[size], Item, top = -1, res ;
char ch = 'y' ;
system ( " cls " ) ;
while (ch == 'y' || ch == 'Y')
{ cout<<" n Enter ITEM for insertion: " ; cin>>Item ;
res = Push(Stack, top, Item) ;
if (res == -1 )
{ cout<<" OVERFLOW!!! Aborting!! n ";
exit(1) ;}
cout<<" n The Stack now is : n ";
Display(Stack, top) ;
cout<<" n Want to insert more elements? (y/n) ... " ; cin>>ch ;
}
getch(); return 0 ;
}
int Push(int Stack[], int & top, int ele)
{ if (top == size-1) return -1 ;
else
{ top++;
Stack[top] = ele;
}
return 0 ;
}
void Display(int Stack[], int top)
{ cout<<Stack[top] <<" <-- "<< endl ;
for(int i = top-1 ;i >= 0 ; i--)
cout<<Stack[i]<<endl ;
}

44
outPut:-

44
Program to PoP out element In stack ImPlemented
usIng array
#include<iostream.h>
#include<conio.h>
#include<process.h> // for exit( )
int Pop(int[],int&) ; // prototype
int Push(int [], int&, int); // prototype
void Display(int [], int);// prototype
const int size = 50;
int main()
{ int Stack[size], Item, top = -1, res;
char ch = 'Y' ;
while (ch == 'y' || ch == 'Y')
{ cout<<" n Enter ITEM for insertion: " ;
cin>> Item;
res = Push(Stack, top,Item) ;
if (res == -1 )
{ cout<<" OVERFLOW!!! Aborting!! n " ;
exit(1);
}
cout<<" n The Stack now is : n " ;
Display(Stack, top);
cout<<" n Want to insert more elements? (y/n) ... " ;
cin>>ch;
}
cout<<" Now deletion of elements begins ... n " ;
ch = 'Y' ;
while ( ch == 'y' || ch == 'Y' )
{ res = Pop(Stack, top);
if (res == -1 )
{ cout<<" UNDERFLOW!!! Aborting!! n ";
exit(1);
}
else
{ cout<< " nElement deleted is : " << res << endl ;
cout<< " n The Stack now is : n " ;
Display(Stack, top) ;
}
cout<<" n Want to delete more elements? (y/n) ... " ;
cin>>ch;

44
}
return 0;
}
int Push(int Stack[ ], int & top, int ele) // function to insert element
{ if (top == size-1 )
return -1 ;
else
{ top++ ;
Stack[top] = ele ;
}
return 0 ;
}
int pop(int Stack[], int & top) // function to pop element
{
int ret ;
if (top == -1 ) return -1 ;
else
{ ret = Stack[top] ;
top--;
}
return ret ;
}
void Display(int Stack[], int top)
{ if ( top == -1 ) return ;
cout<< Stack[top]<<" <--"<<endl ;
for( int i = top-1; i >= 0; i--)
cout<<Stack[i]<<endl ;
}

DISCLAIMER :I HAVE ALSO MADE THIS PROJECT TAKING HELP FROM
INTERNETI EXPREE MY REGARDS WHO ARE ACTUALLY
BEHIND THIS PROJECT. I HAVE UPLOADED THIS ONLY SO
THAT MORE PEOPLE CAN TAKE HELP FROM THIS
UPLOAD THROUGH MY PROFILE IN SLIDESHARE… TO
REGISTER YOUR OBJECTION TO THIS UPLOAD PLZ
COMMENT UNDER THE PRESENTATION IN THE WEBSITE
44
44

CBSE Class XII Comp sc practical file

  • 1.
    NAME :- PRANAVGHILDIYAL Class: - XII B 44
  • 2.
    INDEX S. No. 1 2 3 4 pagE No. 01 02 03 07 20(A) 20(B) programNamE Fibonacci Series using copy constructor Largest element of the array Banking Simulation using inheritance Program to illustrate the use of this pointer by finding the greater number among the two entered Linear Search in Array Binary Search in Array Selection Sort in Array Insertion Sort in Array Insertion at the beginning of a linked list Bubble Sort in Array Merging of two array initially in ASCENDING order and the resultant also in ASCENDING order Calculating Area using Function overloading Program to obtain marks and date of birth of student and print it using the concept of nested structure Program to display employee details using array and structure Program to display Worker’s details using Class and Objects Program to show working of constructor and destructor Program to print the address and the respective values of different numbers using the concept of array pointers Program to update a data file containing structure objects using data file handling Program to perform deletion at beginning of Stack- implemented using Linked list Program to push in elements in stack - implemented using Linked list Program to pop out elements in stack - implemented using Linked list 21 22 Program for Implementation of Linked Queues Program to implement circular Queue 32 34 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 23 24 29(A) 29(B) Program to update a data file containing class objects using data file handling SQL Commands Program To push in element in stack implemented using Array Program To pop out element in stack implemented using Array FIboNaccI SErIES uSINg copy coNStructor 44 08 09 10 11 12 14 15 17 19 20 21 23 24 25 26 28 30 36 37 39 41
  • 3.
    #include<iostream.h> #include<conio.h> class fibonacci { unsigned longint f0, f1, fib; public: fibonacci() { f0=0; f1=1; fib=f0+f1; } fibonacci (fibonacci &ptr) { f0=ptr.f0; f1=ptr.f1; fib=ptr.fib; } void increment() { f0=f1; f1=fib; fib=f0+f1; } void display() { cout<<fib<<"nn"; } }; //end of class void main() { clrscr(); fibonacci number; cout<<"Fibonacci series:-nn"; for (int i=0; i<=10; i++) { number.display(); number.increment(); } getch(); } output:- 44
  • 4.
    LargESt ELEmENt oFthE array #include<iostream.h> #include<conio.h> int main() { clrscr(); float large (float arr[], int n); char ch; int i = 0; float amount[50], biggest; for (i = 0; i<50; i++) { cout<<"enter element number” <<i+1<<"n"; cin>>amount[i]; cout<<"more elements (Y/N)"; cin>>ch; if (ch!= 'y') break; } if ( i< 50) i++; biggest = large (amount, i); cout<<"The largest element of array is "<<biggest; getch(); return 0; } float large (float arr[], int n) { float max = arr[0]; for(int j = 0; j<n; j++) if (arr[j] > max) max = arr[j]; return max; } output:- 44
  • 5.
    baNkINg SImuLatIoN uSINgINhErItaNcE #include <iostream.h> #include <conio.h> class account { char cust_name[20]; int acc_no; char acc_type[20]; public: void get_accinfo() { cout<<"nn Enter Customer Name: - "; cin>>cust_name; cout<<"Enter Account Number: - "; cin>>acc_no; cout<<"Enter Account Type: - "; cin>>acc_type; } void display_accinfo() { cout<<"nn Customer Name: - "<<cust_name; cout<<"n Account Number: - "<<acc_no; cout<<"n Account Type: - "<<acc_type; } }; class cur_acct : public account { static float balance; public: void disp_currbal() { cout<<"n Balance: - "<<balance; } void deposit_currbal() { float deposit; cout<<"n Enter amount to Deposit :- "; cin>>deposit; balance = balance + deposit; } void withdraw_currbal() { float penalty, withdraw; cout<<"nn Balance: - "<<balance; cout<<"n Enter amount to be withdrawn:-"; cin>>withdraw; balance=balance-withdraw; if(balance < 500) { penalty= (500-balance)/10; 44
  • 6.
    balance=balance-penalty; cout<<"n Balance afterdeducting penalty: "<<balance; } else if (withdraw > balance) { cout<<"nn You have to take permission for Bank Overdraft Facilityn"; balance=balance+withdraw; } else cout<<"n After Withdrawl your Balance revels : "<<balance; } }; class sav_acct : public account { static float savbal; public: void disp_savbal() { cout<<"n Balance: - "<<savbal; } void deposit_savbal() { float deposit, interest; cout<<"n Enter amount to Deposit: - "; cin>>deposit; savbal = savbal + deposit; interest=(savbal*2)/100; savbal=savbal+interest; } void withdraw_savbal() { float withdraw; cout<<"n Balance: - "<<savbal; cout<<"n Enter amount to be withdrawn:-"; cin>>withdraw; savbal=savbal-withdraw; if(withdraw > savbal) { cout<<"nn You have to take permission for Bank Overdraft Facilityn"; savbal=savbal+withdraw; } else } }; float cur_acct :: balance, sav_acct :: savbal; void main() { clrscr(); cur_acct c1; sav_acct s1; 44
  • 7.
    cout<<"n Enter Sfor saving customer and C for current a/c customernn"; char type; cin>>type; int choice; if(type=='s' || type=='S') { s1.get_accinfo(); while(1) { clrscr(); cout<<"n Choose Your Choicen"; cout<<"1) Depositn"; cout<<"2) Withdrawn"; cout<<"3) Display Balancen"; cout<<"4) Display with full Detailsn"; cout<<"5) Exitn"; cout<<"6) Choose Your choice:-"; cin>>choice; switch(choice) { case 1 : s1.deposit_savbal(); getch(); break; case 2 : s1.withdraw_savbal(); getch(); break; case 3 : s1.disp_savbal(); getch(); break; case 4 : s1.display_accinfo(); s1.disp_savbal(); getch(); break; case 5 : goto end; default: cout<<"nn Entered choice is invalid,"TRY AGAIN""; } } } else { { c1.get_accinfo(); while(1) { cout<<"n Choose Your Choicen"; cout<<"1) Depositn"; cout<<"2) Withdrawn"; cout<<"3) Display Balancen"; cout<<"4) Display with full Detailsn"; cout<<"5) Exitn"; cout<<"6) Choose Your choice:-"; 44
  • 8.
    cin>>choice; switch(choice) { case 1 :c1.deposit_currbal(); getch(); break; case 2 : c1.withdraw_currbal(); getch(); break; case 3 : c1.disp_currbal(); getch(); break; case 4 : c1.display_accinfo(); c1.disp_currbal(); getch(); break; case 5 : goto end; default: cout<<"nn Entered choice is invalid,"TRY AGAIN""; } } } end: } } output:- 44
  • 9.
    program to ILLuStratEthE uSE oF thIS poINtEr by FINDINg thE grEatEr NumbEr amoNg thE two ENtErED #include<iostream.h> #include<conio.h> class max { int a; public: void getdata() { cout<<"Enter the Value:"; cin>>a; } max &greater(max &x) { if(x.a>=a) return x; else return *this; } void display() { cout<<"Maximum No. is : "<<a<<endl; }; main() { clrscr(); max one, two, three; one.getdata(); two.getdata(); three=one.greater(two); three.display(); getch(); } output:- 44 }
  • 10.
  • 11.
    LINEar SEarch INarray #include<iostream.h> #include<conio.h> int Lsearch(int [ ], int ,int) ; //i.e., Lsearch(the array, its size, search Item) int main() { clrscr(); int AR[50], ITEM, N, index; // array can hold max. 50 elements cout<< “Enter desired array size (max. 50) ..."; cin>>N ; cout<<" n Enter Array elementsn"; for(int i = 0; i < N; i++) { cin>>AR[i] ; } cout<<"n Enter Element to be searched for ..."; cin>>ITEM; index = Lsearch(AR, N, ITEM) ; if (index == -1) cout<<" n Sorry!! Given element could not be found.n"; else cout<<"n Element found at index: "<< index <<" , Position: "<<index + 1<<endl; getch(); return 0 ; } int Lsearch(int AR[ ], int size, int item) //function to perform linear search { for(int i = 0 ; i < size; i++) { if (AR[i] == item) return i ; } // return index of item in case of successful search return -1 ; // the control will reach here only when item is not found } output:- 44
  • 12.
    bINary SEarch INarray #include<iostream.h> #include<conio.h> int Bsearch(int [ ], int ,int) ; //i.e., Bsearch(the array, its size, search Item) int main() { clrscr(); int AR[50], ITEM, N, index; // array can hold max. 50 elements cout<< "Enter desired array size (max. 50) ..."; cin>>N ; cout<<" n Enter Array elements ( must be sorted in Ascending order)n"; for(int i = 0; i < N; i++) { cin>>AR[i] ; } cout<<"n Enter Element to be searched for ..."; cin>>ITEM; index = Bsearch(AR, N, ITEM) ; if (index == -1) cout<<" n Sorry!! Given element could not be found.n"; else cout<<"n Element found at index: "<< index <<" , Position: "<<index + 1<<endl; getch(); return 0 ; } int Bsearch(int AR[ ], int size, int item) //function to perform Binary search {int beg, last, mid; beg = 0; last = size - 1; while (beg<= last) { mid = (beg + last)/2; if (item == AR[mid]) return mid; else if(item > AR[mid]) beg = mid + 1; else last = mid- 1; } return -1 ; // the control will reach here only when item is not found } output:- 44
  • 13.
  • 14.
    Selection Sort inArrAy #include<iostream.h> #include<conio.h> void SelSort(int [], int); //function for selection sort int main() { clrscr(); int AR[50], ITEM, N, index; // array can hold max. 50 elements cout<<" How many elements do U want to create array with? (max. 50) ..." ; cin>>N; cout<<" n Enter Array elements ... "; for(int i = 0; i < N ; i++) cin >> AR[i]; SelSort(AR, N); cout <<" nn The Sorted array is as shown below ... n "; for(i=0; i<N; i++) cout<<AR[i]<<" "<<endl; getch(); return 0; } void SelSort(int AR[ ], int size) //function to perform selection sort { int small, pos, tmp; for(int i = 0; i < size ; i++) { small = AR[i]; pos = i; for(int j = i+1 ; j< size; j++) { if ( AR[j]< small) { small = AR[j]; pos = j;} } tmp = AR[i]; AR[i]= AR[pos]; AR[pos] = tmp; cout<<" n Array after pass - "<< i+1<<"-is :"; for (j= 0; j< size; j++) cout<< AR[j]<<" "; } } oUtPUt:- 44
  • 15.
  • 16.
    inSertion Sort inArrAy #include<iostream.h> #include<limits.h> // for INT_MIN #include<conio.h> void InsSort(int [ ], int) ; int main() { clrscr(); int AR[50], ITEM, N, index; // array can hold max. 50 elements cout << " How many elements do U want to create array with? (max. 50) ... " ; cin>>N ; cout<<" n Enter Array elements ... " ; for(int i = 1 ; i <= N ; i++) cin >> AR[i] ; InsSort(AR, N) ; cout <<" the Sorted array is as shown below ... n"; for(i = 1 ; i <= N ; i++) cout << AR[i] << " " << endl ; getch(); return 0; } void InsSort (int AR[ ], int size) // function to perform Insertion Sort { 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--; } AR[j+1] = tmp; cout<<" Array after pass -" <<i<< "- is: " ; for(int k = 1; k <= size; k++) cout <<AR[k]<<" " << endl; } } oUtPUt:- 44
  • 17.
    inSertion At thebeginning of A linked liSt #include<iostream.h> #include<process.h> struct Node { int info ; Node * next; } *start, *newptr, *save, *ptr ; Node * Create_New_Node(int) ; void Insert_Beg( Node* ) ; void Display( Node* ) ; int main() { start = NULL ; int inf; char ch = 'Y' ; while ( ch == 'Y' || ch == 'Y' ) { system ( " cls " ) ; cout<< "n Enter INFOrmation for the new node ... "; cin>>inf ; cout <<"n Creating New Node!! Press Enter to continue ... " ; system ( "pause") ; newptr = Create_New_Node( inf ); if ( newptr != NULL) { cout<<"nn New Node Created Successfully. Press Enter to continue ... " ; system ( "pause") ; } else { cout<< "n cannot create new node!!! Aborting !!n" ; system ( "pause") ; exit(1) ; } cout<<"nn Now inserting this node in the beginning of List ... n" ; cout<<"Press Enter to continue ... n" ; system ( "pause") ; Insert_Beg( newptr ) ; cout<<"n Now the list is : n" ; Display( start) ; cout<<"n Press Y to enter more nodes, N to exit ... n" ; cin>>ch ; } return 0 ; } Node * Create_New_Node( int n ) { ptr = new Node; ptr -> info = n ; ptr -> next = NULL; return ptr ; } void Insert_Beg( Node* np) { if ( start == NULL) start = np ; else { save= start ; start = np ; np -> next = save ; } } void Display( Node*np ) // function to Display list { while ( np != NULL) { cout<<np->info<<" ->"; np = np->next ; } cout << "!!!n" ; } 44
  • 18.
  • 19.
    bUbble Sort inArrAy #include<iostream.h> #include<conio.h> void BubbleSort(int [ ], int) ; // function for bubble sort int main() { clrscr(); int AR[50], ITEM, N, index ; // array can hold max. 50 elements cout<< " How many elements do U want to create array with? (max. 50) ... "; cin>>N; cout<<" nEnter Array elements ... n" ; for(int i = 0 ; i < N ; i++) cin >>AR[i]; BubbleSort(AR, N) ; cout<<"nThe Sorted array is as shown below ... n" ; for(i = 0 ; i < N ; i++) cout<<AR[i] << " "<< endl ; getch(); return 0; } void BubbleSort(int AR[ ], int size) // function to perform Bubble Sort { int tmp, ctr = 0 ; for(int i = 0; i<size; i++) { for (int j = 0; j< (size-1)-i; j++) { if (AR[j] > AR[j+1] ) { tmp = AR[j] ; AR[j] = AR[j+1] ; AR[j+1]= tmp; } } cout<< "Array after iteration - " << ++ctr<<" - is: "; for(int k = 0; k < size ; k++) cout<< AR[k]<<" "<<endl; } } oUtPUt:- 44
  • 20.
    Merging of twoArrAy initiAlly in AScending order And the reSUltAnt AlSo in AScending order #include<iostream.h> #include<conio.h> void main() { clrscr(); int a[100],b[100],c[100],n,m,i,j,k,s; cout<<"nn Enter No. of Elements in First Array : "; cin>>n; cout<<"n Enter Elements in Ascending Order:n"; for(i=1;i<=n; i++) { cin>>a[i]; } cout<<"nEnter No. of Elements in Second Array : "; cin>>m; cout<<"nEnter Elements in Ascending Order:n"; for(i=1;i<=m;i++) { cin>>b[i]; } i=1,j=1; for(k=1;k<=n+m;k++) { if(a[i]<b[j]) { c[k]=a[i]; i++; if(i>n) goto b; } else { c[k]=b[j]; j++; if(j>m) goto a; } } a: for(s=i;s<=n;s++) // Copy the Remaining Elements of Array A to C { k++; c[k]=a[s]; } b: for(s=j;s<=m;s++) // Copy the Remaining Elements of Array B to C { k++; c[k]=b[s]; } cout<<"n nAfter Merging Two Arrays:n"; for(k=1;k<=n+m; k++) { cout<<c[k]<<endl; } getch(); } 44
  • 21.
  • 22.
    cAlcUlAting AreA USingfUnction overloAding #include<iostream.h> #include<conio.h> #include<math.h> float area (float a, float b, float c) {float s, ar; s = (a + b + c)/ 2; ar = sqrt(s*(s - a)*(s - b)*(s - c)); return ar; } float area (float a, float b) { return (a*b); } float area (float a) { return (a*a); } int main () { clrscr (); int choice, ch; float s1, s2, s3, ar; cout<<"n Area menu n"; cout<<"1. Triangle n"<<"2. Square n"<<"3. Rectangle n"<<"4. Exit n"; cout<<"Enter your choice n"; cin>>choice; switch (choice) { case 1: cout<<"Enter the three sides :- "; cin>>s1>>s2>>s3; ar = area(s1,s2,s3); cout<<"the area is "<<ar<<"n"; getch(); break; case 2: cout<<"Enter the side :- "; ar = area(s1); cout<<"the area is "<<ar<<"n"; getch(); break; cin>>s1; case 3: cout<<"Enter the two sides :- "; cin>>s1>>s2; ar = area(s1,s2); cout<<"the area is "<<ar<<"n"; getch(); break; case 4: break; default: cout<<"n Wrong Choice n"; }; return 0; } 44
  • 23.
  • 24.
    ProgrAM to obtAinMArkS And dAte of birth of StUdent And Print it USing the concePt of neSted StrUctUre #include<iostream.h> #include<conio.h> int main() { clrscr(); struct dob { short day; short month; struct student { int roll_num; float marks1, marks2, marks3; dob D1; }stu1; short year; }D1; cout<<"Enter roll number of the student n"; cin>>stu1.roll_num; cout<<"Enter marks of the students in the three subjects n"; cin>>stu1.marks1>>stu1.marks2>>stu1.marks3; cout<<"Enter Date of birth of the student n"; cin>>stu1.D1.day>>stu1.D1.month>>stu1.D1.year; cout<<"nnn Student details Follow n"; cout<<"roll number n"<<stu1.roll_num<<"n"; cout<<"Marks n"<<stu1.marks1<<" , "<<stu1.marks2<<" , "<<stu1.marks3<<"n"; cout<<"Date of birthn"<<stu1.D1.day<<" , "<<stu1.D1.month<<" , "<<stu1.D1.year<<"n"; getch(); return 0; } oUtPUt:- 44
  • 25.
    Program to disPlayemPloyee details using array and structure #include<iostream.h> #include<conio.h> int main() { clrscr(); struct employee { char name[4], desig[10]; int emp_id; float basic; }emp1; cout<<"Enter name of the employee n"; cin.getline(emp1.name,4); cout<<"Enter employee id of the employee n"; cin>>emp1.emp_id; cout<<"Enter basic pay of the employee n"; cin>>emp1.basic; cout<<"nnn Employee Details Follown"; cout<<"Namen"; cout.write(emp1.name,4); cout<<"n"; cout<<"Employee idn"<<emp1.emp_id<<"n"; cout<<"basic payn"<<emp1.basic; getch(); return 0; } outPut:- 44
  • 26.
    Program to disPlayWorker’s details using class and objects #include<iostream.h> #include<conio.h> class employee { int emp_num; char emp_name[20]; float emp_basic, sal, emp_da, net_sal, emp_it; public: void get_details(); void find_net_sal(); void show_emp_details(); }; void employee :: get_details() { cout<<"nEnter employee number:n"; cin>>emp_num; cout<<"nEnter employee name:n"; cin>>emp_name; cout<<"nEnter employee basic:n"; cin>>emp_basic; } void employee :: find_net_sal() { emp_da=0.52*emp_basic; emp_it=0.30*(emp_basic+emp_da); net_sal=(emp_basic+emp_da)-emp_it; } void employee :: show_emp_details() { cout<<"nnnDetails of : "<<emp_name; cout<<"nnEmployee number: "<<emp_num; cout<<"nBasic salary : "<<emp_basic; cout<<"nEmployee DA : "<<emp_da; cout<<"nIncome Tax : "<<emp_it; cout<<"nNet Salary : "<<net_sal; } int main() { employee emp[10]; int i,num; clrscr(); cout<<"nEnter number of employee detailsn"; cin>>num; 44
  • 27.
    for(i=0;i<num;i++) { cout<<"Enter Details Foremployee number"<<i + 1; } for(i=0;i<num;i++) emp[i].find_net_sal(); for(i=0;i<num;i++) } emp[i].show_emp_details(); getch(); return 0; outPut:- 44 emp[i].get_details();
  • 28.
    Program to shoWWorking of constructor and destructor #include<iostream.h> #include<conio.h> class Base { public: Base () { cout<<"Base Class constructor" << endl; } ~Base () { cout<<"Base Class destructor" <<endl; } }; class Derived : public Base { public: Derived() { cout<<"Derived Class constructor" << endl; } ~Derived() { cout<<"Derived Class destructor" << endl; } }; void main( ) { clrscr(); { Derived x; getch(); } for(int i = 0; i< 10 ;i++); cout<<"object now out of scope n"; outPut:- 44 }
  • 29.
    Program to Printthe address and the resPective values of different numbers using the concePt of array Pointers #include<iostream.h> #include<conio.h> int main() { clrscr(); int *ip[5]; // array of 5 int pointers int f = 65, s = 67, t = 69, fo = 70, fi = 75; // initialization ip[0] = &f; ip[1] = &s; ip[2] = &t; ip[3] = &fo; ip[4] = &fi; for (int i = 0; i < 5; i++) cout<< " the pointer ip["<<i<<"] points to" <<*ip[i]<<"n"; cout<<" the base address of array ip of pointers is "<<ip<<"n"; for(i = 0; i< 5; i++) cout<< " the address stored in ip["<<i<<"] is "<<ip[i]<<"n"; getch(); return 0; } outPut:- 44
  • 30.
    Program to uPdatea data file containing structure objects using data file handling #include<iostream.h> #include<conio.h> #include<fstream.h> struct student { char name[10]; int roll_num; float cent_marks; }stu1; int main() { clrscr(); ofstream fout; fout.open("Student.dat", ios::app); cout<<"Enter name of the student n"; cin.getline(stu1.name,10); cout<<"Enter roll number of the student n"; cin>>stu1.roll_num; cout<<"Enter percentage marks of the student n"; cin>>stu1.cent_marks; fout.write((char*) &stu1, sizeof(stu1)); cout<<"Record successfully Updated"; getch(); return 0; } outPut:- 44
  • 31.
    Program to Performdeletion at beginning of stack- imPlemented using linked list #include<iostream.h> #include<conio.h> #include<stdlib.h> #include<process.h> // for exit( ) struct Node { int info ; Node * next; } *start, *newptr, *save, *ptr,*rear ; Node * Create_New_Node(int) ; void Insert( Node* ) ; void Display( Node* ) ; void DelNode(); int main() { clrscr(); start = rear = NULL ; // In the beginning list is empty, thus, pointers are NULL int inf ; char ch = 'Y' ; while(ch == 'y' || ch == 'Y') { system ( " cls " ) ; cout<<" n Enter INFOrmation for the new node ... " ; cin >> inf ; newptr = Create_New_Node( inf ) ; if ( newptr == NULL) { cout<<" n cannot create new node!!! Aborting!!n "; system ( "pause") ; exit(1) ; } Insert( newptr ); cout<< " n Press Y to enter more nodes, N to exit... n " ; cin>>ch; } system ( " cls " ) ; do { cout<<" n The List now is: n " ; Display( start); system ( "pause") ; cout<<" Want to delete first node? (y/n) ... " ; cin >> ch ; if( ch=='y' || ch=='Y' ) DelNode() ; } while(ch=='y' || ch=='Y') ; getch(); return 0 ; } Node * Create_New_Node( int n ) { ptr = new Node; ptr -> info = n ; ptr -> next = NULL; return ptr ; } 44
  • 32.
    void Insert( Node*np) // Function to insert node in the list { if ( start == NULL) start = rear = np ; else { rear -> next = np ; rear = np ; } } void DelNode( ) // function to delete a node from the begining of list { if (start == NULL) cout <<"UNDERFLOW CONDITION !!! n"; else { ptr = start; start = start -> next ; delete ptr ; } } void Display( Node* np ) // function to Display list { while ( np != NULL) {cout<<np->info<<" ->"; np = np->next ; } cout<< "!!!n" ; } outPut:- 44
  • 33.
    Program to Pushin elements in stack - imPlemented using linked list #include<iostream.h> #include<stdlib.h> #include<process.h> struct Node { int info ; Node * next; } *top, *newptr, *save, *ptr; Node * Create_New_Node( int ); //prototype void Push( Node* ); // prototype void Display( Node* ); // prototype int main( ) { int inf ; char ch = 'Y'; while ( ch == 'y' || ch == 'Y' ) { cout<<" n Enter INFOrmation for the new node ... " ; cin>> inf; newptr = Create_New_Node( inf); if ( newptr == NULL) { cout<<" n cannot create new node!!! Aborting!!n "; exit(1) ; } Push( newptr ) ; cout<<"n now the linked-stack is :n"; Display(top); cout<<" n Press Y to enter more nodes, N to exit ... " ; cin>>ch; } return 0 ; } Node * Create_New_Node( int n ) { ptr = new Node; ptr -> info = n ; ptr -> next = NULL ; return ptr ; } void Push( Node* np) { if ( top == NULL) top = np ; else { save= top ; top = np ; np -> next = save ; } } void Display( Node* np ) { while ( np !=NULL ) { cout<<np -> info<<" ->";np = np -> next; } cout<<" !!!n" ; } 44
  • 34.
  • 35.
    Program to PoPout elements in stack - imPlemented using linked list #include<iostream.h> #include<iostream.h> #include<stdlib.h> #include<process.h> // for exit( ) struct Node { int info ; Node * next; } *top, *newptr, *save, *ptr; Node * Create_New_Node( int ); //prototype void Push( Node* ); // prototype void Display( Node* ); // prototype void Pop( ); // prototype int main( ) { top = NULL ;// In the beginning linked-stack is empty, thus, pointers are NULL int inf ; char ch = 'Y'; while ( ch == 'Y' || ch == 'Y' ) { cout<<" n Enter INFOrmation for the new node ... " ; cin>> inf; newptr = Create_New_Node( inf); if ( newptr == NULL) { cout<<" n cannot create new node!!! Aborting!!n "; system ("pause") ; exit(1) ; } Push( newptr ) ; cout<< " n Press Y to enter more nodes, N to exit ... " ; cin>>ch; } system ( " cls" ); do { cout<<" n The Stack now is: n " ; Display( top) ; system ( "pause"); cout<<" Want to pop an element? (y/n) ... " ; cin >> ch; if ( ch == 'Y' || ch == 'Y' ) Pop( ) ; } while (ch == 'Y' || ch == 'Y') ; return 0 ; } Node*Create_New_Node(int n) { ptr = new Node; ptr -> info = n ; ptr -> next = NULL ; return ptr ; } void Push( Node* np) 44
  • 36.
    { if (top == NULL) top = np ; else { save= top ; top = np ; np -> next = save ; } } void Pop( ) { if (top == NULL) cout<<" UNDERFLOW!!!n"; else { ptr = top ; top= top -> next ; delete ptr ; } } void Display( Node* np ) { while ( np !=NULL ) { cout<<np -> info<<" ->";np = np -> next; } cout<<" !!!n" ; } outPut:- 44
  • 37.
    Program for ImPlementatIonof lInked Queues #include<iostream.h> #include<conio.h> #include<process.h> struct Node { int info; Node * next; } *front, *newptr, *save, *ptr, *rear ; Node * Create_New_Node( int) ; void Insert_End( Node* ) ; void Display( Node* ) ; int main( ) { front = rear = NULL; // In the beginning Queue is empty int inf; char ch = 'y' ; while (ch == 'y' || ch == 'Y') { cout<<" n Enter INFOrmation for the new node ... " ; cin>>inf ; newptr = Create_New_Node( inf ) ; if ( newptr == NULL) { cout<< "ncannot create new node!!! Aborting!!n"; Insert_End( newptr ) ; cout<< " nNow the Queue ( Front ... to ... Rear) is : n " ; Display( front) ; cout<< " n Press Y to enter more nodes, N to exit ... " ; cin>>ch; } return 0 ; } Node * Create_New_Node( int n ) { ptr = new Node; ptr -> info = n ; ptr -> next = NULL; return ptr ; } void Insert_End( Node* np) { if (front == NULL) front = rear = np ; else { rear -> next = np ; rear = np; } } void Display( Node* np ) // function to Display Queue { while ( np != NULL) { cout<< np -> info<<" ->" ; np = np -> next; } cout<<" !!!n " ; } 44 exit(1); }
  • 38.
  • 39.
    Program to ImPlementcIrcular Queue #include<iostream.h> #include<stdlib.h> #include<process.h> int Insert_in_CQ(int [ ], int); void Display(int [ ], int, int) ; int Del_in_CQ( int CQueue[ ] ); const int size = 7; int CQueue[size], front= -1, rear = -1; int main() { int Item, res, ch; do{ system ( " cls " ); cout<<" ttt Circular Queue Menun "; cout<<" t 1. Insertn"<<" t 2. Deleten "<<" t 3. Displayn "<<" t 4. Exitn "; cout<<" Enter your choice (1-4) ... "; cin>>ch; switch(ch) { case 1 : cout <<"n Enter ITEM for insertion: "; cin>>Item; res= Insert_in_CQ(CQueue, Item); if (res == -1 ) cout<<" OVERFLOW!!! n"; else { cout<<" n Now the Cir _Queue is : n "; Display(CQueue, front, rear); } system( "pause"); break; case 2: Item = Del_in_CQ( CQueue); cout<<" Element deleted is : "<<Item<<endl; Display(CQueue, front, rear); system ( "pause"); break ; case 3: Display(CQueue, front, rear) ; system ( "pause"); break ; case 4: break; default: cout<<" Valid choices are 1...4 onlyn " ; system ( "pause") ; break; } } while(ch != 4 ) ; return 0 ; } int Insert_in_CQ(int CQueue[ ], int ele) // function to insert element in CIR_Queue { if ( (front == 0 && rear == size-1 )|| (front == rear+1 ) ) return -1 ; else if (rear == -1 ) front = rear = 0 ; else if ( rear == size -1 ) rear = 0 ; else rear++ ; CQueue[rear] = ele ; return 0 ; } void Display(int CQueue[ ], int front, int rear) { int i = 0 ; cout<<" n Cir_Queue is: n " <<" ( Front shown as >>>, Rear as <<< AND free space as - )n " ; 44
  • 40.
    if (front ==-1 ) return ; if ( rear >= front) { for(i = 0; i < front; i++) cout<< "-"; cout<<">>>"; for(i = front; i < rear; i++) cout << CQueue[i] << " <-" ; cout<<CQueue[rear]<<"<<<"<<endl; } else { for(i = 0; i< rear; i++)cout<<CQueue[i]<<" <-"; cout<<CQueue[rear]<<"<<<" ; for(;i < front;i++) cout<<"-"; cout<<">>>"; for(i = front; i < size; i++) cout<< CQueue[i]<<" <-" ; cout<<" t ... wrap around ... " ; } } int Del_in_CQ( int CQueue[ ] ) { int ret; if ( front == -1 ) return -1 ; else { ret = CQueue[front]; if ( front == rear) front = rear = -1; else if ( front == size-1) front = 0; //wrap arol md else front++; } return ret; } outPut:- 44
  • 41.
    Program to uPdatea data fIle contaInIng class objects usIng data fIle handlIng #include<iostream.h> #include<conio.h> #include<stdlib.h> #include<fstream.h> class student { char name[10], grade; float marks; public: void getdata( void) { char ch; cin.get(ch); cout<<"Enter name : " ; cin.getline(name, 10); cout<<"Enter grade : " ; cin>>grade; cout<<"Enter marks : " ; cout<<"n"; cin >> marks ; cout<<"n"; } }arts[1]; // End of Class int main() { system ("cls"); fstream fillin; fillin.open("Student.dat",ios::app); if (!fillin) { cout<<" cannot open file !! n " ; return 1 ; } cout<<"Enter details of student to be saved"; arts[1].getdata(); fillin.write((char*) &arts[1], sizeof(arts[1])); cout<<"Record successfully Updated"; getch(); return 0; } 44
  • 42.
    sQl command formanIPulatIon of two tables=. workers and desIgnatIon SELECT * FROM workers W, designation D WHERE W.WID = D.DID; sQl command for followIng I. to dIsPlay w-Id, fIrst name, address and cIty of all emPloyees lIvIng In new york from the workers table SELECT w-id, first name, address, city FROM WORKERS WHERE city = ‘New York’; II. to dIsPlay the content of workers table In ascendIng order of lastname SELECT * FROM WORKERS GROUP BY lastname; sQl command for dIsPlayIng all clerks from the tables workers and desIgnatIon where salary Is calculated as salary + benefIts SELECT name, salary + benifits FROM workers W, designation D WHERE D.Designation = ‘clerk’; sQl command for dIsPlayIng mInImum salary among managers and clerks from the table desIgnatIon SELECT name, MIN(salary) FROM Designation WHERE( ( designation = MANAGER ) or ( designation = clerk ) 44
  • 43.
    sQl command fordIsPlayIng detaIls of emPloyees whose name stat wIth a SELECT * FROM Employees WHERE name LIKE ”A%” 44
  • 44.
    Program to PushIn element In stack ImPlemented usIng array #include<iostream.h> #include<conio.h> #include<stdlib.h> #include<process.h> // for exit( ) int Push(int [], int&, int) ; //prototype void Display(int [ ], int) ; // prototype const int size = 50 ; int main() { clrscr(); int Stack[size], Item, top = -1, res ; char ch = 'y' ; system ( " cls " ) ; while (ch == 'y' || ch == 'Y') { cout<<" n Enter ITEM for insertion: " ; cin>>Item ; res = Push(Stack, top, Item) ; if (res == -1 ) { cout<<" OVERFLOW!!! Aborting!! n "; exit(1) ;} cout<<" n The Stack now is : n "; Display(Stack, top) ; cout<<" n Want to insert more elements? (y/n) ... " ; cin>>ch ; } getch(); return 0 ; } int Push(int Stack[], int & top, int ele) { if (top == size-1) return -1 ; else { top++; Stack[top] = ele; } return 0 ; } void Display(int Stack[], int top) { cout<<Stack[top] <<" <-- "<< endl ; for(int i = top-1 ;i >= 0 ; i--) cout<<Stack[i]<<endl ; } 44
  • 45.
  • 46.
    Program to PoPout element In stack ImPlemented usIng array #include<iostream.h> #include<conio.h> #include<process.h> // for exit( ) int Pop(int[],int&) ; // prototype int Push(int [], int&, int); // prototype void Display(int [], int);// prototype const int size = 50; int main() { int Stack[size], Item, top = -1, res; char ch = 'Y' ; while (ch == 'y' || ch == 'Y') { cout<<" n Enter ITEM for insertion: " ; cin>> Item; res = Push(Stack, top,Item) ; if (res == -1 ) { cout<<" OVERFLOW!!! Aborting!! n " ; exit(1); } cout<<" n The Stack now is : n " ; Display(Stack, top); cout<<" n Want to insert more elements? (y/n) ... " ; cin>>ch; } cout<<" Now deletion of elements begins ... n " ; ch = 'Y' ; while ( ch == 'y' || ch == 'Y' ) { res = Pop(Stack, top); if (res == -1 ) { cout<<" UNDERFLOW!!! Aborting!! n "; exit(1); } else { cout<< " nElement deleted is : " << res << endl ; cout<< " n The Stack now is : n " ; Display(Stack, top) ; } cout<<" n Want to delete more elements? (y/n) ... " ; cin>>ch; 44
  • 47.
    } return 0; } int Push(intStack[ ], int & top, int ele) // function to insert element { if (top == size-1 ) return -1 ; else { top++ ; Stack[top] = ele ; } return 0 ; } int pop(int Stack[], int & top) // function to pop element { int ret ; if (top == -1 ) return -1 ; else { ret = Stack[top] ; top--; } return ret ; } void Display(int Stack[], int top) { if ( top == -1 ) return ; cout<< Stack[top]<<" <--"<<endl ; for( int i = top-1; i >= 0; i--) cout<<Stack[i]<<endl ; } DISCLAIMER :I HAVE ALSO MADE THIS PROJECT TAKING HELP FROM INTERNETI EXPREE MY REGARDS WHO ARE ACTUALLY BEHIND THIS PROJECT. I HAVE UPLOADED THIS ONLY SO THAT MORE PEOPLE CAN TAKE HELP FROM THIS UPLOAD THROUGH MY PROFILE IN SLIDESHARE… TO REGISTER YOUR OBJECTION TO THIS UPLOAD PLZ COMMENT UNDER THE PRESENTATION IN THE WEBSITE 44
  • 48.