u

VB Projects

Get all Visual Basic Projects here..

ASP Dot Net Projects

Get all Asp Dot Net Projects.

C++ Projects and Programs

Get all C++ Projects and Programs here...

PHP Projects

Get all PHP Projets here..

JAVA Projects

Get All JAVA Projects here...

Thursday 5 January 2012

C++ Program to depict the usage of Binary Search Technique


Program to depict the usage of Binary Search Technique. (It is assumed that the list of numbers in an array is  stored in ascending order).

 #include<iostream.h>
#include<conio.h>
main()
{
int num[10],m,min,max,mid,pp;
clrscr();
cout<<"Enter any ten numbers as elements ofan array in";
 cout<<" ascending order "<<endl;
for (int i=0;i<10;i++)
{
cin>>num[i];
}
cout<<endl<<"Enter number to search ";
cin>>m;
cout<<endl;
min = 0;
max = 9;
pp = -1;
while ((min<= max)&&(pp == -1))
{
mid = (min+max)/2;
if (num[mid] == m)
pp = mid;
else
if (num[mid]<m)
min = mid + 1;
else
max = mid - 1;
}
if (pp>-1)
cout<<"The element "<<m<<" lies in the array"<<" at "<<pp+1<<" position";
else
cout<<"The element does not lie in the array";
cout<<endl;
cout<<"Program over....press any key to continue";
getch();
return 0;
}

C++ Program to input any string upto 500 characters and convert the same into binary


C++ Program to input any string upto 500 characters  and convert the same into binary.

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

char *entry, letter, choice[2];
int ascii, len, binary[8], total;
void prog();

int main()
{
      clrscr();
      prog();
      return 0;
}

void prog()
{
   entry = new char[501];
   cout<<"Enter string to convert (up to 500 chars): ";
   cin.getline(entry, 500);
   len = strlen(entry);  /* get the number of characters in entry. */
   for(int i = 0; i<len; i++)
   {
      total = 0;
      letter = entry[i]; /* store the first letter */
      ascii = letter;    /* put that letter into an int, so we can
                see its ASCII number */
      while(ascii>0) /* This while loop converts the ASCII # into binary,
            stores it backwards into the binary array. */
      {
     if((ascii%2)==0)
     {
        binary[total] = 0;
        ascii = ascii/2;
        total++; /* increasing by one each time will yeild the
            number of numbers in the array. */
     }
     else
     {
        binary[total] = 1;
        ascii = ascii/2;
        total++;
     }
      }
      total--;
      while(total>=0)
      {
     cout<<binary[total];
     total--;
      }
   }
   delete[] entry; /* free up the memory used by entry */
   cout<<endl<<"Do again(1 = yes, 2= no)?: ";
   cin.getline(choice,3);
   if(choice[0] == '1')
      prog();
   else
      exit(0); /* quits the program */
}

C++ Program to define a class point and implement operations


C++ Program to define a class point and implement operations.

 #include<iostream.h>
#include<math.h>
#include<conio.h>
class Point{
public:
     Point();
void setPoint(float,float);
void printPoint();
float getx();
float gety();

private:
   float x;
   float y;

      };
  Point::Point(){x=0.0;y=0.0;}
void Point::setPoint(float a,float b)
  {x=a;y=b;}
void Point::printPoint()
     {
     cout<<'('<<x<<","<<y<<')';
     }
float Point::getx(){return x;}
float Point::gety(){return y ;}

  void main()
{
clrscr();
Point p1,p2;
char ch;

cout<<"Initially,the points are :";
  p1.printPoint();

cout<<",";

  p2.printPoint();
cout<<endl;
p1.setPoint(3.5,4.5);
p2.setPoint(7.5,9.5);

  cout<<"After setting the points are:";

p1.printPoint();
cout<<",";
p2.printPoint();
cout<<endl;
  float d=0.0;
d=sqrt((p2.getx()-p1.getx())*(p2.getx()-p1.getx())+(p2.gety()-p1.gety())*(p2.gety()-p1.gety()));
cout<<"d="<<d<<endl;

cout<<"Enter any key to continue";
getch();
}

C++ Program to get the day the month starts on, and the number of days in the month to output a calendar


C++ Program to get the day the month starts  on, and the number of days in the month to  output a calendar.

//-------------------Includes-------------------- 
#include <iostream.h>
#include<conio.h>

