C++ Programs

C++ program to implement Queue using Formula Based Representation

#include <iostream.h> #include <conio.h> class queue { private :   int *arr ; int front, rear ; int MAX ; public : queue( int maxsize = 10 ) ; void addq ( int item ) ; int delq( ) ; } ; queue :: queue( int maxsize ) { MAX = maxsize ; arr = […]


C++ program to implement Hash Table

#include <iostream.h> #include <stdlib.h> #include<constream.h> template<class E, class K> class HashTable { public: HashTable(int divisor = 11); ~HashTable() {delete [] ht; delete [] empty;} int Search(const K& k, E& e) const; HashTable<E,K>& Insert(const E& e); void Output();// output the hash table void del(E e); private: int hSearch(const K& k) const; int D; // hash function […]


C++ program to evaluate an expression entered in postfix form

#include <iostream.h> #include <stdlib.h> #include <math.h> #include <ctype.h> const int MAX = 50 ; class postfix { private :   int stack[MAX] ; int top, nn ; char *s ; public : postfix( ) ; void setexpr ( char *str ) ; void push ( int item ) ; int pop( ) ; void calculate( […]


C++ program to convert an Expression from Infix expression to Prefix form

#include <iostream.h> #include <string.h> #include <ctype.h> const int MAX = 50 ; class infix { private : char target[MAX], stack[MAX] ; char *s, *t ; int top, l ; public : infix( ) ; void setexpr ( char *str ) ; void push ( char c ) ; char pop( ) ; void convert( ) […]


C++ program to convert an Expression from Infix form to Postfix form

#include <iostream.h> #include <string.h> #include <ctype.h> const int MAX = 50 ; class infix { private : char target[MAX], stack[MAX] ; char *s, *t ; int top ; public : infix( ) ; void setexpr ( char *str ) ; void push ( char c ) ; char pop( ) ; void convert( ) ; […]


Program to implement Linear Search algorithm

#include<iostream.h> #include<constream.h> void read(int a[10],int n) { cout<<"reading\n"; for(int i=0;i<n;i++) cin>>a[i]; } void display(int a[10],int n) { for(int i=0;i<n;i++) cout<<a[i]<<"\t"; } void linearsearch ( int a[10],int n ) { int k,flag=0; read(a,n); display(a,n); cout<<"\nenter an element to be search\n"; cin>>k; for(int i=0;i<n;i++) { if(a[i]==k) flag=1; break; } if(flag==1) cout << "\nsearching is successful,element is found […]


Program to represent Indirect Addressing of Linear List using Templates

IndirectList(int MaxLinearSize=10);
~IndirectList();//destructor
int IsEmpty()const{return length==0;}
int Length()const{return length;}
int Find(int k,T&x)const;
int Search(const T&x)const;
void Delete(int k,T&x);
void Insert(int k,const T&x);
void Output()const;


Program to implement linked representation of Linear list using templates

#include<iostream.h> #include<constream.h> #include<stdlib.h> template<class T> class ChainNode { friend Chain<T>; private: T data; ChainNode<T>*link; }; template<class T> class Chain { private: ChainNode<T>*first; public: Chain() { first=0; } ~Chain(); int IsEmpty()const; int Length()const; int Find(int k,T&x); int Search(const T&x); void Delete(int k,T&x); void Insert(int k,const T&x); void Output(); }; template<class T> Chain<T>::~Chain() { ChainNode<T>*next; while(first) { […]


Program for Array Based Representation of Linear List using templates

LinearList(int MaxLinearSize=10);
~LinearList(){delete[]element;}
int isEmpty()const{return length==0;}
int Length()const{return length;}
int Find(int k,T&x)const;
int Search(const T&x)const;
void Delete(int k,T&x);
void Insert(int k,const T&x);
void Output()const;


C++ program using class to generate mark sheet using multiple inheritance

Using multiple inheritances, prepare a Student Mark sheet, class marks for every student in three subjects. The inherited class generates mark sheet. #include<iostream.h> #include<stdio.h> #include<dos.h> class student { int roll; char name[25]; char add [25]; char *city; public: student() { cout<<"welcome in the student information system"<<endl; } void getdata() { cout<<"\n enter the student roll […]