## C++ Algorithms Code Examples Area overloded

`Area overloded `
` `
` `
` `
``` #include<iostream.h>
#include<conio.h>
#define phi  3.14
int area(int,int);
float area(int);
void main()
{
int a,b,c,cho;
clrscr();
cout<<"\t  What do you want to do?\n";
cout<<"1. area of rectangle"<<endl;
cout<<"2. area of circle"<<endl;
cout<<"Choice:";
cin>>cho;
switch(cho)
{
case 1:
cout<<"Enter lengt and breath (with white space):";
cin>>a>>b;
cout<<"Area of RECTANGLE:"<<area(a,b);
break;
case 2:
cin>>c;
cout<<"Area of CIRCLE:"<<area(c);
break;
}
getch();
}
int area(int x,int y)
{
return (x*y);
}
float area(int s)
{
return (phi*s*s);
}
```

## C++ Algorithms Code Examples:- Binary arithmatic Algorithms Code

`Binary arithmetic `
` `
` `
``` #include<stdio.h>
#include<conio.h>
#include<string.h>
#include<math.h>

void b_to_d(char result[]); //binary to decimal
void d_to_b(int dec,char binary[]); // decimal to binary

main()
{
int ch,n1,n2,i=0,j,k,l,carry,r,x1,x2,x;
char bn1[30],bn2[30],result[30],binary[30];
char multi[30][30];
clrscr();
do
{
printf("<1> input first operand \n");
printf("<2> input second operand \n");
printf("<4> binary subtraction \n");
printf("<5> binary multiplation \n");
printf("<6> result to decimal \n");
printf("<7> Exit \n\n");
do
{
scanf("%d",&ch);
}while(ch>7 || ch<1);
switch (ch)
{
case 1:
printf("\n input first operand ");
scanf("%d",&n1);
x1=n1;
d_to_b(n1,binary);
for(i=0;binary[i]!='\0';++i)
bn1[i]=binary[i];
bn1[i]='\0';
break;
case 2:
printf("\n input second operand ");
scanf("%d",&n2);
x2=n2;
d_to_b(n2,binary);
for(i=0;binary[i]!='\0';++i)
bn2[i]=binary[i];
bn2[i]='\0';
break;
for(i=0;i<30;++i)      //reset result
result[i]='\0';
carry=0;
if(strlen(bn1)<strlen(bn2))
r=strlen(bn2);
else
r=strlen(bn1);
for(i=0;i<r;++i)
{
result[i+1]='\0';
if(carry==0)
{
if(bn1[i]-48+bn2[i]-48+carry==1)
result[i]=bn1[i]-48+bn2[i]-48+48;
else
result[i]=0+48;
}
else
{
if(bn1[i]-48+bn2[i]-48+carry==2)
result[i]=0+48;
else
result[i]=1+48;
}
if(bn1[i]-48+bn2[i]-48+carry>1)
carry=1;
else
carry=0;
if(carry==1)
result[i+1]=carry+48;
}
printf("\n%s\n",strrev(result));
break;
case 4:        //subtraction
for(i=0;i<30;++i)      //reset result
result[i]='\0';
carry=0;
if(strlen(bn1)<strlen(bn2))
r=strlen(bn2);
else
r=strlen(bn1);
for(i=0;i<r;++i)
{
result[i+1]='\0';
if(bn1[i]<bn2[i])
carry=2,--bn1[i+1];
else
carry=0;
if(carry+bn1[i]-48-bn2[i]+48==1)
result[i]=1+48;
else
if(carry+bn1[i]-48-bn2[i]+48==0)
result[i]=0+48;
}
printf("\n%s\n",strrev(result));
break;
case 5:        //binary multiplication complited on 27-03-2004
for(i=0;i<30;++i)      //reset result
result[i]='\0';
strrev(bn2); // reversing second binary operand
k=0,x=0;
if(bn2[i]=='1')
{
for(j=i+1;bn2[j]!='\0';++j)
multi[k][x++]='0';
for(l=0;bn1[l]!='\0';++j,++l)
multi[k][x++]=bn1[l];
for(;x<30;++j)
multi[k][x++]='0';
++k,x=0;
}
l=0;
for(j=0;j<30;++j)  //addition of all columns without carry
{
x=0;
for(i=0;i<k;++i)
x+=(multi[i][j]-48);
multi[0][l++]=x;
}
for(i=0;i<30;++i)   //loop for including carry.
if(multi[0][i]>1)
multi[0][i+1]+=((multi[0][i]-(multi[0][i]%2))/2);
printf("\n");
for(i=29;i>=0;--i)  // excluding first zero's (0's) of array
if(multi[0][i]!=0)
break;
j=0;
for(;i>=0;--i)   // final calculations and print
if(multi[0][i]<48)
{
multi[0][i]%=2;
result[j++]=multi[0][i]+48;
//    printf("%d",multi[0][i]);
}
printf("\n");
printf("%s\n",result);
break;
case 6:        //result in decimal
b_to_d(result);
printf("\n");
break;
}
n1=x1;
d_to_b(n1,binary);
for(i=0;binary[i]!='\0';++i)
bn1[i]=binary[i];
bn1[i]='\0';

n2=x2;
d_to_b(n2,binary);
for(i=0;binary[i]!='\0';++i)
bn2[i]=binary[i];
bn2[i]='\0';

}while(ch!=7);
printf("\n\n i will wait for your mails");
getch();
return 0;
}

void b_to_d(char result[]) //binary to decimal
{
short int i;
long int dec=0;
strrev(result);
for(i=0;i<strlen(result);++i)
dec+=(result[i]-48)*pow(2,i);
printf("result in decimal is %ld\n",dec);
strrev(result);
}

void d_to_b(int dec,char binary[]) // decimal to binary
{
int i=0;
while(dec>0)
{
binary[i++]=dec%2+48;
binary[i]='\0';
dec-=(dec%2);
dec/=2;
}
}
```

