You are on page 1of 64

Page 1 of 64

Index
Demonstration of sorting an array using bubble sort method. ________________ 3

Demonstration of sorting an array using insertion sort method _______________ 5

Demonstration of sorting an array using selection sort method _______________ 7

Write a program for searching in an array using “Linear Search” ____________ 9

Write a program for searching in an array using “Binary Search” ___________ 11

Create an application to enter the rollno, name of the student and marks in
five subjects in a user defined structure Student. _________________________ 14

Write a program to demontrate multiple inheritance using three classes.____ 18

Write a program to demonstrate multilevel inheritance using three classes __ 22

Demonstrates Employee class as a constructor _____________________________ 25

Demonstrates Employee class as a destructor ______________________________ 27

Write a data entry program using employee class to create a data file called
EMP1.dat. ________________________________________________________________ 29

Write a program to modify an existing record from EMP1.dat using the


empcode key field sequentially. ____________________________________________ 31

Write a program to delete records one by one from the EMP1.dat file using
the emp.code key field. ___________________________________________________ 34

Basic Stacks operation using Array (Insertion,Deletion and Traveral in a


Stacks) ___________________________________________________________________ 37

Basic Stack operation using Linked List (Insertion, Deletion and Traversal in a
Stack) ____________________________________________________________________ 40

Basic Queue operation using Array (Insertion,Deletion and Traveral in a


Queue) ____________________________________________________________________ 43

Basic Queue operation using Linked List (Insertion,Deletion and Traveral in a


Queue) ____________________________________________________________________ 46
Database Concepts/SQL _______________________________________________________ 49

Page 2 of 64
Demonstration of sorting an array using bubble sort method.

#include <iostream.h>
#include<conio.h>
main()
{
clrscr();
int Num[100], N, i, j, tmp;
cout << "How many numbers you want to sort? ";
cin >> N;
cout << "Please enter " << N << " Values ... \n";
for (i = 0; i < N; i++) {
cout << "Enter number " << i+1 << ": ";
cin >> Num[i];
}
for (i = 0; i < N; i++)
for (j = 0; j < N-1; j++)
if (Num[j] > Num[j+1]) {
tmp = Num[j];
Num[j] = Num[j + 1];
Num[j + 1] = tmp;
}
cout << "The sorted elements are :\n";
for (i = 0; i < N; i++)
cout << Num[i] << " ";
getch();
}

Page 3 of 64
Output

Page 4 of 64
Demonstration of sorting an array using insertion sort method

#include <iostream.h>
#include <conio.h>
main()
{
clrscr();
int Num[100], i, j, N, Tmp, x;
cout << "Enter the number of elements in array: ";
cin >> N;
cout << "Enter the array elements: \n";
for (i = 0; i < N; i++) {
cout << "Enter number " << i + 1 << ": ";
cin >> Num[i];
}
cout << "The original array elements are: ";
for (i = 0; i < N; i++)
cout << Num[i] << " ";
for (i = 1; i < N; i++) {
Tmp = Num[i]; // Extracts the first element of the unsorted part
j = i - 1;
while ((Tmp < Num[j]) && (j >= 0)) {
Num[j + 1] = Num[j];
j = j - 1;
}
Num[j + 1] = Tmp;
}
cout << "\nThe sorted array elements are: ";
for (i = 0; i < N; i++)
cout << Num[i] << " ";
return 0;
}

Page 5 of 64
Output

Page 6 of 64
Demonstration of sorting an array using selection sort method

#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int Num[100], loc, lowest, T, N, i, j, x;
cout << "Enter the number of elements in array: ";
cin >> N;
cout << "Enter the array elements: \n";
for (i = 0; i < N; i++) {
cout << "Enter number " << i + 1 << ": ";
cin >> Num[i];
}
cout << "The original array elements are: ";
for (i = 0; i < N; i++)
cout << Num[i] << " ";

for (i = 0; i < N - 1; i++) {


lowest = Num[i]; loc = i;
for (j = i + 1; j < N; j++) {
if (lowest > Num[j]) {
loc = j;
lowest = Num[j];
}
}
T = Num[i];
Num[i] = Num[loc];
Num[loc] = T;
}
cout << "\nThe sorted array elements are: ";
for (i = 0; i < N; i++)
cout << Num[i] << " ";
getch();
}