//--------------Function Prototypes-------------- 
int ShowDateLine(int day, int EndDay, int BoxWidth); 
void ShowRestOfBox(int BoxWidth, int BoxHeight); 
void ShowDates(int BoxWidth); 
void Divider(int BoxWidth); 

//---------------------Main---------------------- 
int main() 
{
    int StartDay, EndDay, day, counter, weeks; 
    const int BoxWidth = 8, BoxHeight = 3; 
    char end; 
    cout << "1. Sun  2. Mon  3. Tue  4. Wed " << endl; 
    cout << "5. Thu  6. Fri  7. Sat" << endl << endl; 
    do 
    { 
        cout << "Enter the starting day: "; 
        cin >> StartDay; 
        if ((StartDay < 1) || (StartDay > 7)) 
        { 
            cout << "\aError, must be between 1 and 7.\n"; 
    }
    } 
    while ((StartDay < 1) || (StartDay > 7)); /* Error checking */ 
    day = StartDay * -1 + 2; 
    cout << "Enter the amount of days in the month: "; 
    cin >> EndDay; 
    cout << endl; 
    weeks = (EndDay + StartDay - 2) / 7; 
weeks++; 
    //----------------Draw Calendar------------------ 
    ShowDates(BoxWidth); 
    Divider(BoxWidth); 
    for (counter = 0; counter < weeks; counter++) 
    { 
        day = ShowDateLine(day, EndDay, BoxWidth); 
        ShowRestOfBox(BoxWidth, BoxHeight); 
        Divider(BoxWidth); 
    } 
    cout<<"Press any key to continue"<<endl;
getch();
}

//------------------Functions-------------------- 
int ShowDateLine(int day, int EndDay, int BoxWidth) 
/* Outputs a '*' then it outputs the days till it reaches the 'EndWeek' value. 
If day reaches the EndDay value, then it will output a space instead of a day. 
After each date it will output a '*', then proceed 'BoxWidth' spaces ahead. */ 
{ 
    int counter, EndWeek; 
    cout.setf(ios::right); 
    cout << "*"; 
    EndWeek = day + 7; 
    for (counter = 0; counter < 7; counter++, day++) 
    { 
        cout.width(BoxWidth - 1); 
        if ((day < 1) || (day > EndDay)) 
        { 
            cout << " "; 
        } 
        else 
        { 
            cout << day; 
        } 
        cout << "*"; 
    } 
    cout << endl; 

    return day; 
} 
//----------------------------------------------- 
void ShowRestOfBox(int BoxWidth, int BoxHeight) 
/* Outputs a '*' every 'BoxWidth' length, for a total of 8 '*'. 
It does that 'BoxHeight' times. */ 
{ 
    int countera, counterb; 
    cout.setf(ios::right); 
    for (countera = 1; countera < BoxHeight + 0; countera++) 
    { 
        cout << "*"; 
        for (counterb = 0; counterb < 7; counterb++) 
        { 
             cout.width(BoxWidth); 
             cout << "*"; 
        } 
        cout << endl; 
    } 
} 
//----------------------------------------------- 
void ShowDates(int BoxWidth) 
/* Outputs the all 7 days of the week. It takes the 'BoxWidth' and outputs the 
day in the 
middle of where the box will be. */ 
{ 
  cout.setf(ios::right); 
  cout.width(BoxWidth / 2 + 2); 
  cout << "Sun"; 
  cout.width(BoxWidth); 
  cout << "Mon"; 
  cout.width(BoxWidth); 
  cout << "Tue"; 
  cout.width(BoxWidth); 
  cout << "Wed"; 
  cout.width(BoxWidth); 
  cout << "Thu"; 
  cout.width(BoxWidth); 
  cout << "Fri"; 
  cout.width(BoxWidth); 
  cout << "Sat" << endl; 
} 
//----------------------------------------------- 
void Divider(int BoxWidth) 
//Outputs a bar of '*' 'BoxWidth' * 7 + 1 
{ 
    int length, counter; 
    length = BoxWidth * 7 + 1; 
    for (counter = 0; counter < length; counter++) 
    { 
        cout << "*"; 
    } 
    cout << endl; 
}  

C++ Program to print the corresponding ASCII character