## C++ Algorithms Code Examples:- Binary Search Tree

`Binary Search Tree `
` `
` `
` `
` `
``` #include<iostream.h>
#include<conio.h>
#include<alloc.h>

struct tree
{
int data;
tree *left;
tree *right;
}*sptr,*q;
void rightcheck();
void leftcheck();
void search();

int insdata;
tree *node;
void main()
{
clrscr();
node=new tree;
cin>>node->data;
sptr=node;
q=sptr;
node->left=NULL;
node->right=NULL;
cout<<"   GIVE THE child->>";
cin>>insdata;
search();
while(insdata!=0)
{
if(insdata>sptr->data)
rightcheck();
else
leftcheck();
cout<<"   GIVE  THE  child->>";
cin>>insdata;
search();
sptr=node;
}
getch();
}
void rightcheck()
{
if(sptr->right==NULL)
{
cout<<"    "<<insdata<<" IS THE  RIGHT  child of "<<q->data<<endl;
sptr->right=new tree;
sptr=sptr->right;
sptr->data=insdata;
sptr->left=NULL;
sptr->right=NULL;
q=node;
}
else
{
if(insdata>sptr->data)
{
sptr=sptr->right;
q=sptr;
if(insdata>sptr->data)
rightcheck();
else
leftcheck();
}
else
{
sptr=sptr->left;
q=sptr;
leftcheck();
}
}
}
void leftcheck()
{
if(sptr->left==NULL)
{
cout<<"   "<<insdata<<" IS THE LEFT child of "<<q->data<<endl;
sptr->left=new tree;
sptr=sptr->left;
sptr->data=insdata;
sptr->right=NULL;
sptr->left=NULL;
q=node;
}
else{
if(insdata<sptr->data)
{
sptr=sptr->left;
q=sptr;
if(insdata>sptr->data)
rightcheck();
else
leftcheck();
}
else
{
sptr=sptr->right;
q=sptr;
rightcheck();}
}
}

void search()
{
sptr=node;
while(sptr!=NULL)
{
if(insdata==sptr->data)
{
cout<<"This is not insertable.";
cout<<"\nInsert child ";
cin>>insdata;
search();
break;
}
else
{
if(insdata>sptr->data)
sptr=sptr->right;
else
sptr=sptr->left;
}
}
sptr=node;

}
```

## C++ Algorithms Code Examples:- Frequency words,characters