Page 7 of 64
Output

Page 8 of 64
Write a program for searching in an array using “Linear Search”

#include<iostream.h>
#include<conio.h>
//linear search function
void linearSearch(int Num[11],int N,int SearchVal){
int ctr=0, pos= -1;
while(ctr <=N) {
if(Num[ctr] == SearchVal) {
pos = ctr + 1;
break; //terminate the loop
}
else
ctr= ctr +1;
}
if (pos >=0)
cout<<"The search value"<< SearchVal<<" 's position is:" <<pos;
else
cout<<"The search value does not found";
}
main()
{
clrscr();
int N,Num[11],i,SearchVal;
cout<<"Enter total numbers for an array:";
cin>>N;
cout<<"Please enter " <<N<< " Values...\n";
for(i=0;i<N;i++){
cout<<"Enter number"<<i+1<<":";
cin>>Num[i];
}
cout<<"Enter the search value:";
cin>>SearchVal;
linearSearch(Num,N,SearchVal);
return 0;
}

Page 9 of 64
OUTPUT

Page 10 of 64
Write a program for searching in an array using “Binary Search”

#include<iostream.h>
#include<conio.h>
//Binary search function
void binarySearch(int Num[11],int N, int SearchVal){
int first=1, last=N-1, find=0, mid=0;
while ((first<=last) && (find==-0)){
mid= (first+last)/2;
if (Num[mid] == SearchVal) {
find = mid;
break; // terminates the loop after search success.
}
else
if(Num[mid] < SearchVal)
first= mid +1;
else
last=mid -1;
}
if (find > 0)
cout<<"\n The position of the element is:"<< ++find;
else
cout<<"\n No, does not found in array.";
}
main()
{
Clrscr();
int N, Num[11],i,j,temp,SearchVal;
cout<<"Enter total numbers for an array:";
cin>>N;
cout<<"Please enter " << N << " Values...\n";
for(i=0;i<N;i++){
cout<<"Enter number" << i+1 <<":";
cin>>Num[i];
}
//sorting array before binary search
//Note. you can skip these lines if youu enter sorted elements.
for(i=0;i<N;i++)
for(j=0;j<N-1;j++)
if(Num[j]> Num[j+1])
{
temp = Num[j];
Num[j]=Num[j+1];

Page 11 of 64
Num[j+1] = temp;
}
cout<<"\n Sorted elements are:";
for(i=0;i<N;i++) {
cout<< Num[i] <<" ";
}
cout<<"\n Enter the search value:";
cin>> SearchVal;
binarySearch(Num,N,SearchVal);
return 0;
}

Page 12 of 64
OUTPUT

Page 13 of 64
Create an application to enter the rollno, name of the student and
marks in five subjects in a user defined structure Student.