C++ Program to print the  corresponding ASCII character
#include <stdio.h>
#include <fstream.h>
#include <stdlib.h>
#include<conio.h>
main()
    {
    clrscr();
    char line[512]; /* input string */
    char sym;       /* ASCII code number */
    cout<<"Please enter the number to be factored: ";
    cin.getline(line, 512);
    sym = atoi(line);
    cout<<int(sym)<<"  is the ASCII code for ";
    if (sym == 0)
    cout<<"null\n";
    else if (sym == ' ')
    cout<<"blank\n";
    else if (sym == 127)
    cout<<"del\n";
    else if (sym >=  1 && sym <=  31)
    cout<<"CONTROL-\n"<< sym + 64;
    else if (sym >= '0' && sym <=  '9')
    cout<<"digit \n"<< sym;
    else if (sym >= 'A' && sym <=  'Z')
    cout<<"UPPERCASE \n"<< sym;
    else if (sym >= 'a' && sym <= 'z')
    cout<<"lowercase \n"<< sym;
    else
    cout<<"punctuation mark \n"<< sym;
    getch();
    }

C++ Program displays the month of any year and also has controls to view the previous & the Next months






C++ Program displays the month  of any year and also has controls to view the   previous & the Next  months.

# include <iostream.h>
# include <stdio.h>
# include <conio.h>
void main()
{
    clrscr();
    int b1,b2,o;
     cout<<"  ENTER THE MONTH  : ";
    cin>>b1;
    cout<<"  ENTER THE YEAR  : ";
    cin>>b2;
    a:cout<<"\n";
     o = b1-1;
    int
i,j,k=0,l=0,m=0,n=0,b3,c=0,c1,c2,c3,a[12]={31,28,31,30,31,30,31,31,30
,31,30,31};
    int ab[12] = {1,2,3,4,5,6,7,8,9,10,11,12};
    char *z[12] =
{"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"};
char choice;
    for (o=0;o<=11;o++)
    {
     if (b1 == ab[o])
     {
      cout<<"\n         "<<z[o]; cout<<"       "<<b2;
     }
    }
    if(b2%4==0)
        a[1] = 29;
    else
        a[1] = 28;
    if(b2>=2000)
        b3=b2-2000;
    else
    {
        b3=2000-b2;
        b3*=2;
    }
    if(b1==12)
        n=12;
    if(b1==1)
    {
        k=11;
        l=1;
        for(i=0;i<=k;i++)
            m+=a[i];
    }
    for(i=0;i<(b1-1);i++)
        c+=a[i];

       c2=(c+b3)%7;
   textcolor(10);
    cout<<"\n\n\n\n";
    cout<<"  SU  MO  TU  WE  TH  FR  SA\n\n";
    for(j=0;j<c2;j++)
        cout<<"    ";
    for(j=1;j<=a[b1-1];j++)
    {
        if(j<10)
            cout<<"   "<<j;
        else
            cout<<"  "<<j;
        if((j+c2)%7==0)

            cout<<"\n\n";
    }
    cout<<"\n";


    cout<<"\n\n Use these arrow keys to display the Sequential Year or Month :   \n";
    cout<<"**************************************************************\n";
    cout<<" |         Up    = Next Year      |   Down = Previous Year   | \n";
    cout<<" |         Right = Next Month   |   Left = Next Month   | \n";
    cout<<"************************************************************** \n";
    choice = getch();
    if (choice==0)
    {
     choice = getch();
     switch(choice)
     {
      case 80  : {b2-=1; goto a; break;}
      case 72  : {b2+=1;goto a; break;}
      case 75 :  {
          if (b1!=1)
                    b1-=1;
                  else
                   {b1=12; b2-=1;}
                 goto a; break;}
      case 77 : {
                 if (b1!=12)
                   b1+=1;
                 else
                   {b1 = 1; b2+=1;}
                 goto a; break;}
     }
    }
 getch();
}

C++ Program to print prime factorization



C++ Program to print prime factorization
 #include<conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <fstream.h>
main()
    {
    clrscr();
    char line[512]; /* input string */
    short ii;   /* number to be factored */
    short j;   /* divisors */
    short p;   /* powers of j in ii */
    cout<<"Please enter the number to be factored: ";
    cin.getline(line, 512);
    ii = atoi(line);
    cout<<"The prime divisors of "<< ii<< " are/ is ";
    for (j = 2; ii != 1; j = j + 1)
    {
    if (ii % j == 0)
        {
        for (p = 0; ii % j == 0; p = p + 1)
        ii = ii / j;
        cout<< j<<" ";
        }
    }
    cout<<endl;
    getch();
    }

C++ Program to conduct binary search for any alphabet [a-z] out of an array