`Frequency words,characters `
` `
```

```
` `
``` // ISO/ANSI C program
// 0 Errors and 0 Warnings on turboC 3.0 compilers
// borland 3.0

#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
int ch,i,j,k,l,fc[50][2],flag;
char line[50],fw[50][50];
clrscr();
do
{
printf("\n<1> Input a line");
printf("\n<2> Number of characters");
printf("\n<3> Number of words");
printf("\n<4> Number of vowals");
printf("\n<5> Frequency of characters");
printf("\n<6> Frequency of words");
printf("\n<7> Exit\n");
do
{
scanf("%d",&ch);
}while(ch>7 || ch<1);
switch (ch)
{
case 1:        //input a line
printf("\n Enter a line ");
scanf("\n%[^\n]",line);
break;
case 2:        //number of characters
j=0;
for(i=0;i<strlen(line);++i)
{
if(line[i]>64 && line[i]<93)
++j;
else
if(line[i]>96 && line[i]<123)
++j;
}
printf("total number of characters are %d",j);
break;
case 3:        //number of words
j=0;
for(i=0;i<strlen(line);++i)
{
if(line[i]==' ' || line[i]=='\t')
continue;
else
{
for(k=i;k<strlen(line);++k)
{
if(line[k]==' ' || line[k]=='\t')
break;
else
++i;
}
}
++j;
}
printf("\n total number of words are %d",j);
break;
case 4:        //number of vowels
j=0;
for(i=0;i<strlen(line);++i)
{
if(line[i]=='a' || line[i]=='e' || line[i]=='i' || line[i]=='o' || line[i]=='u')
++j;
else
if(line[i]=='A' || line[i]=='E' || line[i]=='I' || line[i]=='O' || line[i]=='U')
++j;
}
printf("total number of vowels are %d",j);
break;
case 5:        //frequency of characters
for(i=0;i<strlen(line);++i)
{
fc[i][1]=0;
flag=0;
for(j=0;j<strlen(line);++j)
{
if(line[i]==fc[j][0])
{
fc[j][0]=line[i];
++fc[j][1];
flag=1;
break;
}
}
if(flag==0)
fc[i][0]=line[i],fc[i][1]=1;
}
printf("\n Frequency of each characters");
for(i=0;i<strlen(line);++i)
if(fc[i][1]!=0)
printf("\n%c %d",fc[i][0],fc[i][1]);
break;
case 6:        //frequency of words
j=0;
for(i=0;i<strlen(line);++i)
{
if(line[i]==' ' || line[i]=='\t')
continue;
else
{
l=0;
for(k=i;k<strlen(line);++k)
{
if(line[k]==' ' || line[k]=='\t')
break;
else
{
fw[j][l]=line[k],fw[j][++l]='\0';
++i;
}
}
}
++j;
}
for(i=0;i<j;++i)
{
fc[0][0]=0;
for(k=i;k<j;++k)
{
flag=1;
for(l=0;l<j;++l)
if(fw[i][l]!=fw[k][l])
flag=0;
if(flag==1)
{
++fc[0][0];
if(fc[0][0]>1)
fw[k][0]='\0';
}
}
if(fc[0][0]>0)
{
flag=0;
do
{
printf("%c",fw[i][flag]);
} while(fw[i][flag++]!='\0');
if(fw[i][0]!='\0')
printf("%d\n",fc[0][0]);
}
fc[0][0]=0;
}
break;
}
}while(ch!=7);
printf("\n\n i will wait for your mails ");
getch();
return ;
}
```

## C++ Algorithms Code Examples:- Info person

`Info person `
` `
```

```
` `
``` #include<iostream.h>
#include<conio.h>
class person
{
long pno,ctzno;
public:
void info()
{
cout<<"Enter the name:";
cin>>name;
cout<<"Enter the phone no:";
cin>>pno;
cout<<"Enter the citizenship no:";
cin>>ctzno;
}
void PrintInfo()
{
cout<<"********************Person Data***************************"<<endl;
cout<<"Name:"<< name <<endl;
cout<<"Phone no:"<<pno<<endl;
cout<<"Citizenship no:"<<ctzno<<endl;
cout<<"********************Thank YOU******************************"<<endl;
}
};
void main()
{
person d;
d.info();
d.PrintInfo();
getch();
}
```

## C++ Algorithms Code Examples:- Byte alignment in a struct

`Byte alignment in a struct `
` `
```

```
` `
` `
``` #include <iostream.h>

#define ALIGN 8
#pragma pack(ALIGN)

/* Algorithm

Byte offset between currentType and nextType  = MIN( multiple of Byte
Alignment specified , multiple of size of nextType)
**/

nextTypeSize)
{

int nOffset = currrentTypeSize ;//this is size of the current
type.Offset will be minimum of this size.
increased by size of current type.
if( nextTypeSize < ALIGN) // now alignment depens on the next type
and also alignment defined by #pragam pack(#)
{
// if the size of next type is less than byte alignment size
specified , then offset will be increased to the muliple of
// size of next type.
int nRemainder  = currRelativeAddess % nextTypeSize ;
if(nRemainder != 0)
{
nOffset += nextTypeSize - nRemainder ;//this will
align boundary to next multiple of nextTypeSize
}

}
else
{
// if the byte alignment size specified is less than size of
next type , then offset will be increased to the next muliple of
// size of byte alignment.
int nRemainder  = currRelativeAddess % ALIGN ;
if(nRemainder != 0)
{
nOffset += ALIGN - nRemainder ;//this will align the
boundary to next multiple of ALIGN
}
}
return nOffset ;
}

struct S
{

char a[2];
int b;
double c;
char d[1];
int e;
double f;
};

void main()
{
S sz;
cout << "size of struct :" << sizeof(sz) << endl;
cout << "address of size::a "<< &sz.a <<" Actual offset = " <<
int(0) << " Calculated offset = " << 0 << endl;

int offset = ((int)&sz.b)- (int)(&sz.a);

cout << "address of size::b " << &sz.b <<" Actual offset = " <<
offset << " Calculated offset = " << ALIGNOFFSET((int)(&sz.a)-
(int)(&sz),sizeof(sz.a),sizeof(sz.b)) << endl;
offset = ((int)&sz.c)- (int)(&sz.b);

cout << "address of size::c " << &sz.c <<" Actual offset = " <<
offset << " Calculated offset = " << ALIGNOFFSET((int)(&sz.b) -
(int)(&sz),sizeof(sz.b),sizeof(sz.c)) << endl;
offset = ((int)&sz.d)- (int)(&sz.c);

cout << "address of size::d " << &sz.d <<" Actual offset = " <<
offset << " Calculated offset = " << ALIGNOFFSET((int)(&sz.c)-
(int)(&sz),sizeof(sz.c),sizeof(sz.d)) << endl;

offset = ((int)&sz.e)- (int)(&sz.d);

cout << "address of size::e " << &sz.e <<" Actual offset = " <<
offset << " Calculated offset = " << ALIGNOFFSET((int)(&sz.d)-
(int)(&sz),sizeof(sz.d),sizeof(sz.e)) << endl;
offset = ((int)&sz.f)- (int)(&sz.e);
cout << "address of size::f " << &sz.f <<" Actual offset = " <<
offset << " Calculated offset = " << ALIGNOFFSET((int)(&sz.e)-
(int)(&sz),sizeof(sz.e),sizeof(sz.f)) << endl;
}
```

