1. The document contains details of Pranav Ghildiyal, a class XII student. It includes a table of contents listing 24 programs with page numbers.
2. The programs cover concepts like arrays, structures, classes, inheritance, file handling, stacks, queues and more. Algorithms covered include sorting, searching and linked lists.
3. The document serves as an index for various C++ programs written by the student to demonstrate different concepts and data structures.
This document contains some programs of C using Data structures, like Stack, LinkedList, queue, Fibonacci series, addition and multiplication of two matrices,etc.
This document contains some programs of C using Data structures, like Stack, LinkedList, queue, Fibonacci series, addition and multiplication of two matrices,etc.
Data Structures are the programmatic way of storing data so that data can be used efficiently. Almost every enterprise application uses various types of data structures in one or the other way. This tutorial will give you a great understanding on Data Structures needed to understand the complexity of enterprise level applications and need of algorithms, and data structures.
C++ Searching & Sorting5. Sort the following list using the select.pdfRahul04August
C++ Searching & Sorting
5. Sort the following list using the selection sort algorithm. Show the list after each iteration of
the outerforloop.
36, 55, 17, 35, 63, 85, 12, 48, 3, 66
6. Consider the following list: 5, 18, 21, 10, 55, 20
The first three keys are in order. To move 10 to its proper position using the insertion sort as
described in this chapter, exactly how many key comparisons are executed?
7. Consider the following list: 7, 28, 31, 40, 5, 20
The first four keys are in order. To move 5 to its proper position using the insertion sort as
described in this chapter, exactly how many key comparisons are executed?
8. Consider the following list: 28, 18, 21, 10, 25, 30, 12, 71, 32, 58, 15
This list is to be sorted using the insertion sort algorithm. Show the resulting list after six
passes of the sorting phase – that is, after six iterations of the for loop.
9. Perform the insertion sort algorithm using the following list of keys: 18, 8, 11, 9, 15, 20, 32,
61, 22, 48, 75, 83, 35, 3
Show the list after each iteration. Exactly how many key comparisons are executed to sort this
list using insertion sort?
10. a. The performance of bubble sort can be improved if we stop the sorting process as soon as
we find that in an iteration, no swapping of elements takes place. Write a function that
implements bubble sort algorithm using this fact.
b. Using the algorithm that you designed in part (a), find the number of iterations that are needed
to sort the list: 65, 14, 52, 43, 75, 25, 80, 90, 95.
11. Suppose that L is a sorted list of 4096 elements. What is the maximum number of
comparisons made by binary search to determine whether an item is in L?
12. Suppose that the elements of a list are in descending order, and they need to be put in
ascending order. Write a C++ function that takes as input an array of items in descending order
and the number of elements in the array. The function must not incorporate any sorting
algorithms, that is, no item comparisons should take place.
Solution
# include
# include
# include
#include
#include
#include
#include
// Function related to sorting in class sorting
class sorting
{
int array[50],array1[50],final[100],i,n,m,j;
public:
// Function to read an array
void read();
// Function to read arrays for merge sort
void read_mer();
// Function to display an array
void display();
// Function to perform bubble sort
void bub_sort();
// Function to perform selection sort
void Sel_sort();
// Function to perform insertion sort
void Ins_sort();
// Function to perform quick sort
void Qui_sort();
// Function to perform heap sort
void Heap_sort();
// Function to build a heap
void heap(int array[], int n);
// Function to interchange the value of root node with a
// child node in heap sort
void below_heap(int array[], int first, int last);
// Function to perform merges sort
void Mer_sort();
// Function to perform shell sort
void Shell_sort();
// Function to split the array into two halves during quick sort
void partition(int arra.
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
ARRAYS
TYPES OF ARRAYS
MULTIDIMENSIONAL ARRAYS
CHARACTER HANDLING IN C
STRING HANDLING IN C
QUIZ SET 2
So I already have most of the code and now I have to1. create an .pdfarjuncollection
So I already have most of the code and now I have to:
1. create an index file to keep track of all the inventory IDs and their locations
2. modify my class to be able to display any record with a given ID without searching through
the entire file
// This program displays the contents of the inventory file.
#include
#include
#include
using namespace std;
class DB{
// Declaration of InventoryItem structure
class InventoryItem
{
public:
char Id[5];
char desc[31];
int qty;
float price;
};
string DBname;
fstream inventory;// (DBname, ios::in | ios::binary);
public: DB(string N){ DBname = N; }// constructor
private:void Input(InventoryItem &Inv)
{
cout << \"Please type Id\" << endl;
cin >> Inv.Id;
cout << \"Please type Desc\" << endl;
cin >> Inv.desc;
cout << \"Please type qty\" << endl;
cin >> Inv.qty;
cout << \"Please type price\"<> Inv.price;
}
public: void Create(int Nrec)
{
inventory.open(DBname, ios::out | ios::binary);
// fstream inventory(\"Inventory.dat\", ios::out | ios::binary);
InventoryItem record = { \"\", \" \", 0, 0.0 };
// Write the blank records
for (int count = 0; count < Nrec; count++)
{
Input(record);
cout << \"Now writing record \" << count << endl;
inventory.write(reinterpret_cast(&record), sizeof(record));
}
// Close the file.
inventory.close();
return ;
}
public: void Display()
{
inventory.open(DBname, ios::in | ios::binary);
InventoryItem record = { \"\",\"\", 0, 0.0 };
// Now read and display the records
inventory.read(reinterpret_cast(&record),
sizeof(record));
while (!inventory.eof())
{
cout << \"Inventory Id: \";
cout << record.Id << endl;
cout << \"Description: \";
cout << record.desc << endl;
cout << \"Quantity: \";
cout << record.qty << endl;
cout << \"Price: \";
cout << record.price << endl << endl;
inventory.read(reinterpret_cast(&record), sizeof(record));
}
// Close the file.
inventory.close();
return;
}
};
int main()
{
DB Mydb(\"Inventory.dat\"); // declare a database
Mydb.Create(3); // load data
cout << \"***** display ***\" << endl;
Mydb.Display(); // print entire database
// implement the following function
// Mydb.Show(\"AB001\"); // display record with given ID
char C; cin >> C; return 0;
}
Solution
Programming Code in C++
#include
#include
#include
#include
#include
#include
using namespace std;
//Structure.
struct InvStruct
{
string iName;
int iQuantity;
double iPrice;
};
const int MAXSIZE = 9;
void addToInventory(InvStruct aList[], int& aSize);
void displayInventory(const InvStruct aList[], int aSize);
void saveToFile(const InvStruct aList[], int aSize);
void openAFile(InvStruct aList[], int& aSize);
char menuResponse();
int main(int argc, char *argv[])
{
InvStruct iRecords[MAXSIZE];
int noOfRec = 0;
bool reRun = true;
do
{
cout << \"Inventory has \" << noOfRec << \" items\" << endl;
switch (menuResponse())
{
case \'A\':
addToInventory(iRecords, noOfRec);
break;
case \'D\':
displayInventory(iRecords, noOfRec);
break;
case \'O\':
openAFile(iRecords, noOfRec);
break;
case \'S\':
saveToFile(iRecords, noOfRe.
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
1sequences and sampling. Suppose we went to sample the x-axis from Xmin to Xmax using a
step size of step
A)Draw a picture of what is going on.
B) Write a expression for n the total number of samples involved (in terms of Xmin, Xmax and
step)
C) Write out the sequence of x-samples
D) Write a direct and general expression for xi that captures the sequence
E) Write a recursive expression for the sequence
F) Write a program to compute and store the x-samples over the range -5x5 using a step size of
0.1 do everything in main ()
2 . We talked about the following string functions that are available in C (as long as you include
string.h):
int strlen(char str[])
void strcpy(char str1[], char str2[])
void strcat(char str1[], str2[])
Write your own versions of these functions; for example: int paul_strlen(int char str[]). Hint: for
your version of the strlen function, start at the first character in the array and keep counting until
you find the ‘\\0’ character (use a while loop for this). Note: Use your version of the strlen
function in the strcpy and strcat functions.
9. We want to insert a number into an array.
(a) Formulate the problem mathematically with two sequences: x and y. (b) Write a function of
the form:
insertNumIntoArray(int n, int array[], int num, int index)
The function inserts num into the array at the specified index. The rest of the array then follows.
For example, if num = 9 and index = 3 and array = [7 2 8 8 3 1 2] then the function will produce:
array = [7 2 8 9 8 3 1 2]
Note: assume that array is properly dimensioned to have at least 1 extra space for storage.
10. Repeat #2 by for the delete operation; that is, we want to delete a single element (at a
specified index) from an array; for example, suppose index = 3 and array = [50 70 10 90 60 20],
then the result will be
array: [50 70 10 60 20]
11. Repeat #2 by for an insert operation where we are inserting several values into the array. The
function should be of the form:
int insertArrayIntoArray(int n, int inArray[],
int nInsert, int insertArray[], int outArray[], int index)
The dimension of outArray is returned (explicitly). For example:
inArrayarray: [7 2 8 6 3 9]
insertArray: [50 60 70]
index: 2
outArray: [7 2 50 60 70 8 6 3 9]
Assume that outArray is large enough to hold all n + nInsert values.
Solution
#include
//Simulates strlen() library function
int paul_strlen(char str[])
{
int l;
for(l = 0; str[l] != \'\\0\'; l++) ;
return l;
}
//Simulates strcpy() library function
void paul_strcpy(char str1[], char str2[])
{
int c;
for(c = 0; str1[c] != \'\\0\'; c++)
str2[c] = str1[c];
str2[c] = \'\\0\';
printf(\"\ Original String: %s\", str1);
printf(\"\ Copied String: %s\", str2);
}
//Simulates strcat() library function
void paul_strcat(char str1[], char str2[])
{
int i, j;
for(i = 0; str1[i] != \'\\0\'; i++) ;
for (j = 0; str2[j] != \'\\0\'; i++, j++)
{
str1[i] = str2[j];
}
str1[i] = \'\\0\';
printf(\"\ Concatenated String: %s\", str1);
}
int main()
{
char data1[20], data2[20];
pri.
Similar to CBSE Class XII Comp sc practical file (20)
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
2. 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
4. 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
6. 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
7. 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
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 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
}
11. 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
12. 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
14. 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
16. 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
17. 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
19. 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
20. 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
22. 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
24. 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
25. 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
26. 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
28. 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
}
29. 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
30. 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
31. 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
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 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
35. 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
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 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); }
39. 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
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 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
42. 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
43. sQl command for dIsPlayIng detaIls of emPloyees
whose name stat wIth a
SELECT * FROM Employees
WHERE name LIKE ”A%”
44
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
46. 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
47. }
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