C++ Program to conduct binary search  for any alphabet [a-z] out of an array
#include <ctype.h>
#include <conio.h>
#include <iostream.h>
#define max 26
char array[max] = "\0";
void initialise()
{
    for(int i=0; i<max; i++)
    {
        array[i] = (char)(65+i);
    }
}

int binsearch(int low, int high, int &num)
{
    int mid = (high+low)/2;

    if( array[mid] == num )
    {
        return mid;
    }
    else if( low >= high )
    {
        return -1;
    }
    else if( num > array[mid] )
    {
        return binsearch(mid+1, high, num);
    }
    else if( num < array[mid] )
    {
        return binsearch(low, mid-1, num);
    }
    else return -2;
}

void main()
{
    char    alpha;
    int    number;
    int      result;

    clrscr();
    initialise();

    cout << "Enter the alphabet to search [lower case]: ";
    cin  >> alpha;

    number = (int)toupper(alpha);

    result = binsearch(0, max, number);

    if( result >= 0 )
    {
        cout << "Found at index # : " << result+1;
    }
    else if( result == -1 )
    {
        cout << "Not Found";
    }
        else cout << "Unspecified Error";

        getch();
}

C++ Program using structure to define a Bank A/c System


C++ Program using structure to define a Bank A/c System
#include "iostream.h"
#include "conio.h"
#include "stdio.h"
struct account
{
int no[10];
char name[20];
long int d,b,a;
long double t;
};
void main()
{
clrscr();
window(27,2,53,4);
textbackground(3);
clrscr();
textcolor(0);
cprintf(" \n   BANK ACCOUNT SYSTEM");
/*menu*/
window(20,5,60,25);
textbackground(13);
clrscr();
gotoxy(2,3);
textcolor(10);
cprintf("G");
gotoxy(3,3);
textcolor(14);
cprintf("ive The Account No.");
/*name of the account holder*/
textcolor(10);
gotoxy(2,5);
cprintf("E");
textcolor(14);
gotoxy(3,5);
cprintf("nter The Name ");
/*balance*/
textcolor(10);
gotoxy(2,7);
cprintf("A");
textcolor(14);
gotoxy(3,7);
cprintf("mount");
/*amount*/
account i;
/*input*/
gotoxy(22,3);
cin>>i.no[10];
gotoxy(22,5);
cin>>i.name;
gotoxy(22,7);
cin>>i.a;
gotoxy(3,14);textcolor(11);
cout<<"Name: "<<i.name;
/*runtime calculations*/
/*******************************for deposit*******************************/
i.d=i.a+5;
gotoxy(3,16);
cout <<"The Deposite Is: "<<i.d;
/****************************Tax Deduction ***********************************/
i.t=700.8/i.d*100;
gotoxy(3,18);
cout <<"The deduced Tax is :"<<i.t;
gotoxy(15,35);
cout <<"%";
/***************************For Balance**********************************/
i.b=i.d-i.t;

/********** object of the struct account********************/
if (i.b>0 && i.a<=i.b)
{
    gotoxy(3,20);
    cout <<"WITHDRAW THE BALANCE :"<<i.b;
    }
else
     {
       gotoxy(3,20);textcolor(11);
    cprintf("Can't Withdraw Your Balance!!!");}
getch();
}

C++ Program to perform updation of a data file for mainipulating an address book





C++ Program to perform updation of a data file for mainipulating an address book
#include<stdio.h>
#include<stdlib.h>
#include<fstream.h>
#include<string.h>
#include<conio.h>
#define ENTER 13
#define BACK 8


struct student
{
  char name[30];
  char proff[40];
  char address[20];
  char country[20];
  char tel[20];
  char fax[20];
  char mobile[20];
  char email[50];
};

class data
{
private:
  student std;
  int j,count;
  char sname[50],pass[10],c;
public:
  struct student getData();
  void showData(struct student);
  void saveData();
  int readData();
  void delet();
  void modify();
  void searchData();
  void emergency();
  void password();
  int checkpass();
  void modpass();
  char* takepass();
  int checkvalidity(char []);
};

