Wednesday, February 13, 2013

Project on ATM machine working in CPP

/*program of ATM machine working....*/

#include<string.h>
#include<iostream.h>
#include<conio.h>
class Atm               //classname......//
{
int choice,i;
float b,c;
char str[7];
public:
void get();              //function declaration.....//
};
void Atm::get()
{
cout<<"\tEnter Your Password: ";         //ATM  password(ABCDE)...//
for(i=0;i<=4;i++)
{
str[i]=getch();
cout<<"*";
}
str[i]='\0';
if(strcmp(str,"ABCDE")==0)
{
float a=30000;                         //ATM's front page....//
cout<<endl<<endl<<"\t** WELCOME TO SBI **"<<endl<<endl;
cout<<" \tHello Mr.Chinmay Mahajan\t"<<endl<<endl<<endl;
cout<<"\t1.Information.\t2.Balance enquiry.";
cout<<endl<<endl<<"\t3.Withdrawal\t4.Quit";
cout<<endl<<endl<<endl<<"\t-->please select your choice:";
cin>>choice;
switch(choice)
{
case 1:
cout<<endl<<endl<<"\tName-Chinmay Mahajan"<<endl<<endl;
cout<<"\t Account no.-0181cs081059"<<endl<<endl<<"\tBranch name-Bhopal";
cout<<endl<<endl<<"\tYour main balance is:"<<a<<endl<<endl<<endl<<"\t\tThank U";
break;
case 2:
cout<<endl<<"\tYour balance is: "<<a<<endl<<endl<<endl<<"\t  Thank U  ";
break;
case 3:
cout<<endl<<"\t your balance is: "<<a<<endl;
cout<<endl<<"\t Please enter your amount:";
cin>>b;
if(b>a)
{
cout<<endl<<endl<<"\tyou have not sufficient balance";
goto out;
}
else
{
c=a-b;
cout<<endl<<endl<<"\tyou have withdrawn Rs. "<<b;
cout<<endl<<endl<<"\tYour balance now:"<<c<<endl<<endl<<"\tThank U";
break;
}
out:
default:
cout<<endl<<endl<<"\tThank U";
}
}
else
{
cout<<endl<<endl<<"\tPassword incorrect";
cout<<endl<<endl<<"\tThank U";
 }
}
void main()
{
clrscr();
Atm A;
A.get();
getch();
}

Thursday, January 31, 2013

ADDITION OF TWO NUMBERS IN C++ USING FRIEND FUNCTION

/* FRIEND FUNCTION DEMO */


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

class two;
class one
{
private:int data1;
public: void setdata(int init)
{
data1=init;
}
friend int add_both(one a,two b);

};//class

class two
{
private: int data2;
public:
void setdata(int init)
{
data2=init;
}
friend int add_both(one a,two b);
};
int add_both(one a,two b)
{
return a.data1+b.data2;
}
void main()
{
one a;
two b;

int i,j;
clrscr();
cout<<"Enter the value of a & b";
cin>>i>>j;

a.setdata(i);
b.setdata(j);
cout<<"sum of one & two :"<<add_both(a,b);
getch();
}

Monday, October 1, 2012

Star Pattern in C language


#include<stdio.h>
#include<conio.h>
void main()
{
int b=2,c=1,i,p,a;
clrscr();
for(i=0;i<3;i++)
{
for(a=0;a<b;a++)
{
printf(" ");
}//for spacing
for(p=0;p<c;p++)
{
printf(" *");
}//for printing
for(a=0;a<b;a++)
{
printf(" ");
}//for spacing
for(p=0;p<c;p++)
{
printf(" *");
}//for printing
for(a=0;a<b;a++)
{
printf(" ");
}//for spacing
printf("\n");
b--;
c++;

}//outer for loop
getch();
}//eofm

Wednesday, August 29, 2012

c program to reverse a number

#include <stdio.h>
 
main()
{
   int n, reverse = 0;
 
   printf("Enter a number to reverse\n");
   scanf("%d",&n);
 
   while (n != 0)
   {
      reverse = reverse * 10;
      reverse = reverse + n%10;
      n = n/10;
   }
 
   printf("Reverse of entered number is = %d\n", reverse);
 
   return 0;
}

Decimal to binary conversion

#include <stdio.h>
 
int main()
{
  int n, c, k;
 
  printf("Enter an integer in decimal number system\n");
  scanf("%d", &n);
 
  printf("%d in binary number system is:\n", n);
 
  for (c = 31; c >= 0; c--)
  {
    k = n >> c;
 
    if (k & 1)
      printf("1");
    else
      printf("0");
  }
 
  printf("\n");
 
  return 0;
}

Palindrome number program c

Palindrome number algorithm

1. Get the number from user.
2. Reverse it.
3. Compare it with the number entered by the user.
4. If both are same then print palindrome number
5. Else print not a palindrome number.
 -----------------------------------------------------------
#include<stdio.h>
 
main()
{
   int n, reverse = 0, temp;
 
   printf("Enter a number to check if it is a palindrome or not\n");
   scanf("%d",&n);
 
   temp = n;
 
   while( temp != 0 )
   {
      reverse = reverse * 10;
      reverse = reverse + temp%10;
      temp = temp/10;
   }
 
   if ( n == reverse )
      printf("%d is a palindrome number.\n", n);
   else
      printf("%d is not a palindrome number.\n", n);
 
   return 0;
}