Thursday 7 May 2015

TEXT FILE ANTIVIRUS C++ PROGRAM



This type of antivirus program are followed by many antivirus companies .However there program better then this.This program is only example of antivirus making using c++.
The main logic followed is the matching of characters(signatures) of infected file from virus database provided by company.
1st)   Write VIRUSACTIV on notepad and save it as vdt.dat in TCC. -(this will be your virus database)
2nd)  Write VIRUSACTIV on notepad and save it as inf.dat in TCC.-(filename to be search)
3rd)  Copy below code and run it.--by this u will learn how antivirus worked.



#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
void main()
{ clrscr();
ifstream f1,f2;
f1.open("vdt.dat");//VIRUS DATABASE
char p[100],q[100],w,d;
int i=0,ct=0;
long pos[100],pos2[100];
char comm[300], dirpath[100],filename[20];
while(!f1.eof())
{ f1.get(w);
 if(isalpha(w))
 {
 p[i]=w;
 pos[i]=f1.tellg();  i++;
 }
 } i=0;
 cout<<"**************************WELCOME TO TEXTFILE ANTIVIRUS-H.S*********************\n";
cout<<"\ntype the text(ext ex-txt/dat/bak etc) file name you want to scan = " ;
cin.getline(filename,20);
f2.open(filename);
 while(!f2.eof())
 {f2.get(d);
  if(isalpha(d))
  { q[i]=d;
     pos2[i]=f2.tellg();
     i++;
     }
  }
  for(int a=0;a<10;a++)
  { if((p[a]==q[a])&&(pos[a]==pos2[a]))
  ct++;


  }cout<<"\n*******************************SCAN COMPLETED**********************************\n";
  if (!(ct==10))
 cout<<"\n virus not found in this "<<filename<<" ..try another(existing) file\n";
 else
cout<<"VIRUS FOUND IN THIS" <<filename<< "ACTION-DELETION"<< remove(filename)<<"\n";
cout<<"*************************THANK YOU FOR USING**************************""\n";
cout<<"***************TEXT FILE ANTIVIRUS OF HIMANSHU SINGH************* ";
 getch();
 }
                This is the virus database file which was provided by antivirus company(original virus database file looks different from this vdt.dat). If words like"VIRUS ACTIV" found in inf.dat at the time of scanning .The inf.dat will be tagged as infected file.  
                                                
                                                                OUTPUT

SOCIAL NETWORKING WEBSITE- MY school project