student data::getData()
{
      cout<<"Name          : ";
      gets(std.name);
      cout<<"Proffession   : ";
      gets(std.proff);
      cout<<"Address       : ";
      gets(std.address);
      cout<<"Country       : ";
      gets(std.country);
      cout<<"Telephone     : ";
      gets(std.tel);
      cout<<"Fax           : ";
      gets(std.fax);
      cout<<"Mobile        : ";
      gets(std.mobile);
      cout<<"E.mail        : ";
      gets(std.email);
}
void data:: showData(student str)
{
     clrscr();
     cout<<"\nName         : "<<str.name;
     cout<<"\nProffession  : "<<str.proff;
     cout<<"\nAddress      : "<<str.address;
     cout<<"\nCountry      : "<<str.country;
     cout<<"\nTelephone    : "<<str.tel;
     cout<<"\nFax          : "<<str.fax;
     cout<<"\nMobile       : "<<str.mobile;
     cout<<"\nE.mail       : "<<str.email;
     getch();
}
void data::modify()
{
     char dname[30];
     int l;
     int coutn=0,choice;
     int k=0;
     l=checkpass();
     if(l==1)
     {
     cout<<"\nPlease mention the name to be modified : ";
     cin>>dname;
     fstream infile;
     infile.open("tata.Dat",ios::in|ios::out);
     infile.seekg(0);
     if(infile)
     {
     while(infile.read((char *)&std,sizeof(student)))
     {
        coutn++;
        char ans='y';
        if(stricmp(std.name,dname)==0)
        {
        k=1;
        while(ans=='y'||ans=='Y')
        {
        clrscr();
        cout<<"What do you want to modify\n1.Name\n2.Proffession\n3.Address ";
        cout<<"\n4.Country\n5.Telephone Number\n6.Fax Number\n7.Mobile";
        cout<<"\n8.E-mail\t";
        cin>>choice;
        switch(choice)
        {
          case 1:
            cout<<"Name          : ";
            cin>>std.name;
            break;
          case 2:
            cout<<"Proffession   : ";
            cin>>std.proff;
            break;
          case 3:
            cout<<"Address       : ";
            cin>>std.address;
            break;
          case 4:
            cout<<"Country       : ";
            cin>>std.country;
            break;
          case 5:
            cout<<"Telephone     : ";
            cin>>std.tel;
            break;
          case 6:
            cout<<"Fax           : ";
            cin>>std.fax;
            break;
          case 7:
            cout<<"Mobile        : ";
            cin>>std.mobile;
            break;
          case 8:
            cout<<"E-mail        : ";
            cin>>std.email;
            break;
          default:
            cout<<"Wrong choice ";
            break;
        }
        cout<<"\nAnything More to modify ";
        cin>>ans;
         }
        infile.seekp((coutn-1)*sizeof(student));
        infile.write((char *)&std,sizeof(student));
        }
     }
     if(k!=1)
        cout<<"The name doesn't exist ";
     else
        cout<<"The name has been successfully modified ";
     }
     }
     else
        cout<<"access denied ";
        getch();
}
void data::delet()
{
     char dname[30];
     int coutn=0;
     int k=0;
     if(checkpass()==1)
     {
     cout<<"\n\nPlease mention the name to be deleted : ";
     gets(dname);
     fstream infile;
     infile.open("tata.Dat",ios::in|ios::out);
     infile.seekg(0);
     if(infile)
     {
     while(infile.read((char *)&std,sizeof(student)))
     {
        coutn++;
        if(stricmp(std.name,dname)==0)
        {
        k=1;
        strcpy(std.name," ");
        strcpy(std.proff," ");
        strcpy(std.address," ");
        strcpy(std.country," ");
        strcpy(std.tel," ");
        strcpy(std.fax," ");
        strcpy(std.mobile," ");
        strcpy(std.email," ");
        infile.seekp((coutn-1)*sizeof(student));
        infile.write((char *)&std,sizeof(student));
        break;
        }
     }
     if(k!=1)
        cout<<"The name doesn't exist ";
     else
        cout<<"The name has been successfully deleted ";
     }
     }
     else
        cout<<"\n\nAccess Denied ";
     getch();
}