## C++ Algorithms Code Examples Graphic Simulation for Shortest & 2nd shortest path in a Weighted Graph

`Graphic Simulation for Shortest & 2nd shortest path `
```in a Weighted Graph

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
float
sum=0,w=0,s,wn,v[8],td=0,e,i,j,n,w1[8],j1[8],arr[8],arr1[8],e1,count,d2,y1
;
float var,a[8][8],d[8],p[8],n1,c,c1,w2;
void main()
{
int gd=DETECT,gm;
clrscr();
void draw(float,float);
void dijkstra(float s,float e,float v1[8],float d1[8],float p1[8],float
a1[8][8],float n);
void ssp();
void path();
void initial();
printf("There are 8 routers in each subnet
");
n=8;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=32767;
}}
printf("Enter the weight between 0 & 1 : ");
scanf("%f",&a[0][1]);
a[1][0]=a[0][1];
printf("Enter the weight between 0 & 3 : ");
scanf("%f",&a[0][3]);
a[3][0]=a[0][3];
printf("Enter the weight between 1 & 5 : ");
scanf("%f",&a[1][5]);
a[5][1]=a[1][5];
printf("Enter the weight between 1 & 2 : ");
scanf("%f",&a[1][2]);
a[2][1]=a[1][2];
printf("Enter the weight between 2 & 4 : ");
scanf("%f",&a[2][4]);
a[4][2]=a[2][4];
printf("Enter the weight between 2 & 3 : ");
scanf("%f",&a[2][3]);
a[3][2]=a[2][3];
printf("Enter the weight between 3 & 7 : ");
scanf("%f",&a[3][7]);
a[7][3]=a[3][7];
printf("Enter the weight between 4 & 5 : ");
scanf("%f",&a[4][5]);
a[5][4]=a[4][5];
printf("Enter the weight between 4 & 7 : ");
scanf("%f",&a[4][7]);
a[7][4]=a[4][7];
printf("Enter the weight between 5 & 6 : ");
scanf("%f",&a[5][6]);
a[6][5]=a[5][6];
printf("Enter the weight between 6 & 7 : ");
scanf("%f",&a[6][7]);
a[7][6]=a[6][7];
printf("Enter source and destination node from network 1 ");
scanf("%f %f",&s,&e);
clrscr();
initgraph(&gd,&gm,"c:\tc\bgi");
setcolor(WHITE);
fillellipse(20,100,7,7);fillellipse(85,50,7,7);
fillellipse(150,100,7,7);fillellipse(85,150,7,7);
fillellipse(320,100,7,7);fillellipse(385,50,7,7);
fillellipse(450,100,7,7);fillellipse(385,150,7,7);
w1[0]=20;w1[1]=85;w1[2]=150;w1[3]=85;w1[4]=320;
w1[5]=385;w1[6]=450;w1[7]=385;
j1[0]=100;j1[1]=50;j1[2]=100;j1[3]=150;j1[4]=100;j1[5]=50;
j1[6]=100;j1[7]=150;
initial();
setcolor(GREEN);
for(i=0;i<n;i++)
{
v[i]=32767;
d[i]=32767;
p[i]=0;
}
w=s;
d[s]=0;
v[s]=s;
td=0;
dijkstra(s,e,v,d,p,a,n);
path();
c=w1[e];
c1=j1[e];
printf("One more packet ?(Type 1 if yes) ");
scanf("%f",&count);
path();
if(count==1)
ssp();
path();
w=e;
setcolor(GREEN);
count=0;
printf("Enter source and destination node from network 2 ");
scanf("%f %f",&s,&e);
a[0][1]=2;
a[0][3]=6;
a[1][2]=2;
a[1][5]=7;
a[2][3]=1;
a[2][4]=2;
a[4][5]=3;
a[5][6]=3;
a[4][7]=2;
a[6][7]=2;
a[3][7]=4;
a[1][0]=2;
a[3][0]=6;
a[2][1]=2;
a[5][1]=7;
a[3][2]=1;
a[4][2]=2;
a[5][4]=3;
a[6][5]=3;
a[7][4]=2;
a[7][6]=2;
a[7][3]=4;
setcolor(WHITE);
fillellipse(20,400,7,7);fillellipse(85,350,7,7);
fillellipse(150,400,7,7);fillellipse(85,450,7,7);
fillellipse(320,400,7,7);fillellipse(385,350,7,7);
fillellipse(450,400,7,7);fillellipse(385,450,7,7);
w1[0]=20;w1[1]=85;w1[2]=150;w1[3]=85;w1[4]=320;
w1[5]=385;w1[6]=450;w1[7]=385;
j1[0]=400;j1[1]=350;j1[2]=400;j1[3]=450;j1[4]=400;j1[5]=350;
j1[6]=400;j1[7]=450;
initial();
setcolor(GREEN);
for(i=0;i<n;i++)
{
v[i]=32767;
d[i]=32767;
p[i]=0;
}
w=s;
d[s]=0;
v[s]=s;
td=0;
line(c,c1,w1[s],j1[s]);
delay(2000);
dijkstra(s,e,v,d,p,a,n);
path();
if(count==1)
ssp();
path();
getch();
}
void dijkstra(float s,float e,float v1[8],float d1[8],float p1[8],float
a1[8][8],float n)
{
while((p1[e])==0)
{
for(i=0;i<n;i++)
{
if((a1[w][i]+td)<d1[i]&&i!=w&&a1[w][i]!=32767)
{
d1[i]=a1[w][i]+td;
d2=d1[i];
v1[i]=w;
}}
sum=32767;
for(i=0;i<n;i++)
{
if(d1[i]<sum&&i!=s&&p1[i]!=1)
{
sum=d1[i];
wn=i;
}}
p1[wn]=1;
td=d1[wn];
w=wn;
}
}
void draw(float w,float v1)
{
float s,x,y;
s=(j1[v1]-j1[w])/(w1[v1]-w1[w]);
if(s<0)
s=s*-1;
x=w1[w];
y=j1[w];
moveto(x,y);
if(x==w1[v1])
{
while(y!=j1[v1])
{
if(y>j1[v1])
{
line(x,y,x,y-1);
delay(10);
y=y-1;
}
else
{
line(x,y,x,y+1);
delay(10);
y=y+1;
}}}
if(y==j1[v1])
{
while(x!=w1[v1])
{
if(x>w1[v1])
{
line(x,y,x-1,y);
delay(10);
x=x-1;
}
else
{
line(x,y,x+1,y);
delay(10);
x=x+1;
}}}
if(x<w1[v1]&&y<j1[v1])
{
while(x!=w1[v1])
{
line(x,y,x+1,y+s);
delay(10);
x=x+1;
y=y+s;
}}
if(x>w1[v1]&&y>j1[v1])
{
while(x!=w1[v1])
{
line(x,y,x-1,y-s);
delay(10);
x=x-1;
y=y-s;
i=i+1;
}}
if(x>w1[v1]&&y<j1[v1])
{
while(x!=w1[v1])
{
line(x,y,x-1,y+s);
delay(10);
x=x-1;
y=y+s;
i=i+1;
}}
if(x<w1[v1]&&y>j1[v1])
{
while(x!=w1[v1])
{
line(x,y,x+1,y-s);
delay(10);
x=x+1;
y=y-s;
i=i+1;
}
}}
void ssp()
{
d2=y1=32767;
setcolor(RED);
e1=e;
for(i=0;i<n;i++)
{
arr1[i]=v[i];
arr[i]=v[i];
}
while(e1!=s)
{
var=a[e1][arr1[e1]]=a[arr1[e1]][e1];
a[e1][arr1[e1]]=a[arr1[e1]][e1]=32767;
for(i=0;i<n;i++)
{
v[i]=32767;
d[i]=32767;
p[i]=0;
}
w=s;d[s]=0;
v[s]=s;
td=0;
dijkstra(s,e,v,d,p,a,n);
if(d2<y1)
{
y1=d2;
for(i=0;i<n;i++)
arr[i]=v[i];
}
a[e1][arr1[e1]]=a[arr1[e1]][e1]=var;
e1=arr1[e1];
}}
void path()
{
while(w!=s)
{
if(count==0)
{
draw(w,v[w]);
w=v[w];
}
else
{
draw(w,arr[w]);
w=arr[w];
}}}
void initial()
{
line(w1[0],j1[0],w1[1],j1[1]);
line(w1[0],j1[0],w1[3],j1[3]);
line(w1[1],j1[1],w1[5],j1[5]);
line(w1[1],j1[1],w1[2],j1[2]);
line(w1[2],j1[2],w1[4],j1[4]);
line(w1[2],j1[2],w1[3],j1[3]);
line(w1[3],j1[3],w1[7],j1[7]);
line(w1[4],j1[4],w1[5],j1[5]);
line(w1[4],j1[4],w1[7],j1[7]);
line(w1[5],j1[5],w1[6],j1[6]);
line(w1[6],j1[6],w1[7],j1[7]);
}
```

