Home.............Unix a view.......... Unix porgram........DBMS.............basic computer tutor............microprocessor 8085..........Student part time jobs..........Colleges in Tamilnadu.............website park
Home
Hello Friends,
I am launching these blog for the students as a guiding aspect. In this blog you can clarify your doubts about c/c++,unix,os, DBMS, microprocessor. I am going to publish many complicated programs such as sjf preemptive algorithm and micro processor programs which will help you in lab programs. Here I have mentioned some part time jobs for student also. I referred some contents from other resources, So I should say thanks to them.

This blog will be updated by many programs like anna university question papers, c and c++ programs, Many projects on c,c+= and micro processor,etc. I hope that this will be a helpful blog for you. Especially this will help for the anna university students.
I need your cooperation and valuable feed backs, Which will help me to improve my self. You can send your suggestions to
studentsevice@gmail.com
.

"All the best"
Thank you.

c/c++ programs

QUEUE:

#include "iostream.h"
class que
{
int size;
int arr[5];
int rear,front;
int data;
char a;
public:
que()
{
size=2;
rear=-1;
front=-1;
}
void enque(int data)
{
if(rear+1 >=size)
{
throw i;
else
{
if(rear==-1&&front==-1)
{
front++;
}
rear++;
cout<<"rear"<arr[rear]=data;
cout<}
}
int deque()
{
if(front>rear)
{
throw
}
return(arr[front++]);
}
};
int main()
{
que q;
char choice;
clrscr();
do
{
cout<<"1.Insert\n2.Delete"<cout<<"enter the choice:";
int ch;

cin>>ch;
switch(ch)
{
case 1:
//try
{
cout<<"\nenter the element to insert\n";
int item;
cin>>item;
q.enque(item);
cout<<"\nItem inserted";
}
catch(int j)
{cout<<"queue is full";
}
break;
case 2:
//try
{
cout<<"the deleted item from queue"<}
catch(char b)
{
cout<<"\nqueue is empty\n";
}
break;
}
cout<<"continue(y/n)";
cin>>choice;
}while(choice=='y');
}


LINKED LIST:


#include
#include
#include
class emp
{
private:
char name[20];
int age;
float sal;
public:
emp(char*n="",int a=0,float s=0.0)
{
strcpy(name,n);
age=a;
sal=s;
}
friend ostream&operator<<(ostream &s,emp &e);
};
ostream&operator<<(ostream &s,emp &e)
{
cout<return s;
}
template
class linklist
{
private:
struct node
{
T data;
node*link;
}*p;
public:
linklist();
void append(T);
void addatbeg(T);
void addafter(int,T);
void del(int);
void display();
int count();
~linklist();
};
template
linklist::linklist()
{
p=NULL;
}
template
void linklist::append(T num)
{
node*q,*t;
if(p==NULL)
{
p=new node;
p->data=num;
p->link=NULL;
}
else
{
q=p;
while(q->link!=NULL)
q=q->link;
t=new node;
t->data=num;
t->link=NULL;
q->link=t;
}
}
template
void linklist::addatbeg(T num)
{
node*q;
q=new node;
q->data=num;
q->link=p;
p=q;
}
template
void linklist::addafter(int c,T num)
{
node*q,*t;
int i;
q=p;
for(i=1;i{
q=q->link;
if(q==NULL)
{
cout<return;
}
}
t=new node;
t->data=num;
t->link=q->link;
q->link=t;
}
template
void linklist::del(int n)
{
node*q,*r;
int i=1;
q=p;
if(n==1)
{
p=q->link;
delete q;
return;
}
r=q;
while(q!=NULL)
{
if(i==n)
{
r->link=q->link;
delete q;
return;
}
r=q;
q=q->link;
i++;
}
cout<}
template
void linklist::display()
{
node*q;
cout<for(q=p;q!=NULL;q=q->link)
cout<data<}
template
int linklist::count()
{
node*q;
int c=0;
for(q=p;q!=NULL;q=q->link)
c++;
return(c);
}
template
linklist::~linklist()
{
node*t;
while(p!=NULL)
{
t=p;
p=p->link;
delete t;
}
}
void main()
{
linklistl1;
cout<emp e2("sachin",33,3500.00);
emp e3("sourav",24,2400.00);
emp e4("sanket",25,2500.00);
emp e5("sandeep",26,2600.00);
l2.append(e1);
l2.append(e2);
l2.append(e3);
l2.append(e4);
l2.append(e5);
l2.display();
l2.del(3);
l2.display();
cout<
VIRTUAL CLASS:


#include
#include
class shape
{
public:
int x,y;
public:
void getdata(int a,int b=0)
{
x=a;
y=b;
}
virtual void area()
{cout<<"shape";
}
};
class square:public shape
{
public:
void area()
{
cout<<"area of square"<}
};
class rectangle:public shape
{
public:
void area()
{
cout<<"area of rectangle:"<}
};
class circle:public shape
{
public:
void area()
{
cout<<"area of circle:"<<(3.14)*x*x<}
};
class triangle:public shape
{
public:
int area1;
void area()
{
cout<<"area of triangle";
area1=(0.5)*x*y;
cout<}
};
class polygon:public shape
{
public:
int area1;
void area()
{
area1=(0.5)*x*y;
cout<<"area of polygon:"<<6*area1<}
};
void main()
{
clrscr();
shape *s;
triangle t;
square sq;
rectangle rt;
polygon p;
circle c;
s=&t;
s->getdata(3,2);
s->area();
s=&sq;
s->getdata(4);
s->area();
s=&c;
s->getdata(3);
s->area();
s=&rt;
s->getdata(2,4);
s->area();
s=&p;
s->getdata(3,2);
s->area();
getch();
}


DYNAMIC OVERLOADING:

#include
const int asize=10;
class vector
{
int*a;
public:
void*operator new(size_t)
{
vector*v;
v=::new vector;
v->a=new int[asize];
return v;
}
void operator delete(void*vec)
{
vector*v;
v=(vector*)vec;
delete(int*)v->a;
::delete vec;
}
void read()
{
for(int i=0;i{
cin>>a[i];
}
}
int sum()
{
int sum=0;
for(int i=0;i{
sum+=a[i];
}
return sum;
}
};
void main()
{
vector*v=new vector;
cout<<"enter the vector element";
v->read();
cout<<"the sum of vector element"<sum();
delete v;
}


SORTING ALGORITHMS:


#include
#include
enum Boolean{false,true};

template
void swap(T &x,T&y)
{
T t;
t=x;
x=y;
y=t;
}
template
void bubb(T &s,int size)
{
Boolean swapped=true;
for(int i=0;(i{
swapped=false;
for(int j=0;j<(size-1)-i;j++)
if(s[j]>s[j+1])
{
swapped=true;
swap(s[j],s[j+1]);
}
}
}
template //INSERTION SORT
void insertionsort(T numbers[], int array_size)
{
T i, j, index;

for (i=1; i < array_size; i++)
{
index = numbers[i];
j = i;
while ((j > 0) && (numbers[j-1] > index))
{
numbers[j] = numbers[j-1];
j = j - 1;
}
numbers[j] = index;
}
}

template//Quick Sort
int Partition(int low,int high,T arr[])
{ T pivot,high_vac,low_vac;
pivot=arr[low];
while(high>low)
{
high_vac=arr[high];
while(pivot {
if(high<=low) break;
high--;
high_vac=arr[high];
}
arr[low]=high_vac;
low_vac=arr[low];
while(pivot>low_vac)
{
if(high<=low)
break;
low++;
low_vac=arr[low];
}
arr[high]=low_vac;
}
arr[low]=pivot;
return low;
}
template
void Quick_sort(int low,int high,T arr[])
{
int Piv_index;
if(low {
Piv_index=Partition(low,high,arr);
Quick_sort(low,Piv_index-1,arr);
Quick_sort(Piv_index+1,high,arr);
}
}
void main()
{
int num[25],temp[25];
char charnum[25];
float floatnum[25];
int i,size,ch,c1,c2,c3;
clrscr();
cout<<"Program to sort.."<cout<<"enter the size of interger and float and char:";
cin>>size;
cout<<"Enter the integer element"<for(i=0;icin>>num[i];
cout<<"Enter the float element"<for( i=0;icin>>floatnum[i];
cout<<"Enter the char"<for( i=0;icin>>charnum[i];
do
{
cout<<"Sorting"<cout<<" \n1.quick sort\n2.bubble sort\n3.insertion sort \n4.Exit\n"<cout<<"Enter your choice:";
cin>>ch;
switch(ch)
{
case 1:
do
{
cout<<"\nsorting\n";
cout<<"\n1.int sort 2.float sort 3.char sort 4.exit\n ";
cout<<"\nenter your choice:\n";
cin>>c1;
switch(c1)
{
case 1:
Quick_sort(0,size-1,num);
cout<<" int sorted vector:"<for(i=0;icout<break;
case 2:
Quick_sort(0,size-1,floatnum);
cout<<"float sorted vector:"<for(i=0;icout<break;
case 3:
Quick_sort(0,size-1,charnum);
cout<<"char sorted vector:"<for(i=0;icout<break;
case 4:
cout<<"exit";
break;
}
}while(c1<4);
break;
case 2:
do
{
cout<<"\n1.int sort 2.float sort 3.char sort 4.exit\n";
cout<<"enter your choice";
cin>>c2;
switch(c2)
{
case 1:
bubb(num,size)
;
cout<<"\nint sorted vector:\n"<for(i=0;icout<break;
case 2:
bubb(floatnum,size);
cout<<"\nfloat sorted vector:\n"<for(i=0;icout<break;

case 3:
bubb(charnum,size);
cout<<"\nchar sorted vector:\n"<for(i=0;icout<break;
case 4:
cout<<"exit";
break;
}
}while(c2<4);
case 3:
do
{
cout<<"\n1.int sort 2.float sort 3.char sort 4.exit\n";
cout<< "enter your choice";
cin>>c3;
switch(c3)
{
case 1:
insertionsort(num,size);
cout<<"\nint sorted vector:\n"<for(i=0;icout<break;
case 2:
insertionsort(floatnum,size);
cout<<"\nfloat sorted vector:\n"<for(i=0;icout<break;
case 3:
insertionsort(charnum,size);
cout<<"\nchar sorted vector:\n"<for(i=0;icout<break;
case 4:
cout<<"exit";
break;
}
}while(c3<4);
break;
case 4:
break;
}
}while(ch<4);
getch();
}


KRUSKAL ALGORITHM:



#include
#include
class kruskal
{
private:
int n;
int noe;
int graph_edge[100][4];
int tree[10][10];
int sets[100][10];
int top[100];
public:
void read_graph();
void initilize_span_t();
void sort_edges();
void algorithm();
int find_node(int);
void print_min_span();
};
void kruskal::read_graph()
{
cout<<"Enter the no of nodes in undirected weighted graph::";
cin>>n;
noe=0;
cout<<"Enter the weights for follwing edges::\n";
for(int i=0;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
cout<<"<"<::";
int w;
cin>>w;
if(w!=0)
{
noe++;
graph_edge[noe][1]=i;
graph_edge[noe][2]=j;
graph_edge[noe][3]=w;
}
}
}
cout<<"\n\n the edges in the given graph::\n";
for(i=1;i<=noe;i++)
cout<<"<"<::"<}
void kruskal::sort_edges()
{
for(int i=1;i<=noe-1;i++)
{
for(int j=1;j<=noe-1;j++)
{
if(graph_edge[j][3]>graph_edge[j+1][3])
{
int t=graph_edge[j][1];
graph_edge[j][1]=graph_edge[j+1][1];
graph_edge[j+1][1]=t;
t=graph_edge[j][2];
graph_edge[j][2]=graph_edge[j+1][2];
graph_edge[j+1][2]=t;
t=graph_edge[j][3];
graph_edge[j][3]=graph_edge[j+1][3];
graph_edge[j+1][3]=t;
}
}
}
cout<<"\n\n after sorting edges in given graph are::\n";
for(i=1;i<=noe;i++)
cout<<"<"<::"<}
void kruskal::algorithm()
{
for(int i=1;i<=n;i++)
{
sets[i][1]=i;
top[i]=1;
}
cout<<"\n the algorithm starts::\n\n";
for(i=1;i<=noe;i++)
{
int p1=find_node(graph_edge[i][1]);
int p2=find_node(graph_edge[i][2]);
if(p1!=p2)
{
cout<<"The edge includes in the tree is::"<<"<"<<
graph_edge[i][1]<<","<"<tree[graph_edge[i][1]][graph_edge[i][2]]=graph_edge[i][3];
tree[graph_edge[i][2]][graph_edge[i][1]]=graph_edge[i][3];
for(int j=1;j<=top[p2];j++)
{
top[p1]++;
sets[p1][top[p1]]=sets[p2][j];
}
top[p2]=0;
}
else
{
cout<<"inclusion of the edges"<<"<"<"<<"forms a cycle so it is removed\n\n";
}
}
}
int kruskal::find_node (int n)
{
for(int i=1;i<=noe;i++)
{
for(int j=1;j<=top[i];j++)
{
if(n==sets[i][j])
return i;
}
}
return -1;
}
int main()
{
clrscr();
kruskal obj;
obj.read_graph();
obj.sort_edges();
obj.algorithm();
getch();
return 0;
}

OPERATOR OVERLOADING:


#include
#include
#include
class complex
{
float real,img;
char real2,img2;
public:
complex()
{
img=real=0;
real2=img2=0;
}
complex(int a)
{
img=0;
real=a;
}
complex(double a1)
{
img=0.0;
real=a1;
}
complex(char a3)
{
img2='b';
real2=a3;
}
void outdata()
{
if(img>=0.0)
{
cout<}
else
{
cout<}
}
void outdata1()
{
cout<}
complex operator+(complex c)
{
complex temp;
temp.img=img+c.img;
temp.real=real+c.real;
return(temp);
}
complex operator-(complex c)
{
complex temp1;
temp1.img=img-c.img;
temp1.real=real-c.real;
return(temp1);
}
complex operator*(complex c)
{
complex temp2;
temp2.img=real*c.img+img*c.img;
temp2.real=real*c.real-img*c.img;
return(temp2);
}
complex operator/(complex c)
{
complex temp3;
temp3.img=((img*c.img)+(real*c.real))/((c.img*c.img)+(c.real*c.real));
temp3.real=((real*c.img)-(img*c.real))/((c.img*c.img)+(c.real*c.real));
return(temp3);
}
operator double()
{
double magnitude;
magnitude=sqrt(pow(real,2)+pow(img,2));
return magnitude;
}
operator float()
{
float addr;
//double real1;
addr=real+img;
return addr;
}
};
void main()
{
clrscr();
complex c1,c2,c3,c4,c5,c6,c7;
int real;
double real1;
char real2;
cout<<"Enter the integer real number:";
cin>>real;
c1=real;
cout<<"Integer to complex conversation"<cout<<"Enter the double real number"<cin>>real1;
c2=real1;
cout<<"double to complex conversation"<cout<<"Enter the char real number";
cin>>real2;
c7=real2;
cout<<"char to complex conversation"<//cout<<"complex to double conversation"<c3=c1+c2;
c4=c1-c2;
c5=c1*c2;
c6=c1/c2;
cout<<"\n\n";
cout<<"the addition result is:";
c3.outdata();
cout<<"\n\n";
cout<<"the subtraction result is:";
c4.outdata();
cout<<"\n\n";
cout<<"the multiplication result is:";
c5.outdata();
cout<<"\n\n";
cout<<"the division result is:";
c6.outdata();
cout<<"\n\n";
cout<<"conversion from complex to double"<double mag=c3;
cout<<"magnitude of a complex number"<//float addr=real+real1;
cout<<"The char complex number is:"<c7.outdata1();
float dd=c4;
cout<cout<getch();
}


CONSTRUCTOR:

#include
#include
class matrix
{
private:
int row;
int col;
int **p;
public:
matrix()
{
row=col=0;
p=NULL;
}
matrix(int r,int c);
~matrix();
void read();
void show();
void add(matrix &a,matrix &b);
void sub(matrix &a,matrix &b);
void operator=(matrix &m1)
{
row=m1.row;
col=m1.col;
p=new int*[m1.row];
for(int i=0;i{
p[i]=new int[m1.col];
}
}
matrix(matrix &m2)
{
row=m2.row;
col=m2.col;
p=new int*[m2.row];
for(int i=0;i{
p[i]=new int[m2.col];
}
for(i=0;ifor(int j=0;j{
p[i][j]=m2.p[i][j];
}
}
};
matrix::matrix(int r,int c)
{
row=r;
col=c;
p=new int *[row];
for(int i=0;ip[i]=new int[col];
}
matrix::~matrix()
{
for(int i=0;idelete p[i];
delete p;
}
void matrix::add(matrix &a,matrix &b)
{
int i,j;
row=a.row;
col=b.col;
for(i=0;ifor(j=0;jp[i][j]=a.p[i][j]+b.p[i][j];
}
void matrix::sub(matrix &a,matrix &b)
{
int i,j;
row=a.row;
col=b.col;
for(i=0;ifor(j=0;jp[i][j]=a.p[i][j]-b.p[i][j];
}
void matrix::read()
{
int i,j;
for(i=0;ifor(j=0;j{
cout<<"Matrix["<cin>>p[i][j];

}
}
void matrix::show()
{
int i,j;
for(i=0;i{
cout<for(j=0;j{
cout<}
}
}

void main()
{
int m,n,p,g,q;
clrscr();
cout<<"Enter the Amatrix "<cout<<"how many rows";
cin>>m;
cout<<"how many col";
cin>>n;
matrix a(m,n);
a.read();
matrix b;
b=a;
cout<<"overloading assignment operator invoke"<cout<<"enter the Bmatrix";
b.read();
cout<<"matrix a is";
a.show();
cout<b.show();
matrix c(m,n);
c.add(a,b);
cout<c.show();
matrix d(m,n);
d.sub(a,b);
cout<d.show();
cout<<"\n copy constructor invoke"<matrix e(c);
e.show();
getch();
}


STACK:

#include
#include
#define MAX 5
class stack
{
int arr[5];
public:
int item;
int top;
stack()
{top=0;
}
//class overflowexception{};
void push(int a)
{
cout<if(top{
top++;
arr[top]=a;
}
else
{
cout<<"Stack is full";
//throw overflowexception();
}}
//class underflowexception{};
int pop()
{
/*if(top==0)
{
//throw underflowexceptions();
cout<<"Stack is empty";
}
else
{*/
int data=arr[top];
top--;
cout<<"the item is poped";
return data;
}};
int main()
{
char ch;
int choice;
stack a;
clrscr();
do
{
cout<<"1.Push 2.Pop"<cout<<"Enter your choice";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter the item";
cin>>a.item;
a.push(a.item);
if(a.top<5)
cout<<"Item pushed";
//catch(stock::overflowexception)
//{cout<<"Stack overflow";}
break;
case 2:
if(a.top==0)
{cout<<"Stack is empty";}
//catch(stack::underflowexception)
else
{cout<<"Item Popped:"<}
cout<<"\ny or n :";
cin>>ch;
}while(ch=='y');
return 0;
}