void data:: saveData()
{
     ofstream outfile;
     outfile.open("tata.Dat",ios::app);
     outfile.write( (char *)&std,sizeof(student));
}
int data::readData()
{
     count=0;
     ifstream infile;
     infile.open("tata.Dat",ios::app);
     if(infile)
     {
     while(infile.read((char *)&std,sizeof(student)))
     {
        if(strcmp(std.name," ")!=0)
        showData(std);
        count++;
     }
     }
     else
     cout<<"no file";
     return(count);
}
void data::emergency()
{
     char emer[30];
     int j=0;
     cout<<"Please type the name to be searched: ";
     gets(emer);
     ifstream infile;
     infile.open("tata.Dat",ios::nocreate);
     while(infile.read((char *)&std,sizeof(student)))
        {
        if(stricmp(emer,std.proff)==0)
        {
        j=1;
        showData(std);
        }
     }
     if(j==0)
     cout<<"Sorry the name doesn't exist";
     getch();
}
void data::searchData()
{
     j=0;
     cout<<"Please type the name to be searched: ";
     gets(sname);
     ifstream infile;
     infile.open("tata.Dat",ios::nocreate);
     while(infile.read((char *)&std,sizeof(student)))
        {
        if(stricmp(sname,std.name)==0)
        {
        j=1;
        showData(std);
        }
     }
     if(j==0)
     cout<<"Sorry the name doesn't exist";
}
void data::password()
{
     char fre[20];
     int pd;
     clrscr();
     cout<<endl<<endl<<"Password ";
     strcpy(fre,takepass());
     pd=checkvalidity(fre);
     clrscr();
     if(pd==1)
         cout<<"This password already exist Please try for new password ";
     else
     {
         strcpy(pass,fre);
         ofstream passfile;
         passfile.open("pass.dat",ios::app);
         passfile.write(pass,sizeof(pass));
         cout<<"Passwords are sensitive do not lend it ";
     }
}
int data::checkvalidity(char fre[])
{
     int idm=0;
     ifstream passfile;
     passfile.open("pass.dat",ios::app);
     while(passfile.read(pass,sizeof(pass)))
     {
        if(stricmp(fre,pass)==0)
        {
         idm=1;
         break;
        }
     }
     return idm;
}


void data::modpass()
{
  char d[20],npass[20];
  clrscr();
  int me=0,in=0;
  cout<<endl<<endl<<"Old Password ";
  strcpy(d,takepass());

  fstream infile;
  infile.open("pass.dat",ios::out|ios::in);
  {
      while(infile.read(pass,sizeof(pass)))
      {
         me++;
         if(strcmp(d,pass)==0)
         {
            in=1;
            cout<<"\nOK the password exist ";
            getch();
            clrscr();
            cout<<endl<<endl<<"New password ";
            strcpy(pass,takepass());
            infile.seekp((me-1)*sizeof(pass));
        infile.write(pass,sizeof(pass));
         }
      }
  }
  if(in==0)
   cout<<"\nThe password doesn't exist ";
  else
   cout<<"\nThe password has been successfully modified ";
   getch();
}

int data::checkpass()
{
     char da[20];
     int z=0,to=0,u=0;
     clrscr();
     ifstream passfile;
     passfile.open("pass.dat",ios::app);
    while(to<1&&z!=1)
     {
     to++;
     cout<<endl<<endl<<"Your password ";
     strcpy(da,takepass());
     passfile.seekg(0);
     while(passfile.read(pass,sizeof(pass)))
     {
        clrscr();
        if(strcmp(da,pass)==0)
         {
            z=1;
            break;

         }
     }
     }
     return z;
}
char* data::takepass()
{
      char ma[20],pa[20];
     int q=0,row=30,col=3;
     int i=0;
     gotoxy(30,3);
        while((c=getch())!=ENTER)
        {

            if(c==BACK)
            {
               gotoxy((row-1),col);
               cout<<" ";
               row--;
               i--;
            }
            else
            {
               ma[i]=c;
               i++;
               gotoxy(row,col);
               cout<<"*";
               row++;
            }
         }
         ma[i]='\0';
         strcpy(pa,ma);
       clrscr();
         return pa;
}
void main()
{
     clrscr();//Clearing the screen.
     int ch,i,k,a;
     char choice,sm[20];
     data s;
      srand(time(NULL));
     a=1+(rand()%100);
      textcolor(WHITE);
     while(1)
     {
        clrscr();
        cout<<"Your Choices";
        cout<<"\n1.Enter datas\n2.Read From File\n3.Search data\n4.ModifyData\n5.DeleteData\n6.View Emergency Contacts\t";
        cout<<"\n7.Create New Password\n8.Modify Password\n9.Exit\t";
        cin>>ch;
        switch(ch)
        {
         case 1:
             cout<<"How many datas do u want to feed " ;
             cin>>i;
             for(k=0;k<i;k++)
             {
                s.getData( );
                s.saveData();
             }
         break;
         case 2:
             s.readData();
             getch();
         break;
         case 3:
             s.searchData();
             getch();
         break;
         case 4:
             s.modify();
             break;
         case 5:
             s.delet();
             break;
         case 9:
             exit(0);
         case 7:
            cout<<"Please mention Your institution ";
            cin>>sm;
            if((strcmpi(sm,"spsl")==0)&&(a%4==0))
            s.password();
            else
            if((strcmpi(sm,"spsl")==0)&&(a%4!=0))
            {
            clrscr();

            textcolor(LIGHTRED+BLINK);
           gotoxy(25,10);
            cout<<"Sorry the system is busy";
            }
            else
            {
              clrscr();
         gotoxy(25,10);
              textcolor(LIGHTRED+BLINK);
              cout<<"\nYOU ARE NOT THE LEGAL PERSON ";
            }
              getch();
         textcolor(WHITE);
            break;
         case 8:
            s.modpass();
            break;
         case 6:
            s.emergency();
            break;
         default:
             cout<<"\nWrong Choice ";
             getch();
        }
     }
getch();
} 