## C++ Algorithms Code Examples:- Complex nos

C++ Algorithms Code Examples:- Complex nos

```#include<iostream.h>
#include<conio.h>
class complex
{
private:
float real,img;
public:
void assign(float x,float y)
{
real=x;
img=y;
}
void print()
{  if(img>=0)
cout<<real<<"+"<<img<<"i";
else
cout<<real<<img<<"i";
getch();
}
};
void add( float a,float b,float c, float d)
{

float e,f;complex g;
e=a+c;
f=b+d;
g.assign(e,f);
g.print();
}
void sub( float a,float b,float c, float d)
{

float e,f;complex g;
e=a-c;
f=b-d;
g.assign(e,f);
g.print();
}
void mul( float a,float b,float c, float d)
{

float e,f; complex g;
e=a*c-b*d;
f=b*c+a*d;
g.assign(e,f);
g.print();
}
void main()
{
float a,b,c,d;
complex x,y,z;
clrscr();
cout<<" for complex 1:";
cout<<"real part:";
cin>>a;
cout<<"imaginary part:";
cin>>b;
cout<<" for complex 2:";
cout<<"real part:";
cin>>c;
cout<<"imaginary part:";
cin>>d;
x.assign(a,b);
y.assign(c,d);
cout<<"**************original data:************\n";
cout<<"Complex 1:\n";x.print();
cout<<"\n Complex 2:\n";y.print();
cout<<"\n************=================**********\n";
cout<<"\n Subtraction:\n";sub(a,b,c,d);
cout<<"\n Multipication:\n";mul(a,b,c,d);
}
```