#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<iomanip.h>
struct Student
{
int Rollno;
char Name[25];
int Marks[5];
float Total;
float Per;
char Grade[2];
};
void main()
{
clrscr();
int i=0,ctr=1,n=1;
Student Std[100];
char ch='Y';
while(ch=='Y'){
fflush(stdin);
cout<<"Enter students details:"<<endl;
cout<<"----------------------------"<<endl;
cout<<"Enter rollno:";
cin>>Std[ctr].Rollno;
cout<<"Enter name:";
gets(Std[ctr].Name);
for(int i=0;i<5;i++)
{
cout<<"Enter marks for subject:"<<i+1<<":";
cin>>Std[ctr].Marks[i];
Std[ctr].Total=Std[ctr].Total+Std[ctr].Marks[i];

Page 14 of 64
}
Std[ctr].Per=Std[ctr].Total/5;
if(Std[ctr].Per>=91 && Std[ctr].Per<=100)
{strcpy(Std[ctr].Grade,"A1");
cout<<"Your Grade is Calculated as "<<Std[ctr].Grade<<endl;}
else if(Std[ctr].Per>=81 && Std[ctr].Per<91)
{strcpy(Std[ctr].Grade,"A2");
cout<<"Your Grade is Calculated as "<<Std[ctr].Grade<<endl;}
else if(Std[ctr].Per>=71 && Std[ctr].Per<81)
{strcpy(Std[ctr].Grade,"B1");
cout<<"Your Grade is Calculated as "<<Std[ctr].Grade<<endl;}
else if(Std[ctr].Per>=61 && Std[ctr].Per<71)
{strcpy(Std[ctr].Grade,"B2");
cout<<"Your Grade is Calculated as "<<Std[ctr].Grade<<endl;}
else if(Std[ctr].Per>=51 && Std[ctr].Per<61)
{strcpy(Std[ctr].Grade,"C1");
cout<<"Your Grade is Calculated as "<<Std[ctr].Grade<<endl;}
else if(Std[ctr].Per>=41&& Std[ctr].Per<51)
{strcpy(Std[ctr].Grade,"C2");
cout<<"Your Grade is Calculated as "<<Std[ctr].Grade<<endl;;}
else if(Std[ctr].Per>=33 && Std[ctr].Per<41)
{strcpy(Std[ctr].Grade,"D");
cout<<"Your Grade is Calculated as "<<Std[ctr].Grade<<endl;}
else if(Std[ctr].Per>=21 && Std[ctr].Per<33)
{strcpy(Std[ctr].Grade,"E1");
cout<<"Your Grade is Calculated as "<<Std[ctr].Grade<<endl;}
else if(Std[ctr].Per>=0 && Std[ctr].Per<=21)
{strcpy(Std[ctr].Grade,"E2");
cout<<"Your Grade is Calculated as "<<Std[ctr].Grade<<endl;}
cout<<"Do U want to continue....";
ch=toupper(getchar());
if(ch=='Y')
{
n++;
}
ctr++;
}
cout<<endl<<"Total records:"<<ctr-1<<endl;

Page 15 of 64
i=1;
cout<<"Student details..."<<endl;
cout<<"------------------------------"<<endl;
while(i<=n)
{
cout<<Std[i].Rollno<<" "<<Std[i].Name<<" ";
cout<<Std[i].Marks[0]<<" "<<Std[i].Marks[1]<<" ";
cout<<Std[i].Marks[2]<<" "<<Std[i].Marks[3]<<" ";
cout<<Std[i].Marks[4]<<" ";
cout<<Std[i].Total<<" " ;
cout<<Std[i].Per<<setprecision(2)<<setiosflags(ios::right)<<setiosflags(ios::fixed)<<" ";
cout<<Std[i].Grade<<endl;
i++;
}
}

Page 16 of 64
OUTPUT

Page 17 of 64
Write a program to demontrate multiple inheritance using three
classes.

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class Student
{
protected:
int rollno;
char name[25];
int Mark1,Mark2,Mark3;
public:
void read_student();
void display_student();
};
class Sports
{
protected:
int SportsMark;
char SportsName[20];
public:
void read_Sportsmarks();
void display_Sportsmarks();
};
class Performance:public Student,public Sports
{
private:
int total;
float percentage;
public:
void calculate_result();
void display_result();
};
void Student::read_student(){
cout<<"\nEnter student details...."<<endl;

Page 18 of 64
cout<<"Enter Rollno.:";
cin>>rollno;
cout<<"Enter name :";
gets(name);
cout<<"Enter Subject1 marks:";
cin>>Mark1;
cout<<"Enter Subject2 marks:";
cin>>Mark2;
cout<<"Enter Subject3 marks:";
cin>>Mark3;
}
void Student:: display_student(){
cout<<"\nStudent details are..."<<endl;
cout<<"Roll No.:"<<rollno<<endl;
cout<<"Name:"<<name<<endl;
cout<<"Mark 1:"<<Mark1<<endl;
cout<<"Mark 2:"<<Mark2<<endl;
cout<<"Mark 3:"<<Mark3<<endl;
}
void Sports::read_Sportsmarks(){
cout<<"Enter sports marks:";
cin>>SportsMark;
cout<<"Enter sports name:";
gets(SportsName);
}
void Sports ::display_Sportsmarks(){
cout<<"Sports Marks:"<<SportsMark<<endl;
cout<<"Sports Name:"<<SportsName<<endl;
}
void Performance::calculate_result(){
total=Mark1+Mark2+Mark3+SportsMark;
percentage=total/4.0;
}
void Performance::display_result(){
cout<<"Total Marks"<<total<<endl;
cout<<"Percentage"<<percentage<<endl;
}
void main()