Assume MYNETWORK.COM a social networking website.
Now adding,modifying and deleting account will be taken place on MYNETWORK.COM server.
 

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<fstream.h>
class user
{       char name[20];
        char id[15];
        char password[5];
        char mobno[10];

int uniqno;
        public:
        void getdata(void);
        void display(void);
        int getuniqueno()
        { return uniqno ; }
    void modify();
} s1,d,obj[3],obj2[3] ;

    void user::getdata(void)
      { cout<<"\n Enter name:- ";
       gets(name);
       cout<<"\n Enter username:- ";
       gets(id);
       cout<<"\n  Enter your password (password should NOT be more then 5 character)"  ;
        int i=0;
        while(i<5)
        {
        password[i]=getch();
        cout<<"*";
        ++i;
        }
        cout<<"\nEnter 10 digit mobile number:- ";
        gets(mobno);
    cout<<"\nEnter your own unique number(this use in modifying and deleting account)";
    cin>>uniqno;
         }
    void user ::display(void)
       { cout<<"\nYour Name          :- " <<name;  cout<<"\n";
         cout<<"\nYour email id       :- "<<id<<"@mynetwork.com" ; cout<<"\n";
         cout<<"\nYour Mobile number :- "<<mobno; cout<<"\n";
         cout<<"\n Your Unique number:- "<<uniqno;cout<<"\n";
         }
    void user::modify()
    { cout<<"\nYour Name          :- " <<name;  cout<<"\n";
          cout<<"\nYour email id       :- "<<id<<"@mynetwork.com" ; cout<<"\n";
          cout<<"\nYour Mobile number :- "<<mobno; cout<<"\n";
        char nm[20]=" ",cl[15]=" ",psd[5],mbn[10];
      cout<<"\nNew name:(enter '.' to retain old one)";
        gets(name);
      cout<<"\nNew username:(enter '.' to retain old one)";
        gets(cl);
      cout<<"\nNew password:(enter '1234' to retain old one)";
       
        int op=0;
        while(op<5)
        {
        psd[op]=getch();
        cout<<"*";
        ++op;

        }
      cout<<"\nNew mobile number:(enter '.' to retain old one)";
        gets(mbn);
    if(strcmp(nm,".")!=0)
    strcpy(name,nm);
    if(strcmp(cl,".")!=0)
    strcpy(id,cl);
    if(strcmp(psd,"1234")!=0)
    strcpy(password,psd);
    if(strcmp(mbn,".")!=0)
    strcpy(mobno,mbn);
}

    int n;

         int main()
{

        clrscr();
         const int a=12;
         int ch ,ch2;


          cout<<"\n................................................................................"      ;
          cout<<"\n................................................................................"    ;
      cout<<"\n                  WELCOME     -       TO      -       MYNETWORK   "  ;
          cout<<"\n................................................................................";
          cout<<"\n................................................................................" ;
          cout<<"\n Menu ";
      cout<<"\n Enter 1 - for create account";
      cout<<"\n Enter 2 - for modify exiting account";
      cout<<"\n Enter 3 - for deactivate exiting account";
      cout<<"\n Enter 4 - for return to previous page";
      cout<<"\n Enter your choice:";
        cin>>ch2;
      cout<<"\n" ;
  {
      if (ch2==1)
        {fstream filin;
        filin.open("serverss.dat",ios::in|ios::out);
        if(!filin)
         {cout<<"\n file not present on disk ..canceling...";
          return 1;
          }

             cout<<"\n                 Now create an account \n";
        cout<<"How many accounts you want to create(create only 3 account at a time)";
                      cin>>n;
        for (int ab=0;ab<n;ab++)
        {cout<<"\nEnter your "<<(ab+1)<<" (st/nd/rd) account details";
         obj[ab].getdata();
                  filin.write((char*)&obj[ab],sizeof(obj[ab]));

        }
                 { cout<<"\nEnter this code ... 12 ...in verification box ";
                  cout<<"\nEnter verification code:- ";
                  cin>>ch;
                  if(ch!=a)
                  { exit(1);
                   }
                 }
                 filin.seekg(0);
          cout<<"\n....Your account details are....  ";
          filin.seekg(0);
            for(int r=0;r<n;r++)
            {cout<<"\n Your "<<(r+1)<<" (st/nd/rd) account details are- ";
            filin.read((char*)&obj[r],sizeof(obj[r]));
                  obj[r].display();
        }
                  filin.close();
                 cout<<"\n................................................................................";
                 cout<<"\n................................................................................";
                  cout<<"\n YOUR ACCOUNT HAS BEEN SUCCESFULLY CREATED ";
                  cout<<"THANK YOU FOR CREATING ACCOUNT IN" ;
                  cout<<"  \n           WORLD MOST POPULAR SOCIAL NETWORKING WEBSITE CALLED-   ";
                  cout<<"\n.....................MYNETWORK.COM OF HIMANSHU SINGH......................";
                  cout<<"\n................................................................................";
                  cout<<"\n................................................................................";
}

 if(ch2==2)
{
        {
            fstream fio;
        fio.open("serverss.dat",ios::in|ios::out|ios::binary);
        int un;
        long pos;
    cout<<"\n Enter your unique number for modify";
    cin>>un;
    {pos=fio.tellg();
    fio.read((char*)&s1,sizeof(s1));
    if (s1.getuniqueno()==un)
    { s1.modify();
    fio.seekg(pos);
    fio.write((char*)&s1,sizeof(s1));
    cout<<"YOUR ACCOUNT WAS MODIFIED";

    }
    break;
    }
    fio.close();
    }
}
if(ch2==3)
{int unw;
cout<<"\n Enter your account's unique number for deactivate";
cin>>unw;
      ifstream op;
ofstream it;
op.open("serverss.dat",ios::in|ios::out|ios::binary);
it.open("atvid.dat");
while(!op.eof())
 { op.read((char*)&d,sizeof(d));
   if(d.getuniqueno()!=unw)
    it.write((char*)&d,sizeof(d));
 }
cout<<"YOUR ACCOUNT HAS BEEN DEACTIVATED";
}
if(ch2==4)

    {exit(3);
    }

}

getch();
return 0;


}

LEARN POINTERS

POINTER- A POINTER IS A VARIABLE WHICH HOLDS A MEMORY ADDRESS OF A ANOTHER VARIABLE OF SAME DATA TYPE.

BELOW PROGRAM WILL BE HELP FULL IN UNDERSTANDING POINTERS AND ALSO HELPS IN FINDING OUTPUTS.

int *iptr ;
int a= 25 ;
 iptr = &a ; or iptr =a ;   ----> here iptr holds and show(in output) memory address of 'a'

*iptr = a;                      ----> here itpr holds the value and show(in output) value (25) of 'a'

int b[10];
int *p;
p=b or p=& b[0]  -----> p hold the address of b

for(int i=0; i<2 ; i++)
{cout<< *p <<" ," << p;
p++ ;------->> after this statement p hold next address
}
assume address of b[0]= 1001 & value 25 and b[1]= 1002 & value 12
output- 
           25 , 1001
           12 , 1002

in int
initially pointer p points at the address of b[0].
then after (p + 2)---> p holds the address of b[2].

char t[]='HIM';
char *w ;
w = & t[0];
for(int i=0; i<2 ; i++)
{
       output of  *(w++) is H
                                       I
 ---------------------------------------------------------------------------------------------
       output of  *(++w) is I
                                      M   
 ---------------------------------------------------------------------------------------------     
    output of  ++*w++  is I
                                     J
 ---------------------------------------------------------------------------------------------
       )

SIZE OF FILE

