Pages

Sunday, April 12, 2015

Code for Program of maintaining banking account information system using inheritance in C++

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

class account
{
  char cust_name[20];
  int  acc_no;
  char acc_type[20];
public:
   void get_accinfo()
   {
       cout<<"\n\nEnter Customer Name :- ";
       cin>>cust_name;
       cout<<"Enter Account Number :- ";
       cin>>acc_no;
       cout<<"Enter Account Type :- ";
       cin>>acc_type;
   }
   void display_accinfo()
   {
       cout<<"\n\nCustomer Name :- "<<cust_name;
       cout<<"\nAccount Number :- "<<acc_no;
       cout<<"\nAccount Type :- "<<acc_type;
   }
};

class cur_acct : public account
{
staticfloat balance;
  public:
    void disp_currbal()
    {
      cout<<"\nBalance :- "<<balance;
    }
    void deposit_currbal()
    {
      float deposit;
      cout<<"\nEnter amount to Deposit :- ";
      cin>>deposit;
      balance = balance + deposit;
    }
    void withdraw_currbal()
    {
      float penalty,withdraw;
      cout<<"\n\nBalance :- "<<balance;
      cout<<"\nEnter amount to be withdraw :-";
      cin>>withdraw;
      balance=balance-withdraw;
      if(balance < 500)
      {
      penalty=(500-balance)/10;
      balance=balance-penalty;
      cout<<"\nBalance after deducting penalty : "<<balance;
      }
      elseif(withdraw > balance)
      {
      cout<<"\n\nYou have to take permission for Bank Overdraft Facility\n";
      balance=balance+withdraw;
      }
      else
      cout<<"\nAfter Withdrawl your Balance revels : "<<balance;
     }
};

class sav_acct : public account
{
staticfloat savbal;
  public:
     void disp_savbal()
    {
      cout<<"\nBalance :- "<<savbal;
    }
    void deposit_savbal()
    {
      float deposit,interest;
      cout<<"\nEnter amount to Deposit :- ";
      cin>>deposit;
      savbal = savbal + deposit;
      interest=(savbal*2)/100;
      savbal=savbal+interest;
    }
    void withdraw_savbal()
    {
      float withdraw;
      cout<<"\nBalance :- "<<savbal;
      cout<<"\nEnter amount to be withdraw :-";
      cin>>withdraw;
      savbal=savbal-withdraw;
      if(withdraw > savbal)
      {
      cout<<"\n\nYou have to take permission for Bank Overdraft Facility\n";
      savbal=savbal+withdraw;
      }
      else
      cout<<"\nAfter Withdrawl your Balance revels : "<<savbal;
     }
};


float cur_acct :: balance;
float sav_acct  :: savbal;


void main()
{
 clrscr();
 cur_acct c1;
 sav_acct s1;

 cout<<"\nEnter S for saving customer and C for current a/c customer\n\n";
 char type;
 cin>>type;

 int choice;

   if(type=='s' || type=='S')
     {
       s1.get_accinfo();
       while(1)
       {
     clrscr();
     cout<<"\nChoose Your Choice\n";
     cout<<"1)   Deposit\n";
     cout<<"2)   Withdraw\n";
     cout<<"3)   Display Balance\n";
     cout<<"4)   Display with full Details\n";
     cout<<"5)   Exit\n";
     cout<<"6)   Choose Your choice:-";
     cin>>choice;
     switch(choice)
     {
       case 1 : s1.deposit_savbal();
            getch();
            break;
       case 2 : s1.withdraw_savbal();
            getch();
            break;
       case 3 : s1.disp_savbal();
            getch();
            break;
       case 4 : s1.display_accinfo();
            s1.disp_savbal();
            getch();
            break;
       case 5 : goto end;
       default: cout<<"\n\nEntered choice is invalid,\"TRY AGAIN\"";
     }
       }
     }
    else
     {
       {
       c1.get_accinfo();
       while(1)
       {
     cout<<"\nChoose Your Choice\n";
     cout<<"1)   Deposit\n";
     cout<<"2)   Withdraw\n";
     cout<<"3)   Display Balance\n";
     cout<<"4)   Display with full Details\n";
     cout<<"5)   Exit\n";
     cout<<"6)   Choose Your choice:-";
     cin>>choice;
     switch(choice)
     {
       case 1 : c1.deposit_currbal();
            getch();
            break;
       case 2 : c1.withdraw_currbal();
            getch();
            break;
       case 3 : c1.disp_currbal();
            getch();
            break;
       case 4 : c1.display_accinfo();
            c1.disp_currbal();
            getch();
            break;
       case 5 : goto end;
       default: cout<<"\n\nEntered choice is invalid,\"TRY AGAIN\"";
     }
       }
     }
end:
}
}


Friday, April 10, 2015

Converting Infix to Postfix using Stacks in C++


#include<iostream>
#include<conio.h>
#include<cstring>
#include<stdlib.h>
using namespace std;
const char size=100;
class stack
{
private:
                char data[size];
                int top;
public:  
                int topnum;
                bool isempty()
                {
                                return top==-1;
                }
                bool isfull()
                {
                                return top==size-1;
                }
                void push(char j)
                {
                                if(isfull())
                                {
                                                cout<<"cannot add new item "<<endl;
                                }
                                else
                                {
                                                top++;
                                                data[top]=j;
                                                topnum=top;
                                }
                }
                void pop(char &j)
                {
                                if (isempty())
                                {
                                                cout<<"stack full"<<endl;
                                }
                                else
                                {
                                                topnum=top;
                                                j=data[top];
                                                top--;
                                }
                }

                void display()
                {
                                cout<<"The Postfix Form Is : ";
                                for(int i=0;i<=top;i++)
                                {
                                                cout<<data[i];
                                }
                }
};

