Social Icons

banner image

Applications of c++ in diffret aspects like for result ,in bank,in fun game

Applications of c++ in different aspects like for result ,in bank,in fun game

ALGORITHM C++:-

#include <iostream>   
#include <algorithm>   
#include <vector>
#include <conio.h>     
using namespace std;
int main ()
{
  int arr[] = { 200, 100, 300 ,400, 50, 150, 246 };
  int prr[] = { 11, 22, 33, 44, 55, 66, 77 };
  int * p;
 
  //find algorithm
  cout<<"\n\t****FIND*****"<<endl<<endl;
  p = find (arr,arr+7,300);
  ++p;
  cout << "The element after 300 is " << *p <<endl;
 
  //copy algorithm
  cout<<"\n\t**** COPY *****"<<endl<<endl;
  vector <int> v(7);
  copy(arr,arr+7,v.begin());
  vector <int>::iterator it;
  for(it=v.begin(); it!=v.end(); ++it)
      cout << "The element is " << *it <<endl;
     
  //sorting algorithm
  cout<<"\n\t**** SORT *****"<<endl<<endl;
  sort(v.begin(),v.end());
  for(it=v.begin(); it!=v.end(); ++it)
      cout << "The element is " << *it <<endl;
    
  //merging algorithm
  cout<<"\n\t**** MERGING arr & 3 element of prr *****"<<endl<<endl;
  vector<int> v1(10);
  merge(arr,arr+7,prr,prr+3,v1.begin());
  vector<int>::iterator itt;
  for(itt=v1.begin(); itt!=v1.end(); ++itt)
      cout << "The element is " << *itt <<endl;
  cout<<"\nPROGRAMMING @ C#ODE STUDIO";
  getch();
  return 0;
}

BUBBLE SORT GENERIC METHOD:-

#include"conio.h"
#include"iostream"
using namespace std;
template<typename data_type>
int sort(data_type *d,int size)
{
    int i,j;
    data_type a;
    for(i=1;i<size;i++)
        for(j=size-1;j>=i;j--)
        {
            if(d[j-1]>d[j])
            {
                a=d[j-1];
                d[j-1]=d[j];
                d[j]=a;
            }
        }
}
int main()
{
    int g[10];
    double h[10];
    int i;
    cout<<"\nInsert Integer Type No. : ";
    for(i=0;i<10;i++)
    {
        cout<<"\nEnter "<<i<<" No. :";
        cin>>g[i];
    }
    cout<<"\nInsert Float Type No. : ";
    for(i=0;i<10;i++)
    {
        cout<<"\nEnter "<<i<<" No. :";
        cin>>h[i];
    }
    sort(g,10);
    sort(h,10);
    cout<<"\nOutput after sorting integer values"<<endl;
    for(i=0;i<10;i++)
    {
        cout<<"\nInt "<<i+1<<" No. :";
        cout<<g[i];
    }
    cout<<"\nOutput after sorting floating values"<<endl;
    for(i=0;i<10;i++)
    {
        cout<<"\nFloat "<<i+1<<" No. :";
        cout<<h[i];
    }
    cout<<"\n\nProgramming @ C#ODE STUDIO";
    getch();
    return 0;
}



CH 1.1:-

#include<iostream>
#include<conio.h>
using namespace std;
int main ()
{
      int k;
      k=10;
      if(k < 15)
      {
            cout << " //...\\";
            k++;
     
      }
      cout <<"\n 2k is "<<2*k--;
      getch ();

}

FILE HANDLING IN C++:-