## C++ Algorithms Code Examples:- Copying one or more than one file into one file

`Copying one or more than one file into one file `
` `
```

```
` `
``` #include <stdio.h>

void main(int argc,char *argv[]){
int i=0,
is_copied=0;

FILE *input,
*output;

char ch;

clrscr();

if (argc>=3){

/* last file is the output file */
output=fopen(argv[argc-1],"w+");
if (output==NULL){
gotoxy(10,1);
printf("Can't open output file :%s",argv[argc-1]);
getch();
return;
}

/* input files */
for(i=1;i<argc-1;i++){
input=fopen(argv[i],"r");

if (input==NULL){
gotoxy(10,i+2);
printf("Can't open input file :%s",argv[i]);
}
else{
/* writing from input file to output file */

rewind(input);
while((ch=fgetc(input))!=EOF){
fprintf(output,"%c",ch);
is_copied=1;
}

gotoxy(10,i+2);

if (is_copied)
printf("%s successfully copied into %s",argv[i],argv[argc-1]);
else
printf("%s can't copy into %s",argv[i],argv[argc-1]);

is_copied=0;

}
fclose(input);
}

fclose(output);

}
else{
gotoxy(10,1);
printf("please specifiy at least two file one source and another target");
}

getch();
}
```

## C++ Program :Algorithms Code Examples

C++ Program :Algorithms Code Examples

```Inheritance Example

class Person
{
public:
Person(const string& firstName, const string& lastName) : _firstName(firstName), _lastName(lastName);
string getFirstName() { return _firstName;};
string getLastName() { return _lastName;};
private:
string _firstName;
string _lastName;
}

class Mother : public Person
{
public:
Mother(const string& firstName, const string& lastName) : Person(firstName, LastName);
~Mother();
Person* hasBaby(const string& firstName);
private:
vector<Person*> children;
};

Person* Mother::hasBaby(const string& firstName);
{
Person* newBaby = new Person(firstName, getLastName());
children.pushback(newBaby);
return newBaby;
}

int main(void)
{
Mother sue("Sue", "Smith");
Person joe = sue.hasBaby("Joe");
Person kay = sue.hasBaby("Kay");

cout << "Baby Joe's last name is: " << joe.getLastName() << endl;
cout << "Baby Kay's last name is: " << kay.getLastName() << endl;

return 0;
}
```

## C++ Program: Accessing SQL Server from C++

Accessing SQL Server from C++

#define DBNTWIN32
#include <stdio.h>
#include <windows.h>
#include <sqlfront.h>
#include <sqldb.h>

// Forward declarations of the error handler and message handler.