Page 19 of 64
{
Performance P;
clrscr();
P.read_student();
P.read_Sportsmarks();
P.calculate_result();
for(int i=1;i<=32;i++)
cout<<"=";
P.display_student();
P.display_Sportsmarks();
P.display_result();
getch();
}

Page 20 of 64
OUTPUT

Page 21 of 64
Write a program to demonstrate multilevel inheritance using three
classes
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class Student
{
private:
int rollno;
char name[25];
public:
void read_student();
void display_student();
};
class Marks: public Student
{
protected:
int Mark1,Mark2,Mark3;
public:
void read_marks();
void display_marks();
};
class Result : public Marks
{
private:
int total;
float percentage;
public:
void calculate_result();
void display_result();
};
void Student::read_student(){
cout<<"\nEnter Student details ...."<<endl;
cout<<"Enter Rollno.";
cin>>rollno;
cout<<"Enter Name:";

Page 22 of 64
gets(name);
}
void Student::display_student(){
cout<<"\nStudents detail are..."<<endl;
cout<<"RollNo.:"<<rollno<<endl;
cout<<"Name:"<<name<<endl;
}
void Marks::read_marks(){
cout<<"Enter Subject 1 marks:";
cin>>Mark1;
cout<<"Enter Subject 2 marks:";
cin>>Mark2;
cout<<"Enter Subject 3 marks:";
cin>>Mark3;
}
void Marks ::display_marks(){
cout<<"Mark 1 :"<<Mark1<<endl;
cout<<"Mark 2:"<<Mark2<<endl;
cout<<"Mark3:"<<Mark3<<endl;
}
void Result::calculate_result(){
total=Mark1+Mark2+Mark3;
percentage=total/3.0;
}
void Result::display_result(){
cout<<"Total marks:"<<total<<endl;
cout<<"Percentage:"<<percentage<<endl;
}
void main(){
Result St;
clrscr();
St.read_student();
St.read_marks();
St.calculate_result();
St.display_student();
St.display_marks();
St.display_result();
getch(); }

Page 23 of 64
OUTPUT

Page 24 of 64
Demonstrates Employee class as a constructor

#include <iostream.h>
#include <string.h>
#include <conio.h>
class Employee
{
private: // Access specifier
int empcode;
char empname[20];
char empdesig[15];
float empsalary;
public:
// Default constructor
Employee();
// Member function prototype declaration
void display();
};
// Body of the default constructor Employee
Employee::Employee() {
empcode = 100; // Initialize object data members
strcpy(empname, "Ms. Sujata");
strcpy(empdesig, "PGT Computer");
empsalary = 27500;
}
// Body of the member function
void Employee::display() {
cout << "\nEmployee code : " << empcode;
cout << "\nEmployee name : " << empname;
cout << "\nEmployee designation : " << empdesig;
cout << "\nEmployee salary : " << empsalary;}
void main(){
clrscr();
Employee emp;
cout << "Here is the employee information : \n";
for (int i = 0; i<=32; i++) cout << "=";
emp.display();
getch();}

Page 25 of 64
Output

Page 26 of 64
Demonstrates Employee class as a destructor

#include <iostream.h>
#include <string.h>
#include <conio.h>
class Employee{
private: // Access specifier
int empcode;
char empname[20];
char empdesig[15];
float empsalary;
public:
Employee(int e_code, char e_name[25], char e_desig[15], float e_salary);
~Employee(); // Employee class destructor
void display();
};
// Destructor of Employee
Employee::~Employee()
{
cout << "\nEmployee class object destroyed";
}
// Constructor class method 1
Employee::Employee(int e_code, char e_name[25], char e_desig[15], float e_salary)
{
empcode = e_code; // Initialize object data members
strcpy(empname, e_name);
strcpy(empdesig, e_desig);
empsalary = e_salary;}
void Employee::display() {
cout << "\nEmployee code : " << empcode;
cout << "\nEmployee name : " << empname;
cout << "\nEmployee designation : " << empdesig;
cout << "\nEmployee salary : " << empsalary;}
void main()
{ clrscr();
Employee emp(100, "Ms. Sujata", "PGT Computer", 27500);
emp.display();
}

Page 27 of 64
Output