#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
struct account_query
{
    char account_number[20];
    char firstName[10];
    char lastName[10];
    float total_Balance;
    void read_data();
    void show_data();
    void write_rec();
    void read_rec();
    void search_rec();
    void edit_rec();
    void delete_rec();
};
void account_query::read_data()
{
    cout<<"\nEnter Account Number: ";
    cin>>account_number;
    cout<<"Enter First Name: ";
    cin>>firstName;
    cout<<"Enter Last Name: ";
    cin>>lastName;
    cout<<"Enter Balance: ";
    cin>>total_Balance;
    cout<<endl;
}
void account_query::show_data()
{
    cout<<"Account Number: "<<account_number<<endl;
    cout<<"First Name: "<<firstName<<endl;
    cout<<"Last Name: "<<lastName<<endl;
    cout<<"Current Balance: Rs.  "<<total_Balance<<endl;
    cout<<"-------------------------------"<<endl;
}
void account_query::write_rec()
{
    ofstream outfile;
    outfile.open("record.bank", ios::binary|ios::app);
    read_data();
    outfile.write(reinterpret_cast<char *>(this), sizeof(*this));
    outfile.close();
}
void account_query::read_rec()
{
    ifstream infile;
    infile.open("record.bank", ios::binary);
    if(!infile)
    {
        cout<<"Error in Opening! File Not Found!!"<<endl;
        return;
    }
    cout<<"\n****Data from file****"<<endl;
    while(!infile.eof())
    {
        if(infile.read(reinterpret_cast<char*>(this), sizeof(*this))>0)
        {
            show_data();
        }
    }
    infile.close();
}
void account_query::search_rec()
{
    int n;
    ifstream infile;
    infile.open("record.bank", ios::binary);
    if(!infile)
    {
        cout<<"\nError in opening! File Not Found!!"<<endl;
        return;
    }
    infile.seekg(0,ios::end);
    int count = infile.tellg()/sizeof(*this);
    cout<<"\n There are "<<count<<" record in the file";
    cout<<"\n Enter Record Number to Search: ";
    cin>>n;
    infile.seekg((n-1)*sizeof(*this));
    infile.read(reinterpret_cast<char*>(this), sizeof(*this));
    show_data();
}
void account_query::edit_rec()
{
    int n;
    fstream iofile;
    iofile.open("record.bank", ios::in|ios::binary);
    if(!iofile)
    {
        cout<<"\nError in opening! File Not Found!!"<<endl;
        return;
    }
    iofile.seekg(0, ios::end);
    int count = iofile.tellg()/sizeof(*this);
    cout<<"\n There are "<<count<<" record in the file";
    cout<<"\n Enter Record Number to edit: ";
    cin>>n;
    iofile.seekg((n-1)*sizeof(*this));
    iofile.read(reinterpret_cast<char*>(this), sizeof(*this));
    cout<<"Record "<<n<<" has following data"<<endl;
    show_data();
    iofile.close();
    iofile.open("record.bank", ios::out|ios::in|ios::binary);
    iofile.seekp((n-1)*sizeof(*this));
    cout<<"\nEnter data to Modify "<<endl;
    read_data();
    iofile.write(reinterpret_cast<char*>(this), sizeof(*this));
}
void account_query::delete_rec()
{
    int n;
    ifstream infile;
    infile.open("record.bank", ios::binary);
    if(!infile)
    {
        cout<<"\nError in opening! File Not Found!!"<<endl;
        return;
    }
    infile.seekg(0,ios::end);
    int count = infile.tellg()/sizeof(*this);
    cout<<"\n There are "<<count<<" record in the file";
    cout<<"\n Enter Record Number to Delete: ";
    cin>>n;
    fstream tmpfile;
    tmpfile.open("tmpfile.bank", ios::out|ios::binary);
    infile.seekg(0);
    for(int i=0; i<count; i++)
    {
        infile.read(reinterpret_cast<char*>(this),sizeof(*this));
        if(i==(n-1))
            continue;
        tmpfile.write(reinterpret_cast<char*>(this), sizeof(*this));
    }
    infile.close();
    tmpfile.close();
    remove("record.bank");
    rename("tmpfile.bank", "record.bank");
}
int main()
{
    account_query A;
    int choice;
    cout<<"***Acount Information System***"<<endl;
    while(true)
    {
        cout<<"Select one option below ";
        cout<<"\n\t1-->Add record to file";
        cout<<"\n\t2-->Show record from file";
        cout<<"\n\t3-->Search Record from file";
        cout<<"\n\t4-->Update Record";
        cout<<"\n\t5-->Delete Record";
        cout<<"\n\t6-->Quit";
        cout<<"\nEnter your choice: ";
        cin>>choice;
        switch(choice)
        {
        case 1:
            A.write_rec();
            break;
        case 2:
            A.read_rec();
            break;
        case 3:
            A.search_rec();
            break;
        case 4:
            A.edit_rec();
            break;
        case 5:
            A.delete_rec();
            break;
        case 6:
            exit(0);
            break;
        default:
            cout<<"\nEnter corret choice";
            exit(0);
        }
    }
    system("pause");
    return 0;
}