void main()
{
                stack a;
                stack b;
                char c;
                char infex[size];
                cout<<" Enter The  Infex Formula :";
        cin.get(infex,size);
       
        char ch;
        int lenght;
        lenght=strlen(infex);
        for(int i=0;i<lenght;i++)
        {
                if(infex[i]=='+'||infex[i]=='-'||infex[i]=='*'||infex[i]=='/'||infex[i]=='('||infex[i]==')')
                {
                        if(infex[i]=='*'||infex[i]=='/'||infex[i]=='(')
                                a.push(infex[i]);                                                                                                              
                        else if(infex[i]=='+'||infex[i]=='-')
                        {
                                if(a.topnum=='*'||a.topnum=='/')
                                {
                                        a.pop(ch);
                                       c=ch;
                                        while(ch!='('&& ch!=a.isempty())
                                        {
                                                b.push(ch);
                                                a.pop(ch);

                                        }
                                        a.push(infex[i]);
                                }
                                else
                                        a.push(infex[i]);
                                }
                        else if(infex[i]==')')
                        {
                                a.pop(ch);
                                c=ch;
                                while(c!='(')
                                {
                                        b.push(c);
                                        a.pop(ch);
                                        c=ch;
                                }
                        }
                        }
                else
                        b.push(infex[i]);
                }
        while(!a.isempty())
        {
                a.pop(ch);
               c=ch;
                b.push(c);    
        }
        b.display();
        cout<<endl;      
getch();
}

Creating a Dialog Box Dynamically in C#

public static int ShowDialog(string text, string caption)
        {
            Form prompt = new Form();
            prompt.Width = 500;
            prompt.Height = 100;
            prompt.Text = caption;
            Label textLabel = new Label() { Left = 50, Top=20, Text=text };

            NumericUpDown inputBox = new NumericUpDown () { Left = 50, Top=50, Width=400 };

            Button confirmation = new Button() { Text = "Ok", Left=350, Width=100, Top=70 };

            confirmation.Click += (sender, e) => { prompt.Close(); };
            prompt.Controls.Add(confirmation);
            prompt.Controls.Add(textLabel);
            prompt.Controls.Add(inputBox);
            prompt.ShowDialog();
            return (int)inputBox.Value;
        }

It can be tested by calling

int promptValue = Prompt.ShowDialog("Test", "123");



Saturday, April 4, 2015

Matrices Multiplication Using 2D Arrays In C++

#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
void main()
{
//note that for multiplication the columns of first matrix should be equal to rows of second matrix.

//rows1=rows of first matrix and col1=column of first matrix and vice versa.

int rows1,col1,rows2,col2;
int array1[50][50],array2[50][50],product[50][50];
cout<<"Enter number of rows forfirstmatrix:";
cin>>rows1;
cout<<"\n   Enter number of columns for first matrix : ";
cin>>col1;
cout<<"\n   Entering values in first matrix :-";
cout<<endl;
for(int i=0;i<rows1;i++)
{
for(int j=0;j<col1;j++)
{
cout<<"\n   Enter value : ";
cin>>array1[i][j];
}
}
cout<<"\n   First matrix is :";
cout<<endl<<endl;
//"rowsFm" means rows of first matrix, "colFm" means cloumns of first matrix and vice versa.
for(int rowsFm=0;rowsFm<rows1;rowsFm++)
{
for(int colFm=0;colFm<col1;colFm++)
{
cout<<"\t"<<array1[rowsFm][colFm];
}
cout<<endl<<endl;
}
cout<<"\n   Enter number of rows for second matrix : ";
cin>>rows2;
cout<<"\n   Enter number of columns for second matrix : ";
cin>>col2;
cout<<"\n   Entering values in second matrix :-";
cout<<endl;
for(int k=0;k<rows2;k++)
{
for(int l=0;l<col2;l++)
{
cout<<"\n   Enter value :  ";
cin>>array2[k][l];
}
}
cout<<"\n   Second matrix is :";
cout<<endl<<endl;
for(int rowsSm=0;rowsSm<rows2;rowsSm++)
{
for(int colSm=0;colSm<col2;colSm++)
{
cout<<"\t"<<array2[rowsSm][colSm];
}
cout<<endl<<endl;
}
cout<<"\n   The product of matrices is :-";
cout<<endl<<endl;
if(col1==rows2)
{
for(int a=0;a<rows1;a++)
{
for(int b=0;b<col2;b++)
{
product[a][b]=0;
for(int c=0;c<rows2;c++)
{
product[a][b]=product[a][b]+array1[a][c]*array2[c][b];
}
}
}
for(int d=0;d<rows1;d++)
{
for(int e=0;e<col2;e++)
{
cout<<"\t"<<product[d][e];
}
cout<<endl<<endl;
}
}
else 
{
cout<<"\n   Product is not possible.";
}
getch();
}

Friday, April 3, 2015

How To Add Two complex Numbers Using C++ class

#include <iostream>
#include <conio.h>
using namespace std;
class complex
{
public :
int real, img;
};
int main()
{
complex a, b, c;
cout << "Enter a and b where a + ib is the first complex number.";

 cout << "\na = ";
 cin >> a.real;
cout << "b = "; cin >> a.img;
cout << "Enter c and d where c + id is the second complex number.";

 cout << "\nc = "; 
 cin >> b.real;
cout << "d = ";

 cin >> b.img;
c.real = a.real + b.real;
c.img = a.img + b.img;
if ( c.img >= 0 )
cout << "Sum of two complex numbers = " << c.real << " + " << c.img << "i"; 

 else
 cout << "Sum of two complex numbers = " << c.real << " " << c.img << "i";
 return 0; 
}