C++ Program adds two numbers in binary using class and object.





C++ Program adds two numbers in binary using class and object.

#include<iostream.h>
#include<conio.h>
//using namespace std; 

class adder{ 
public: 
   int number1[8]; 
   int number2[8]; 
   int carry[8]; 
   int sum[8]; 
   int number_bits; 
   char choice; 
    
    

   void input(){ 
      cout<<"Input the number of bits you want to enter\n"; 
      cout<<"For the first number \n"; 
      cin>>number_bits; 


      if(number_bits<0||number_bits>8){ 
         cout<<"Error, the number of bits cannot be allowed to be \n"; 
         cout<<"greater than 8 or less than 0\n"; 
         cout<<"Please,Input the number correct entry\n"; 
          cout<<"For the first number \n"; 
          cin>>number_bits; 
      } 

      if(number_bits<8){ 
         for(int k=1;k<=(8-number_bits);k++){ 
            number1[k]=0; 
         } 
      } 
      cout<<"Enter the bits as 1 or 0 from the most significant bit\n"; 
      for(int i=(9-number_bits);i<=8;i++){ 
         cout<<"Enter bit "<<i-(8-number_bits)<<" : "; 
         cin>>number1[i]; 
      } 

      cout<<"Input the number of bits you want to enter\n"; 
      cout<<"For the second number \n"; 
      cin>>number_bits; 


      if(number_bits<0||number_bits>8){ 
         cout<<"Error, the number of bits cannot be allowed to be \n"; 
         cout<<"greater than 8 or less than 0\n"; 
         cout<<"Please,Input the number correct entryr\n"; 
          cout<<"For the second number \n"; 
          cin>>number_bits; 
      } 

      if(number_bits<8){ 
         for(int k=1;k<=(8-number_bits);k++){ 
            number2[k]=0; 
         } 
      } 
       
      cout<<"Enter the bits as 1 or 0 from the most significant bit\n"; 
      for(i=(9-number_bits);i<=8;i++){ 
         cout<<"Enter bit "<<i-(8-number_bits)<<" : "; 
         cin>>number2[i]; 
      } 

      cout<<"THE FIRST NUMBER YOU HAVE ENTERED \n"; 
      cout<<"NUMBER ONE:  "; 
      for(int l=1;l<=8;l++){ 
         cout<<number1[l]; 
         cout<<" "; 
      } 
      cout<<endl; 
      cout<<"THE SECOND NUMBER YOU HAVE ENTERED \n"; 
      cout<<"NUMBER TWO: "; 
      for(l=1;l<=8;l++){ 
         cout<<number2[l]; 
         cout<<" "; 
      } 
      cout<<endl; 

       
   } 