HAPPY HEART:-

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    double x, y, size=10;
    char ch=3;
    string message(" Happy Valentine's Day ");
    int print_line = 4;

    if (message.length() % 2 != 0) message += " ";

    for (x=0;x<size;x++)
    {
        for (y=0;y<=4*size;y++)
        {
            double dist1 = sqrt( pow(x-size,2) + pow(y-size,2) );
            double dist2 = sqrt( pow(x-size,2) + pow(y-3*size,2) );

            if (dist1 < size + 0.5 || dist2 < size + 0.5 ) {
                cout << ch;
            }
            else cout << " ";
        }
        cout<<"\n";
    }

    for (x=1;x<2*size;x++)
    {
        for(y=0;y<x;y++) cout << " ";

        for (y=0; y<4*size + 1 - 2*x; y++)
        {
            if (x >= print_line - 1 && x <= print_line + 1) {
                int idx = y - (4*size - 2*x - message.length()) / 2;
                if (idx < message.length() && idx >= 0) {
                    if (x == print_line) cout<<message[idx];
                    else cout << " ";
                }
                else cout << ch;
            }
            else cout << ch;
        }
        cout<<endl;
    }
    return 0;
}


HEART:-

#include <stdio.h>
#include <math.h>
int main()
{
    int x, y, size=8;
    for (x=0; x<size; x++)
    {
        for (y=0; y<=4*size; y++)
        {
            double dist1 = sqrt( pow(x-size,2) + pow(y-size,2) );
            double dist2 = sqrt( pow(x-size,2) + pow(y-3*size,2) );
            if (dist1 < size + 0.5 || dist2 < size + 0.5 )
                 printf("%c",97);
            else
                 printf(" ");
        }
        printf("\n");
    }
    for (x = 1; x <= 2*size; x++)
    {
        for (y=0; y<x; y++)
        printf(" ");
        for (y=0; y<4*size + 1 - 2*x; y++)
            printf("%c",97);
        printf("\n");
    }

    return 0; 
}

INDIA MAP:-

#include<iostream>
using namespace std;
int main (void) {
    int a=10, b=0, c=10;
    char* bits ="TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBLOFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm SOn TNn ULo0ULo#ULo-WHq!WFs XDt!";
    a = bits[b];
    while (a != 0) {
        a = bits[b];
        b++;
        while (a > 64) {
            a--;
            if (++c == 'Z') {
                c /= 9;
                putchar(c);
            } else {
                putchar(33 ^ (b & 0x01));
            }
        }
    }
  
system("pause");
}


JOIN TWO CLASS:-

#include<iostream>
#include<conio.h>
#include<string>
using std::string;
int main()
{
       string f,s2;
       char a[3];
       int c,n,l,q,w,e;
    cout << "Enter String: ";
       getline(cin,f);
     cout<< f <<endl;
     cout<<"\nEnter no. of character you want to skip: ";
     cin>>c;
     s2=f.substr(c);
     n=s2.empty();
    if(n==0)
    {
        cout<<s2;
         cout<<"\nSize of string after skipping chars:"<<s2.size();
         cout<<"\nLength of string :”<<f.length()";
         cout<<"\nEnter 3 character to insert in s2:”";
         cin>>a;
        cout<<"\nEnter position from which you overwrite:”";
         cin>>l;
         cout<<"\nS2 after inserting at 2nd position:”<<s2.insert(l,a)"
             ;
         cout<<"\nNo. of element you want to  delete:”";
         cin>>q;
         cout<<"\nPosition of element from where you want to  delete:”";
         cin>>w;
         cout<<"\nAfter <erase> fn.:”"<<s2.erase(w,q);
        
    }
     cout<<"\n\nPROGRAMMING @C#ODE STUDIO";
     getch();
}