int err_handler(PDBPROCESS, INT, INT, INT, LPCSTR, LPCSTR);
int msg_handler(PDBPROCESS, DBINT, INT, INT, LPCSTR, LPCSTR,
LPCSTR, DBUSMALLINT);
main()
{
PDBPROCESS dbproc; // The connection with SQL Server.
DBCHAR name[100];
DBCHAR city[100];

// Install user-supplied error- and message-handling functions.

dberrhandle (err_handler);
dbmsghandle (msg_handler);

// Initialize DB-Library.

dbinit ();

// Get a DBPROCESS structure for communication with SQL Server.

// Retrieve some columns from the authors table in the
// pubs database.
// First, put the command into the command buffer.

dbcmd (dbproc, "SELECT au_lname, city FROM pubs..authors");
dbcmd (dbproc, " WHERE state = 'CA' ");

// Send the command to SQL Server and start execution.

dbsqlexec (dbproc);

// Process the results.

if (dbresults (dbproc) == SUCCEED)
{

// Bind column to program variables.

dbbind (dbproc, 1, NTBSTRINGBIND, 0, name);
dbbind (dbproc, 2, NTBSTRINGBIND, 0, city);

// Retrieve and print the result rows.

while (dbnextrow (dbproc) != NO_MORE_ROWS)
{
printf ("%s from %s\n", name, city);
}
}

// Close the connection to SQL Server.

dbexit ();
return (0);
}

int err_handler (PDBPROCESS dbproc, INT severity,
INT dberr, INT oserr, LPCSTR dberrstr, LPCSTR oserrstr)
{
printf ("DB-Library Error %i: %s\n", dberr, dberrstr);
if (oserr != DBNOERR)
{
printf ("Operating System Error %i: %s\n", oserr, oserrstr);
}
return (INT_CANCEL);
}

int msg_handler (PDBPROCESS dbproc, DBINT msgno, INT msgstate,
INT severity, LPCSTR msgtext, LPCSTR server,
LPCSTR procedure, DBUSMALLINT line)
{
printf ("SQL Server Message %ld: %s\n", msgno, msgtext);
return (0);
}

# ShareExpenses.Com

This website allows user record expenses regarding a programme like a trip so that how much each member of the trip owes and pays is tracked. This website used the following tools and technologies.
• Asp.Net 4.0
• C# Language
• SQL Server 2008 Express Edition
• Visual Studio.NET 2010
• Layered Architecture with Presentation Layer and Data Access Layer
• ObjectDataSource is used in presentation layer to talk to DAL.
• DropDownList, GridView, FormView are mainly used for UI
• ADO.NET is used to access database
• Stored Procedures in SQL Server are used to perform some major operations
• Validation Controls
• Forms Authentication
• Mutlitple Authorizations - one for website and one for all folder
• hMailServer to send mails during password recovery
• Master pages and Themes
• AJAX using UpdatePanel
The following are the major operations in this application.
• Registration of user
• Add a member to a programme
• Get details of a programme including how much each member paid so far and owes
• Delete a programme with all its details
• Add contribution by a member towards the programme
• Add expenditure related to a programme
• List expenses related to a programme including members share
• Logout

The following are the steps to be taken to run the existing part of the application. Sql Server database, which contains all required tables, is boundled along with this application.
1. Download ShareExpenses.rar and unzip it into any directory in your system. For example, if you extract to c:\ then it will create a directory c:\ShareExpenses.
2. Open Visual Studio.NET 2010
3. Open the website from the directory into which you extracted the .rar file. For example, c:\ShareExpenses
4. Database (Database.dbf) is placed in App_Data and it contains required tables. Tables contains some sample data for testing.
5. I also proived tables.sql, which contains commands to create tables. Though not required now, it could be useful in some cases.
6. Go to Solution Explorer and make login.aspx the startup page.
7. Run project from Visual Studio.NET 2010
8. You should see login.aspx page.
9. Before you use Forgot Password option, make sure you installed a mail server in your system or network.
10. Register a user. And test other options

## CodeSnippets.Com | Asp.Net 4.0 C# Language SQL Server 2008 Express Edition Project

This website allows user to post code on different topics.
This website used the following tools and technologies.
• Asp.Net 4.0
• C# Language
• SQL Server 2008 Express Edition
• Visual Studio.NET 2010
• Layered Architecture with Presentation Layer and Data Access Layer
• ObjectDataSource is used in presentation layer to talk to DAL.
• GridView and FormView are used to display and modify data
• ADO.NET is used to access Database
• Validation Controls
• Forms Authentication
• Mutlitple Authorizations - one for website and one for all folder
• hMailServer to send mails during password recovery
• Master pages and Themes
• Asp.Net Ajax to verify uniqueness of username
• SiteMap, SiteMapPath and TreeView
The following are the major operations in this application.
• Registration of user
• Change Profile
• Post Code Snippet
• List of code snippets of current user
• Updating code snippet by the owner
• Deleting code snippet by the owner
• Search for code snippets by title
• Displaying topics with number of code snippets
• List of code snippets by topic
• Details of code snippet
• Allowing user to rate snippet
• Logout