#include<iostream.h>
#include<process.h>
#include<fstream.h>
#include<conio.h>
int main()
{

char d[12]; cout<<"HIMANSHU SINGH\n";
cout<<"-Enter file name ";
cin.getline(d,12);
 ifstream fin;
 fin.open(d,ios::in);
 if(!fin)
 {cout<<"\n file not found ";
 exit(-1);
 }


fin.seekg(0,ios::end);                              or   ifstream fin(filename,ios::in|ios::ate);
 long bytes=fin.tellg();                                   long bytes=fin.tellg();
 cout<<"\n bytes= "<<(bytes);                      cout<<bytes;
 getch();
 return 0;
 }


                                                          file to be check- sizecal.txt
                                                                            
                                                                         output


COUNT LOWERCASE ALPHABET IN A FILE

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<ctype.h>
#include<process.h>
void main()
{clrscr();
ifstream fin;
char filename[12];
cout<<"HIMANSHU SINGH \n";
cout<<"Enter file name\n ";
cin.getline(filename,12);
 fin.open(filename,ios::in);
 if(!fin)
 {
cout<<"\n file not found ";
 exit(-1);
 }
char ch;
int count=0;
while(!fin.eof())
{ fin.get(ch);
 if(islower(ch))
    count++;
}
fin.close();
cout<<"total lowercase alphabets are= "<<count<<"-- HIMANSHU SINGH";
getch();
}

selected file for opening is LOWER.TXT
OUTPUT

COUNT NUMBER OF "LINES" PRESENT IN TEXT FILE

//Assume 60 characters in one line
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<process.h>
void main()
{ ifstream fin;
char filename[12];
cout<<"himanshu singh-  enter file name\n ";
cin.getline(filename,12);
 fin.open(filename,ios::in);
 if(!fin)
 {cout<<"\n file not found ";
 exit(-1);
 }


char s[60];
int cnt=0;
while(!fin.eof())
{ fin.getline(s,60);
cnt++ ;
}
cout<<"HIMANSHU SINGH\n";
cout<<"total number of lines in file is">>cnt;
fin.close();
getch();
}                                                      FILE TO BE CHECK- LINE.TXT

OUTPUT 


SMALLEST & LARGEST ELEMENT IN 2D ARRAY

#include<iostream.h>
#include<conio.h>
int lar(int [][10],int);
int sml(int [][10],int);
int main()
{

    int a[10][10],largest,smallest;
    int size;
cout<<"himanshu singh\n";   
cout<<"for 2d array enter size and array";
    cin>>size;
    for(int i=0;i<size;i++)
     for(int j=0;j<size;j++)
      cin>>a[i][j];
          for(int t=0;t<size;t++)
           { for(int e=0;e<size;e++)
         cout<<" "<<a[t][e];
         cout<<"\n";
         }
     largest = lar(a,size);
     cout<<"\n Largest element in this array was= ";
     cout<<largest;
     cout<<"\n";
     smallest = sml(a,size);
     cout<<"\n Smallest element in this array was= ";
     cout<<smallest;
     getch();
     return 0;
  }

  int lar(int a1[][10],int n)
  {
    int l=a1[0][0];
    for(int p=0;p<n;p++)
     for(int q=0;q<n;q++)
      if(l<a1[p][q])
         l=a1[p][q];

    return (l);
  }
  int sml(int a2[][10],int z)
  {
    int s=a2[0][0];
    for(int r=0;r<z;r++)
     for(int w=0;w<z;w++)
     if(s>a2[r][w])
        s=a2[r][w];

    return (s);
    }

OUTPUT

DIAGONAL ELEMENTS


#include<iostream.h>
#include<conio.h>
void func(int[10][10],int);

void main()
{clrscr();
int a[10][10],n;
cout<<"HIMANSHU SINGH\n";
cout<<"enter size and 2d array";
cin>>n;
cout<<"\n";
for(int x=0;x<n;x++)
{ for(int y=0;y<n;y++)
 cin>>a[x][y];
 }
 func(a,n);

 getch();

 }

 void func(int w[][10],int n)
 {cout<<"DIAGONAL ELEMENTS ARE-\n";
  for(int i=0;i<n;i++)
   { for(int j=0;j<n;j++)
     { if(i==j)
     cout<<w[i][j];
    else
    cout<<"o ";

    }cout<<endl;
    }
cout<<"\n";
    for(int p=0;p<n;p++)
     { for(int q=0;q<n;q++)
      { if((p==(n-1)-q))
     cout<<w[p][q];
     else
     cout<<"o ";


   }     cout<<endl;
      }
   }



OUTPUT
 


CONVERTING OF 1D ARRAY TO 2D ARRAY



#include<iostream.h>
#include<conio.h>
void func(int [],int)  ;
void main()
{clrscr();
int a[10],n;
cout<<HIMANSHU SINGH\n";
cout<<"enter size and array ";
cin>>n;
cout<<"\n";
for(int y=0;y<n;y++)
{
cin>>a[y];
}
func(a,n);
getch();

}
void func(int u[],int t)
{
int a2[20][20];
int i,j;
for(i=0;i<t;i++)
{ for(j=0;j<t;j++)
{if((i+j)>=t)
a2[i][j]=0;
else
a2[i][j]=u[j];
cout<<a2[i][j];
}
 cout<<endl;
}
}


OUTPUT-