MATRIX:-

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    try
    {
        int a[10][10],b[10][10],c[10][10],m,n,o,p,i,j;
        line:
            cout<<"Enter number of rows of A: ";
        cin>>m;
        cout<<"Enter number of coloumns of A: ";
        cin>>n;
        cout<<endl<<"Enter elements of matrix A: "<<endl;
        for(i=0;i<m;i++)
           {
            for(j=0;j<n;j++)
            {
                cout<<"Enter element a"<<i+1<<j+1<<": ";
                cin>>a[i][j];
            }
        }
        cout<<endl<<"Enter number of rows of B: ";
        cin>>o;
        cout<<"Enter number of coloumns of B: ";
        cin>>p;
        cout<<endl<<"Enter elements of matrix B: "<<endl;
        for(i=0;i<o;i++)
        {
            for(j=0;j<p;j++)
            {
                cout<<"Enter element b"<<i+1<<j+1<<": ";
                cin>>b[i][j];
            }
        }
        cout<<endl<<"Displaying Matrix A: "<<endl<<endl;
        for(i=0;i<m;i++)
        {
            for(j=0;j<n;j++)
            {
                cout<<a[i][j]<<" ";
            }
            cout<<endl<<endl;
           }
           cout<<endl<<"Displaying Matrix B: "<<endl<<endl;
        for(i=0;i<o;i++)
        {
            for(j=0;j<p;j++)
            {
                cout<<b[i][j]<<" ";
            }
               cout<<endl<<endl;
           }
           if(m!=p || n!=o)
                   throw m;
           for(i=0;i<m;i++)
           {
              for(j=0;j<p;j++)
            {
                c[i][j]=0;
                 for(int k=0;k<n;k++)
                 {
                    c[i][j]=c[i][j]+a[i][k]*b[k][j];
                 }
              }
        }
        cout<<endl<<"Matrix A * Matrix B = Matrix C: "<<endl<<endl;
        for(i=0;i<m;i++)
        {
            for(j=0;j<p;j++)
            {
                cout<<c[i][j]<<" ";
             }
            cout<<endl<<endl;
         }
      }
      catch(int x)
      {
          cout<<"\n\nMULTIPLICATION NOT POSSIBLE : DIMENSION OF MATRICES ARE NOT SAME";
    }
    cout<<"\n\nProgramming @C#ODE STUDIO";
    getch();
}

NESTED STRUCTURE:-



#include<conio.h>
#include<iostream>
using namespace std;
struct bookout
{
       char name[25];
       int price;
       int pages;
       struct bookin
       {
              char isbn[10];
              char author[25];
              int pub_yr;
       }b;
};
int main()
{
    struct bookout a;
    cout<<"\nBOOK DESCRIPTION :)\n";
    cout<<"\nNAME OF BOOK : ";
    cin>>a.name;
    cout<<"\nPRICE : ";
    cin>>a.price;
    cout<<"\nPAGES : ";
    cin>>a.pages;
    cout<<"\nISBN NO. : ";
    cin>>a.b.isbn;
    cout<<"\nAUTHOR : ";
    cin>>a.b.author;
    cout<<"\nPUBLICATION YEAR : ";
    cin>>a.b.pub_yr;
    cout<<"\n\nBOOK DESCRIPTION output :) —- \n\n"
        <<"\nNAME:\t"<<a.name
        <<"\nPRICE:\t"<<a.price
        <<"\nPAGES:\t"<<a.pages
        <<"\nISBN NO.:\t"<<a.b.isbn
        <<"\nAUTHOR:\t"<<a.b.author
        <<"\nPUBLICATION YEAR:\t"<<a.b.pub_yr;
    cout<<"\n\nPROGRAMMING @ C#ODE STUDIO";
    getch();
}