   void check(int array[],int size){ 

      for(int b=1;b<=size;b++){ 
         array[b]; 
         } 
      for(b=1;b<=size;b++){ 
       if((array[b]!=0)&&(array[b]!=1)){ 
         cout<<"One of the entry is not 1 0r 0\n"; 
         cout<<"please update it, go back to A on the menu\n"; 
            break; 
       } 
       else{ 
          cout<<"The entries are in binary, ok\n"; 
          break; 
       } 
      } 

   } 

char uppercase(char ch){ 
   switch(ch){ 


case'a':return'A';break; 
case'b':return 'B';break; 
case'c':return 'C';break; 
case'd':return 'D';break; 
case'e':return 'E';break; 
case'f':return 'F';break; 
case'g':return 'G';break; 
case'h':return 'H';break; 
case'i':return 'I';break; 
case'j':return 'J';break; 
case'k':return 'K';break; 
case'l':return 'L';break; 
case'm':return 'M';break; 
case'n':return 'N';break; 
case'o':return 'O';break; 
case'p':return 'P';break; 
case'q':return 'Q';break; 
case'r':return 'R';break; 
case's':return 'S';break; 
case't':return 'T';break; 
case'u':return 'U';break; 
case'v':return 'V';break; 
case'w':return 'W';break; 
case'x':return 'X';break; 
case'y':return 'Y';break; 
     
default:return ch;break;                         
   } 
}       

void adding(int x[],int j,int y[],int k){ 
    carry[8]=0; 
   for(int g=8;g>=1;g--){ 
      if((x[g]+y[g]+carry[g])==0){ 
         sum[g]=0; 
         carry[g-1]=0; 
      } 
      if((x[g]+y[g]+carry[g])==1){ 
         sum[g]=1; 
         carry[g-1]=0; 
      } 
      if((x[g]+y[g]+carry[g])==2){ 
         sum[g]=0; 
         carry[g-1]=1; 
      } 
      if((x[g]+y[g]+carry[g])==3){ 
         sum[g]=1; 
         carry[g-1]=1; 
      } 
   } 
    
   cout<<"THE SUM OF NUMBERS ENTERED IS \n"; 
   for(int r=1;r<=8;r++){ 
      cout<<sum[r]; 
      cout<<" "; 
   } 
   if(carry[1]==1){ 
      cout<<"over flow of "; 
      cout<<carry[1]; 
      cout<<endl; 
   } 
} 


}; 

int main(){
clrscr();
      adder sum;
      sum.choice='Y';

      while(sum.choice=='Y'){
     cout<<"\n";
     cout<<" Choose from the following \n";
     cout<<" A: Input of two numbers in binary \n ";
     cout<<"B: Check the entry of numbers \n";
     cout<<" C: Adding the two numbers \n";
     cout<<" ";
     cin>>sum.choice;
     sum.choice=sum.uppercase(sum.choice);

      switch(sum.choice)
      {

    case 'A':
     sum.input();
     break;

    case 'B':
     cout<<"Checking the first number\n";
     sum.check(sum.number1,8);
     cout<<"Checking the second number\n";
        sum.check(sum.number2,8);
     break;
      case 'C':
     sum.adding(sum.number1,8,sum.number2,8);
     break;


    default: cout<<"Sorry, your selection is not right \a\n";break;
      }

     cout<<"\n";
      cout<<"Do you want to experiment some more [Y/N] ?\n";
      cin>>sum.choice;
     cout<<"\n";
      sum.choice=sum.uppercase(sum.choice);

      if(sum.choice=='N'){
     cout<<"END.......\n";
     cout<<endl;
      }
      clrscr();
      }

      return 0; 
} 
 

C++ Program to find all the combinations that you can make with one word




C++ Program to find all the combinations that you can make with one word example: "abc" -> 9 combinations -> abc - acb - bac - bca - etc...

#include <iostream.h>
#include <string.h>
// Program to display the all available
// unique combinations of a given string of any length.
#include <iomanip.h>
#include<conio.h>

typedef char string[80];

long fac(int getal)
//
{
  long faculteit = 1;

  for (; getal>1; getal--) faculteit*=getal;
  return faculteit;
} // long fac(int getal)

void swapchars(string tekst, int char1, int char2)
//
{
  char hulp;

  hulp=tekst[char2];
  tekst[char2]=tekst[char1];
  tekst[char1]=hulp;
} //

int findcombo(string tekst, int positie)
{
  int teller = 1;
  int nulpos = positie;
  long faculteit;
    string oldtekst;
  faculteit = fac(strlen(tekst)-positie);
  while (teller<=faculteit)
  {
    if (positie<strlen(tekst)-1) positie++;
    if (faculteit>2)
    {
      strcpy(oldtekst,tekst);
      teller+=findcombo(tekst,nulpos+1);
      strcpy(tekst,oldtekst);
      swapchars(tekst,nulpos,positie);
    }
    else
    {
      teller++;
      swapchars(tekst,nulpos,positie);
      cout << tekst << "\n";
    }
  }
  return faculteit;
} //
int main(void)
{
clrscr();
  string tekst;

  cout << "The entered words is : ";
  cin >> tekst;
  cout << endl<<"Word: " << tekst << "\n";
  cout << "Obtained combination: " << fac(strlen(tekst)) << "  ";

  findcombo(tekst,0);
  getch();
  return 0;
}
 

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More