The following are the steps to be taken to run the existing part of the application. Sql Server database, which contains all required tables, is boundled along with this application.
1. Download codesnippets.rar below and unzip it into any directory in your system. For example, if you extract to c:\ then it will create a directory c:\codesnippets.
2. Open Visual Studio.NET 2010
3. Open the website from the directory into which you extracted the .rar file. For example, c:\codesnippets
4. Database (Database.dbf) is placed in App_Data and it contains required tables. Tables contains some sample data for testing.
5. I also proived tables.sql, which contains commands to create tables. Though not required now, it could be useful in some cases.
6. Go to Solution Explorer and make login.aspx the startup page.
7. Run project from Visual Studio.NET 2010
8. You should see login.aspx page.
9. Before you use Forgot Password option, make sure you installed a mail server in your system or network.
10. Register a user. And test other options

## Photos Collection System Developed in ASP.NET 4.0 using C# with Free Source Codes

Photos Collection System Developed in ASP.NET 4.0 using C# with Free Source Codes, This website allows users to upload photos, which can be searched and downloaded by others.
The following are major activities in this application.
• Displaying details of photos
• Seaching for photos
• Browse photos by category

### Technologies and Products Used

• ASP.NET 4.0
• C# language
• Visual Studio.NET 2010
• SQL Server 2005 Express Edition
• FormView, DataList, FileUpload, CalendarExtender controls
• ObjectDataSource to get data from DAL and bind data to data-bound controls such as FormView and DataList
• Data Access Layer - DAL, to access database.

The following are the steps to related to be taken to run the existing part of the application.
1. Download photos.com.rar below and unzip it into any directory in your system. For example, if you extract to c:\ then it will create a directory c:\photos.com. This website has a local database with required tables. So no need to create tables elsewhere.
2. Open Visual Studio.NET 2010 or Visual Web Developer 2010.
3. Open the project from the directory into which you extracted project.For example, c:\photos.com
4. Run website

## Employees Depdendents Information | Asp.Net 4.5 Project with free Source Codes

This intranet application allows employees to add, update and delete information about their dependents.

This Employees Depdendents Information | Asp.Net 4.5 Project with free Source Codes used the following tools and technologies.
• Asp.Net 4.5
• C# Language
• SQL Server 2008 Express Edition
• Visaul Studio 2012 Express For Web
• Layered Architecture with Presentation Layer and Data Access Layer
• ObjectDataSource is used in presentation layer to talk to DAL.
• LINQ TO SQL is used to access database
• Validation Controls
• Forms Authentication
• Mutlitple Authorizations - one for website and one for all folder
• hMailServer to send mails during password recovery
• Master pages and Themes
The following are the major operations in this application.
• List of DeDpendents
• Delete Dependent
• Update Dependent
• Logout

The following are the steps to be taken to run the existing part of the application. Sql Server database, which contains all required tables, is boundled along with this application.
1. Download empdepinfo.rar below and unzip it into any directory in your system. For example, if you extract to c:\ then it will create a directory c:\empdepinfo.
2. Open Visual Studio 2012
3. Open the website from the directory into which you extracted the .rar file. For example, c:\empdepinfo
4. Database (Database.dbf) is placed in App_Data and it contains required tables. Tables contains some sample data for testing.
5. I also proived tables.sql, which contains commands to create tables. Though not required now, it could be useful in some cases.
6. Go to Solution Explorer and make login.aspx the startup page.
7. Run project from Visual Studio.NET 2012
8. You should see login.aspx page.
9. Before you use Forgot Password option, make sure you installed a mail server in your system or network.

## Latest Projects Ideas for MCA, BCA, Btech Students Part 3

1. Point of sale ( POS )
This project is about inventory management system for particular organization Technology : JSP ( JAVA SERVER PAGES )

2. My first English word dictionary
This is a small mobile application to play a game for the kids. Where kids can increase their vocabulary Technology : I-phone

3. Tps Messanger
TPS Messanger allow end user to chat with multiple user in an organization. FRONT END : Android 2.2 BACK END : MySQL

4. E-Bidding System
This is the system for online bidding system. Front End : ASP.NET C# BACK END : MS SQL 2008

5. Tps Messanger
TPS Messanger allow end user to chat with multiple user in an organization. FRONT END : Android 2.2 BACK END : MySQL

6. E-Bidding System
This is the system for online bidding system. Front End : ASP.NET C# BACK END : MS SQL 2008

7. Durga online service management portal
This application allow user to get the computer services at their own. FRONT END : Php5.4 BACK END : MySQL 5.5

8. E-Bidding System
This is the system for online bidding system. Front End : ASP.NET C# BACK END : MS SQL 2008

9. Birthday Reminder
Birthday reminder and scheduler application manages to send the message to birthday person on set schedule date and time. This application manages the event name, event date, schedule date, schedule time, occurrence etc.. Front End: Andriod Back End: SQLite

10. Online property selling system
It is online portal for buyers and sellers who want to invest in real estate business with advance modules using Google API. Front End: Microsoft visual studio 2010 in .NET Framework 4.0 C# Back End: Microsoft SQL Server 2008

Note: In MCA Viva-Vice mostly question asked is what technology the project is used so just remember.