NULL POINTEER:-

#include<stdio.h>
#include<conio.h>
int main()
{
int a[10],b[10],i,sum;

printf("enter the 5 element of a");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
printf("enter the second 5 element");
for(i=0;i<5;i++)
scanf("%d",&b[i]);
for(i=0;i<5;i++)
sum=sum+a[i]*b[i];
printf("%d",sum);
getch();
}

OVERLOADING:-

#include<iostream>
#include<conio.h>
using namespace std;
class inc
{
    private:
        int count ;
    public:
        inc(int x)
        {
            count=x;
        }
        inc()
        {
            count=0;
        }
        friend istream & operator >>(istream &ip, inc &i)
        {
            ip>>i.count;
            return ip;
        }
        friend ostream & operator <<(ostream &op, inc &j)
        {
            op<<j.count;
            return op;
        }
};
int main()
{
    inc obj1(8),obj2,obj3;
    cout<<"\nENTER THE VALUE IN OBJ3 : ";
    cin >> obj3;
    cout<<"\nVALUE IN OBJ1 : ";
    cout << obj1;
    cout<<"\nVALUE IN OBJ2 : ";
    cout<< obj2;
    cout<<"\nVALUE IN OBJ3 : ";
    cout << obj3;
    cout<<"\n\nPROGRAMMING @C#ODE STUDIO";
    getch();
}

PATTERN PRINT:-


 #include<iostream>
 using namespace std;
int main()
{
int i,j,k=0,c=0,l=0;
for(i=1 ; i<=5 ; i++)
{
c=i;
k='a';
for( j=1; j<=i; j++ )
{
c=i+l;
printf("%d",c+1-i);
c=c+k;
k--;
l++;
}
cout<<"\n";
}
}

STACK:-

#include<iostream>
#include<conio.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int top = 10;
struct node
{
char ch;
struct node *next;
struct node *prev;
} *stack[11];
typedef struct node node;
void push(node *str)
{
if (top <= 0)
printf("Stack is Full ");
else
{
stack[top] = str;
top--;
}
}
node *pop()
{
node *exp;
if (top >= 10)
printf("Stack is Empty ");
else
exp = stack[++top];
return exp;
}
void convert(char exp[])
{
node *op1, *op2;
node *temp;
int i;
for (i=0;exp[i]!='\0';i++)
if (exp[i] >= 'a'&& exp[i] <= 'z'|| exp[i] >= 'A' && exp[i] <= 'Z')
{
temp = (node*)malloc(sizeof(node));
temp->ch = exp[i];
temp->next = NULL;
temp->prev = NULL;
push(temp);
}
else if (exp[i] == '+' || exp[i] == '-' || exp[i] == '*' || exp[i] == '/' ||
exp[i] == '^')
{
op1 = pop();
op2 = pop();
temp = (node*)malloc(sizeof(node));
temp->ch = exp[i];
temp->next = op1;
temp->prev = op2;
push(temp);
}
}
void display(node *temp)
{
if (temp != NULL)
{
display(temp->prev);
printf("%c", temp->ch);
display(temp->next);
}
}
int main()
{
char exp[50];

printf("Enter the postfix expression :");
scanf("%s", exp);
convert(exp);
printf("\nThe Equivalant Infix expression is:");
display(pop());
printf("\n\n");
getch();
}


Applications of c++ in diffret aspects like for result ,in bank,in fun game Applications of c++ in diffret aspects like for result ,in bank,in fun game Reviewed by Marketing Thrills on September 16, 2015 Rating: 5

No comments:

Airtel Hackaton 2017

Powered by Blogger.