Page 28 of 64
Write a data entry program using employee class to create a data
file called EMP1.dat.

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
//Declaring class at here
class Employee
{
int empcode;
char empname[20];
char empdesig[15];
float empsalary;
public:
void get_emp();
};
void Employee::get_emp(){
cout<<"\nEmployee code = >";
cin>> empcode;
cout<<"Name = >";
gets(empname);
cout<<"Designation =>";
gets(empdesig);
cout<< "Salary =>";
cin >> empsalary;
}

void main()
{
clrscr();
fstream sfile;
char ans ='y';
sfile.open("EMP1.dat",ios::app);
Employee emp;
cout<< "\nEmployee data entry\n";
do{
emp.get_emp();
sfile.write((char*)&emp,sizeof(emp));
cout<<"Do you want to continue...";
cin>>ans;
}while(ans=='y');
sfile.close();}

Page 29 of 64
OUTPUT

Page 30 of 64
Write a program to modify an existing record from EMP1.dat using
the empcode key field sequentially.

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<iomanip.h>
struct Employee
{
int empcode;
char empname[20];
char empdesig[15];
float empsalary;
};
Employee emp;
void main()
{
int xemp_code;
fstream empfile,tempfile;
empfile.open("EMP1.dat",ios::binary||ios::nocreate);
tempfile.open("TEMP.dat",ios::out);
clrscr();
cout<<"\Enter employee code to modify:";
cin>>xemp_code;
empfile.read((char*)&emp,sizeof(emp));
while(empfile){
if(!empfile)
exit(0);
if(emp.empcode==xemp_code){
cout<<"\nCode is: "<<emp.empcode;
cout<<"\nName is:"<<emp.empname;
cout<<"\nDesignation is:"<<emp.empdesig;
cout<<"\nSalary is:"<<emp.empsalary;
cout<<"\nEnter new employee code:";
cin>>emp.empcode;
cout<<"Employee name:";

Page 31 of 64
gets(emp.empname);
cout<<"Employee designation :";
gets(emp.empdesig);
cout<<"Salary :";
cin>>emp.empsalary;
tempfile.write((char*)&emp,sizeof(emp));
}
else
tempfile.write((char*)&emp,sizeof(emp));
empfile.read((char*)&emp,sizeof(emp));
}
empfile.close();
tempfile.close();
fstream xfile,yfile;
xfile.open("TEMP.dat",ios::binary||ios::nocreate);
yfile.open("EMP1.dat",ios::out);
while(xfile){
if(!xfile)
exit(0);
yfile.write((char*)&emp,sizeof(emp));
xfile.read((char*)&emp,sizeof(emp));
}
xfile.close();
yfile.close();
}

Page 32 of 64
OUTPUT

Page 33 of 64
Write a program to delete records one by one from the EMP1.dat
file using the emp.code key field.

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
//Declaring structure at here
struct Employee
{
int empcode;
char empname[20];
char empdesig[15];
float empsalary;
};
Employee emp; //Global declaration of structure
void main()
{
clrscr();
int xemp_code; //Temporary declaration for employee code
int flag = 0; //Check a flag for delete sure;
fstream empfile,tempfile;
//empfile is opened for data reading
empfile.open("EMP.dat",ios::binary||ios::nocreate);
//tempfile is opened for copying all the records including
//modified record
tempfile.open("TEMP.dat",ios::out);
clrscr();
cout<<"\nEnter employee code to delete";
cin>>xemp_code;
while(empfile){
if(!empfile)
exit(0);
empfile.read((char*)&emp,sizeof(emp));
if(emp.empcode == xemp_code){
flag = 1;
}
else
tempfile.write((char*)&emp,sizeof(emp));
}
empfile.close();
tempfile.close();
if(flag==1)

Page 34 of 64
cout<<"Record deleted !!!";
else
cout<<"Record not found !!!";
fstream xfile,yfile;
//tempfile is opened for data reading
xfile.open("TEMP.dat",ios::binary||ios::nocreate);
//empfile is opened for copying all the records from TEMP.dat file
yfile.open("EMP.dat",ios::out);
while(xfile){
if(!xfile)
exit(0);
xfile.read((char*)&emp,sizeof(emp));
yfile.write((char*)&emp,sizeof(emp));
}
xfile.close();
yfile.close();
}

Page 35 of 64
OUTPUT

Page 36 of 64
Basic Stacks operation using Array (Insertion,Deletion and Traveral
in a Stacks)
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX 100
int Stack [MAX];
int Top;
void Push(int Stack[], int Val, int &Top);
int Pop(int Stack[], int &Top);
void Show_Stack(int stack[], int &Top);
int main(){
int choice,Val;
char opt ='Y';
Top=-1;
cout<<"\n\tMain Menu";
cout<<"\n\t1. Addition of Stack-Push operation";
cout<<"\n\t2. Deletion from Stack-Pop operation";
cout<<"\n\t3. Traverse of Stack";
cout<<"\n\t4. Exit from Menu";
do{
cout<<"\n\tEnter your choice from above -> ";
cin>>choice;
switch(choice){
case 1:
do{
cout<<"\tEnter the value -> ";
cin>>Val;
Push(Stack,Val,Top);
cout<<"\n\tDo you want to add more elements <Y/N> ?";
cin>>opt;
}while(toupper(opt)=='Y');
break;
case 2:
opt='Y';
do{
Val=Pop(Stack,Top);
if(Val!=-1)
cout<<"\tValue deleted from statck is "<<Val;
cout<<"\n\tDo you want to delete more elements <Y/N> ?";
cin>>opt;

Page 37 of 64
}while(toupper(opt)=='Y');
break;
case 3:
Show_Stack(Stack,Top);
break;
case 4:
exit(0);
}}while(choice!=4);
return 0;
}
void Push(int stack[],int Val,int &Top)
{
if(Top==MAX-1){
cout<<"\tStack is full.";
}
else{
Top=Top+1;
Stack[Top]=Val;
}}
int Pop(int Stack[],int &Top)
{
int Val;
if(Top<0){
cout<<"\tStack is empty.";
Val=-1;
}else{
Val=Stack[Top];
Top=Top-1;
}
return(Val);
}
void Show_Stack(int Stack[],int& Top)
{
int i;
if(Top<0){
cout<<"\tStack is empty.";
return;
}
i=Top;
cout<<"\n\tThe values are -> ";
do{
cout<<Stack[i]<<" ";
i=i-1;
}while(i>=0);}

Page 38 of 64
OUTPUT

Page 39 of 64
Basic Stack operation using Linked List (Insertion, Deletion and
Traversal in a Stack)
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
struct Node{
int Data;
Node *Link;
};
Node *Top;
Node *Push(Node *Top,int Val); //Add stack
Node *Pop(Node *Top,int &Val); //Delete stack
void Show_Stack(Node *Top); //Show stack
int main(){
Node *Top;
int Val,choice;
char opt='Y';
Top=NULL;
cout<<"\n\tMain Menu";
cout<<"\n\t1.Addition of Stack-push operation";
cout<<"\n\t2.Deletion from Stack-pop operation";
cout<<"\n\t3.Traverse of Stack";
cout<<"\n\t4.Exit from Menu";
do{
cout<<"\n\tEnter your choice from above-> ";
cin>>choice;
switch(choice)
{
case 1:
do{
cout<<"\tEnter the value -> ";
cin>>Val;
Top=Push(Top,Val);
cout<<"\n\tDo you want to add more elements <Y/N>?";
cin>>opt;
}while(toupper(opt)=='Y');
break;
case 2:
opt='Y';
do{
Top=Pop(Top,Val);
if(Val!=-1)

Page 40 of 64
cout<<"\tValue deleted from stack is -> "<<Val;
cout<<"\n\tDo you want to delete more elements <Y/N>?";
cin>>opt;
}while(toupper(opt)=='Y');
break;
case 3:
Show_Stack(Top);
break;
case 4:
exit(0);
}}while(choice!=4);
return 0;}
Node *Push(Node *Top,int Val){
Node *Temp;
Temp=new Node;
Temp->Data=Val;
Temp->Link=NULL;
if(Top==NULL)
Top=Temp;
else{
Temp->Link=Top;
Top=Temp;}
return(Top);}
Node *Pop(Node *Top,int &Val){
Node *Temp;
if(Top==NULL){
cout<<"\tStack is empty.";
Val=-1;
}else{
Temp=Top;
Top=Top->Link;
Val=Temp->Data;
Temp->Link=NULL;
delete Temp;}
return(Top);}
void Show_Stack(Node *Top){
Node *Temp;
Temp=Top;
cout<<"\tThe values are -> ";
while(Temp!=NULL){
cout<<Temp->Data<<" ";
Temp=Temp->Link;
}}

Page 41 of 64
OUTPUT

Page 42 of 64
Basic Queue operation using Array (Insertion,Deletion and Traveral
in a Queue)

#include<iostream.h>
class queue{
public:
int q[5],front,rear,x,result;
void enqueue();
void dequeue();
void display();
queue()
{
front=0;
rear=0;
}};
void queue:: enqueue(){
if(rear>=5)
cout<<"\n\tQueue overflow!";
else
{
cout<<"\tEnter the number to be inserted -> ";
cin>>x;
rear++;
q[rear]=x;
cout<<"\tNumber pushed in the queue -> ";
cout<<q[rear];
}
}
void queue:: dequeue()
{
if(rear==0)
cout<<"\n\tQueue under flow";
else
{
if(front==rear)
{
front=0;
rear=0;
}
else
front++;
}

Page 43 of 64
cout<<"\tDeleted element is -> ";
result=q[front];
cout<<result;
}
void queue:: display()
{
if(rear==0)
{
cout<<"\n\tQueue underflow";
}
else
{
cout<<"\tContents of the queue is -> ";
for(int i=front+1;i<=rear;i++)
{
cout<<q[i]<<" ";
}
}
}
void main()
{
int c;
queue q;
cout<<"\n";
cout<<"\n\tQUEUE";
cout<<"\n";
cout<<"\n\t1.INSERTION \n\t2.DELETION \n\t3.DISPLAY \n\t4.EXIT";
do
{
cout<<"\n\n\tEnter your choice -> ";
cin>>c;
switch (c)
{
case 1:q.enqueue();
break;
case 2:q.dequeue();
break;
case 3:q.display();
break;
case 4:cout<<"\tEnd of Program";break;
default:cout<<"\tINVALID CHOICE";
}
}while(c!=4);
}

Page 44 of 64
OUTPUT

Page 45 of 64
Basic Queue operation using Linked List (Insertion,Deletion and
Traveral in a Queue)

#include<iostream.h>
struct node{
int info;
struct node *next;
};
class queue{
private:
node *rear;
node *front;
public:
queue();
void enqueue();
void dequeue();
void display();
};
queue :: queue(){
rear=NULL;
front=NULL;
}
void queue :: enqueue(){
int data;
node *temp=new node;
cout<<"\tEnter the data to enqueue -> ";
cin>>data;
temp->info=data;
temp->next=NULL;
if(front==NULL){
front=temp;
}
else{
rear->next= temp;
}
rear = temp;
}
void queue:: dequeue(){
node *temp=new node;
if(front==NULL){
cout<<"\n\tQueue is empty";
}

Page 46 of 64
else{
temp=front;
front=front->next;
cout<<"\tthe data is dequeued";
delete temp;
}}
void queue :: display(){
node *p=new node;
p=front;
if(front== NULL){
cout<<"\n\tNothing to display";}
else{
cout<<"\tContents of the queue is -> ";
while(p!=NULL){
cout<<p->info<<" ";
p=p->next;
}}}
void main() {
queue q;
int c;
cout<<"\n";
cout<<"\n\tQUEUE USING LINKED LIST";
cout<<"\n";
cout<<"\n\t1.INSERTION \n\t2.DELETION \n\t3.DISPLAY \n\t4.EXIT";
do{
cout<<"\n\tEnter your choice -> ";
cin>>c;
switch (c){
case 1:q.enqueue();
break;
case 2:q.dequeue();
break;
case 3:q.display();
break;
case 4:cout<<"\tEnd of Program";
break;
default:cout<<"\tINVALID CHOICE";
}
}while(c!=4);
}

Page 47 of 64
OUTPUT

Page 48 of 64
Database Concepts/SQL

Page 49 of 64
Page 50 of 64
Page 51 of 64
Page 52 of 64
Page 53 of 64
Page 54 of 64
Page 55 of 64
Page 56 of 64
Page 57 of 64
Page 58 of 64
Page 59 of 64
Page 60 of 64
Page 61 of 64
Page 62 of 64
Page 63 of 64
Page 64 of 64

You might also like