Search This Blog

Sunday 21 July 2013

C++ Programs


C++ Programs

#include<iostream.h>
#include<conio.h>
class A
{
    int a;
    public:
    void a_read()
    {
        cout<<"Enter a value"<<endl;
        cin>>a;
    }
    void a_display()
    {
        cout<<"The a value is\t"<<a<<endl;
    }
};
class B:public A
{
    int b;
    public:
    void b_read()
    {
        cout<<"Enter b value"<<endl;
        cin>>b;
    }
    void b_display()
    {
        cout<<"The b value is\t"<<b<<endl;
    }
};
class C:public A
{
    int c;
    public:
    void c_read()
    {
        cout<<"Enter c value"<<endl;
        cin>>c;
    }
    void c_display()
    {
        cout<<"The c value is\t"<<c<<endl;
    }
};
class D:public B,public C
{
    int d;
    public:
    void d_read()
    {
        cout<<"Enter d value"<<endl;
        cin>>d;
    }
    void d_display()
    {
        cout<<"The d value is\t"<<d<<endl;
    }
};
void main()
{
    D co;
    clrscr();
    co.a_read();
    co.b_read();
    co.c_read();
    co.d_read();
    co.a_display();
    co.b_display();
    co.c_display();
    co.d_display();
    getch();

}

=====================================================================
#include<iostream.h>
#include<conio.h>
class complex
{
     int real;
     int img;
     public:
     void read()
     {
     cout<<"Enter real and imaginary parts of the complex number"<<endl;
     cin>>real>>img;
     }
     void display()
     {
        cout<<real;
        if(img<0)
        cout<<"\t-i"<<-(img)<<endl;
        else
        cout<<"\t+i"<<img<<endl;
     }
     complex operator+(complex co)
     {
        complex temp;
        temp.real=real+co.real;
        temp.img=img+co.img;
        return temp;
     }
     friend complex operator-(complex co1,complex co2);
     friend int operator<(complex co1,complex co2);
};
complex operator-(complex co1,complex co2)
{
    complex temp;
    temp.real=co1.real-co2.real;
    temp.img=co1.img-co2.img;
    return temp;
}
int operator<(complex co1,complex co2)
{
    int r=0;
    if(co1.real<co2.real&&co1.img<co2.img)
        r=1;
    return r;
}
void main()
{
    complex co1,co2,res;
    clrscr();
    co1.read();
    co2.read();
    cout<<"First complex number\n\n"<<endl;
    co1.display();
    cout<<"Second complex number\t\t"<<endl;
    co2.display();
    cout<<"co1 co2 sum is\t\t"<<endl;
    res=co1+co2;
    res.display();
    cout<<"co1 co2 difference is \t\t"<<endl;
    res=co1-co2;
    res.display();
    if(co1<co2)
    cout<<"co1 is less than co2"<<endl;
    else
    cout<<"co1 is not less than co2"<<endl;
    getch();
}
=======================================================================
#include <iostream.h>
#include <conio.h>
class A
{
    public:
    A()
    {
        cout<<"Constructor"<<endl;
    }
    ~A()
    {
        cout<<"Destructor"<<endl;
    }
};
int main()
{
    clrscr();
    A ao1,ao2,ao3;
    getch();
}
=========================================================================
#include<iostream.h>
#include<conio.h>
class shape
{
    public:
    int a;
    int cf;
    virtual void display()=0;
    virtual void findac()=0;
};
class Rectangle:public shape
{
    int l;
    int b;
    public:
    void read()
    {
        cout<<"Enter the length and breadth of the rectangle"<<endl;
        cin>>l>>b;
    }
    void findac()
    {
        a=l*b;
        cf=2*(l+b);
    }
    void display()
    {
        cout<<"The area and circum frence of the rectangle\t"<<a
             <<"\tsq.cm\t"<<cf<<"\tsq.cm"<<endl;
    }
};
void main()
{
    Rectangle obj;
    clrscr();
    obj.read();
    obj.findac();
    obj.display();
    getch();

}
========================================================================
#include<iostream.h>
#include<conio.h>
struct complex
{
     int real;
     int img;
     void read()
     {
     cout<<"Enter real and imaginary parts of the complex number"<<endl;
     cin>>real>>img;
     }
     void display()
     {
        cout<<real;
        if(img<0)
        cout<<"\t-i"<<-(img)<<endl;
        else
        cout<<"\t+i"<<img<<endl;
     }
     complex operator+(complex co)
     {
        complex temp;
        temp.real=real+co.real;
        temp.img=img+co.img;
        return temp;
     }
     friend complex operator-(complex co1,complex co2);
     friend int operator<(complex co1,complex co2);
};
complex operator-(complex co1,complex co2)
{
    complex temp;
    temp.real=co1.real-co2.real;
    temp.img=co1.img-co2.img;
    return temp;
}
int operator<(complex co1,complex co2)
{
    int r=0;
    if(co1.real<co2.real&&co1.img<co2.img)
        r=1;
    return r;
}
void main()
{
    complex co1,co2,res;
    clrscr();
    co1.read();
    co2.read();
    cout<<"First complex number\n\n"<<endl;
    co1.display();
    cout<<"Second complex number\t\t"<<endl;
    co2.display();
    cout<<"co1 co2 sum is\t\t"<<endl;
    res=co1+co2;
    res.display();
    cout<<"co1 co2 difference is \t\t"<<endl;
    res=co1-co2;
    res.display();
    if(co1<co2)
    cout<<"co1 is less than co2"<<endl;
    else
    cout<<"co1 is not less than co2"<<endl;
    getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class Address
{
    int hno;
    char city[100];
    char dist[100];
    int pin;
    public:
    //default constructor function
    Address()
    {
        hno=0;
        strcpy(city,"hyd");
        strcpy(dist,"rr");
        pin=123;
    }
    //parametrized constructor
    Address(int h,char *ci,char *di,int p)
    {
        hno=h;
        strcpy(city,ci);
        strcpy(dist,di);
        pin=p;
    }
    void a_display()
    {
        cout<<"\t*******Address Information**********\n\tH.no\t"
        <<hno<<"\n\tCity\t"<<city<<"\n\tDistrict\t"<<dist
        <<"\n\tPin code\t"<<pin<<endl;
    }
};
void main()
{
    Address ao1,ao2(123,"bombay","vidharba",222),ao3(45,"madras","tamilnadu",999);
    clrscr();
    ao1.a_display();
    ao2.a_display();
    ao3.a_display();
    getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
class A
{
    public:
    A()
    {
        cout<<"A constructor"<<endl;
    }
    ~A()
    {
        cout<<"A Destructor"<<endl;
    }
};
class B:public A
{
    public:
    B():A()
    {
        cout<<"B construcotr"<<endl;
    }
    ~B()
    {
        cout<<"B Destructor"<<endl;
    }
};
class C:public B
{
    public:
    C():B()
    {
        cout<<"C constructor"<<endl;
    }
    ~C()
    {
        cout<<"C Destructor"<<endl;
    }
};
void main()
{
    clrscr();
    C co;
    getch();

}
========================================================================
#include<iostream.h>
#include<conio.h>
class list
{
    int *ptr;
    int n;
    public:
    //dynamic constructor function declarations
    list();
    list(int n);
    list(list &ref);
    ~list()
    {
        cout<<"Destructor executed"<<endl;
        delete(ptr);
    }
    void read();
    void display();
};
//dynamic constructor function implementions
list::list()
{
    int i;
    ptr=new int[10];
    for(i=0;i<10;i++)
    *(ptr+i)=0;
    n=10;
}
list::list(int size)
{
    int i;
    ptr=new int[size];
    for(i=0;i<size;i++)
    *(ptr+i)=0;
    n=size;
}
list::list(list &ref)
{
    int i;
    ptr=new int[ref.n];
    for(i=0;i<ref.n;i++)
    *(ptr+i)=*(ref.ptr+i);
    n=size;
}
void read()
{
    cout<<"Enter list elements"<<endl;
    for(int i=0;i<n;i++)
    cin>>*(ptr+i);
}
void list::display()
{
    int i;
    for(i=0;i<n;i++)
    cout<<"\t"<<*(ptr+i);
}
void main()
{
    int n1;
    clrscr();
    cout<<"Enter the list size"<<endl;
    cin>>n1;

    list lo1(n1);
    lo1.read();
    cout<<"\nFirst object list contents"<<endl;
    lo1.display();
    list lo2=lo1;
    cout<<"\n\nSecond object list contents"<<endl;
    lo2.display();
    getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
class A
{
    int a;
    public:
    void a_read()
    {
        cout<<"Enter a value"<<endl;
        cin>>a;
    }
    void a_display()
    {
        cout<<"The a value is\t"<<a<<endl;
    }
};
class B:public A
{
    int b;
    public:
    void b_read()
    {
        cout<<"Enter b value"<<endl;
        cin>>b;
    }
    void b_display()
    {
        cout<<"The b value is\t"<<b<<endl;
    }
};
void main()
{
    B ob;
    clrscr();
    /*c++ allows to keep sub class object pointer
    in Base class pointer variable ,but it lets to access
    only base class functionalities .It also clled compile time
    poly morphism.*/
    A *aptr=&ob;
    aptr->a_read();
    aptr->a_display();
    getch();
}
=======================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
    int mon[]={31,28,31,30,31,30,31,31,30,31,30,31};
    int i,odd=0,d,m,y,ly;
    clrscr();
    cout<<"Enter day month and year"<<endl;
    cin>>d>>m>>y;
    if(y%4==0)
    mon[1]=29;

    y-=1;

    while(y>=400)
    y-=400;
    while(y>=100)
    {
        odd+=5;
        y-=100;
    }
    if(y>0)
    {
        ly=y/4;
        y-=ly;
        odd+=ly*2+y;
    }
    for(i=0;i<m-1;i++)
    odd+=mon[i];
    odd+=d;
    odd%=7;
    switch(odd)
    {
        case 0:
            cout<<"SUNDAY"<<endl;
            break;

        case 1:
            cout<<"MONDAY"<<endl;
            break;
        case 2:
            cout<<"TUSDAY"<<endl;
            break;
        case 3:
            cout<<"WEDNESDAY"<<endl;
            break;
        case 4:
            cout<<"THRUSDAY"<<endl;
            break;
        case 5:
            cout<<"FRIDAY"<<endl;
            break;
        case 6:
            cout<<"SATURDAY"<<endl;
            break;
    }
    getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
class Rectangle;
class Shape
{
    float a;
    float cf;
    friend class Rectangle;
};
class Rectangle
{
    float l;
    float b;
    public:
    void read()
    {
        cout<<"Enter the legth and breadth of the rectangle"<<endl;
        cin>>l>>b;
    }
    Shape findAC(Shape obj)
    {
        obj.a=l*b;
        obj.cf=2*(l+b);
        return obj;
    }
    void display(Shape obj)
    {
        cout<<"Length\t:"<<l<<"\tcm\nBreadth\t:"<<b
            <<"\tcm\nArea\t:"<<obj.a<<"\tsq.cm\nCircumfrance\t:"
            <<obj.cf<<"\tsq.cm"<<endl;
    }

};
void main()
{
    Rectangle robj;
    Shape sobj;
    clrscr();
    robj.read();
    sobj=robj.findAC(sobj);
    robj.display(sobj);
    getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
class A
{
    public:
    int a;
    void read()
    {
        cout<<"Enter the a value"<<endl;
        cin>>a;
    }
    void display()
    {
        cout<<"The a value is\t"<<a<<endl;
    }
};
void main()
{
    A ao;
    clrscr();
    ao.read();
    int A::*m1=&A::a;
    cout<<ao.*m1<<endl;
    void (A::*f)()=&A::display;
    (ao.*f)();
    getch();
}
/*
    local classes:-

    we can define classes inside function or block.
    That are called local classes.

    The following are the restrictions

    1.local classes can access global variables with scope resolution
    operator.

    2.These can access static variables which are
    declared inside the function.

    3.C++ doest not allows to access local variables of the
    function inside classes.

    4.C++ doest not allows to declare static data members inside
    the local classes.

    5.Enclosing functions can not access private members of the
    local classes.

    syntax:-

    returntype functionname(type arg1,type arg2,.....)
    {
        stmt1;
        stmt2;

        -----
        class classname
        {
            type member1;
            type member2;
            ------------
            ------------
            public:
            returntype mfunctionname(type arg1,type arg2,.....)
            {
            stmt1;
            stmt2;
            -----
            -----
            }
        };
        classname obj1,obj2........;
    }
*/
========================================================================
#include<iostream.h>
#include<conio.h>
class figure
{
    protected:
    int a;
    public:
    virtual void read(){};
    virtual void display()=0;
};
class Rect:public figure
{
    int l;
    int b;
    public:
    void read()
    {
        cout<<"Enter the l and b value"<<endl;
        cin>>l>>b;
    }
    void area()
    {
        a=l*b;
    }
    void display()
    {
        cout<<"The rect area is\t"<<a<<"sq.cm"<<endl;
    }
};
class Square:public figure
{
    int s;
    public:
    void read()
    {
        cout<<"Enter the s value"<<endl;
        cin>>s;
    }
    void area()
    {
        a=s*s;
    }
    void display()
    {
        cout<<"The square area is\t"<<a<<"sq.cm"<<endl;
    }
};

void main()
{
    Rect ao;
    Square bo;
    clrscr();
    ao.read();
    ao.area();
    bo.read();
    bo.area();
    figure *ptr;
    ptr=&ao;
    ptr->display();
    ptr=&bo;
    ptr->display();
    getch();
}
=========================================================================
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void swap(int *aptr,int *bptr)
{
    *aptr=*aptr+*bptr;
    *bptr=*aptr-*bptr;
    *aptr=*aptr-*bptr;
    cout<<"a and b values in swap function\t"
    <<*aptr<<setw(5)<<*bptr<<endl;
}
void main()
{
    int a,b;
    clrscr();
    cout<<"Enter a and b values"<<endl;
    cin>>a>>b;
    cout<<"a and b values before swap function\t"<<a<<setw(5)<<b<<endl;
    swap(&a,&b);
    cout<<"a and b values after swap function\t"<<a<<setw(5)<<b<<endl;
    getch();
}
=========================================================================
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void swap(int &a,int &b)
{
    a=a+b;
    b=a-b;
    a=a-b;
    cout<<"a and b values in swap function\t"
    <<a<<setw(5)<<b<<endl;
}
void main()
{
    int a,b;
    clrscr();
    cout<<"Enter a and b values"<<endl;
    cin>>a>>b;
    cout<<"a and b values before swap function\t"<<a<<setw(5)<<b<<endl;
    swap(a,b);
    cout<<"a and b values after swap function\t"<<a<<setw(5)<<b<<endl;
    getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
    int ch1,ch2,rs;
    clrscr();
    do
    {

    cout<<"\n1.NON STOP"<<endl;
    cout<<"2.EXPRESS"<<endl;
    cout<<"3.ORDINARY"<<endl;
    cout<<"Select bus--->(1 2 or 3)"<<endl;
    cin>>ch1;
    switch(ch1)
    {
        case 1:
            cout<<"1.ADULT"<<endl;
            cout<<"2.CHILD"<<endl;
            cout<<"Select category(1 or 2)"<<endl;
            cin>>ch2;
            switch(ch2)
            {
                case 1:
                    cout<<"Enter Non stop Ticket fair(50 rs/-) for adult"<<endl;
                    cin>>rs;
                    if(rs>=50)
                    {
                        rs-=50;
                        cout<<"Nonstop ticket issued for adult"<<endl;
                    }
                    else
                    cout<<"Invalid Amount"<<endl;
                    break;
                case 2:
                    cout<<"Enter Non stop Ticket fair(25 rs/-) for child"<<endl;
                    cin>>rs;
                    if(rs>=25)
                    {
                        rs-=25;
                        cout<<"Nonstop ticket issued for child"<<endl;
                    }
                    else
                    cout<<"Invalid Amount"<<endl;

            }
            break;
        case 2:
            cout<<"1.ADULT"<<endl;
            cout<<"2.CHILD"<<endl;
            cout<<"Select category(1 or 2)"<<endl;
            cin>>ch2;
            switch(ch2)
            {
                case 1:
                    cout<<"Enter Express Ticket fair(40 rs/-) for adult"<<endl;
                    cin>>rs;
                    if(rs>=40)
                    {
                        rs-=40;
                        cout<<"Express ticket issued for adult"<<endl;
                    }
                    else
                    cout<<"Invalid Amount"<<endl;
                    break;
                case 2:
                    cout<<"Enter Express Ticket fair(20 rs/-) for child"<<endl;
                    cin>>rs;
                    if(rs>=20)
                    {
                        rs-=20;
                        cout<<"Express ticket issued for child"<<endl;
                    }
                    else
                    cout<<"Invalid Amount"<<endl;

            }
            break;
        case 3:
            cout<<"1.ADULT"<<endl;
            cout<<"2.CHILD"<<endl;
            cout<<"Select category(1 or 2)"<<endl;
            cin>>ch2;
            switch(ch2)
            {
                case 1:
                    cout<<"Enter Ordinary Ticket fair(30 rs/-) for adult"<<endl;
                    cin>>rs;
                    if(rs>=30)
                    {
                        rs-=30;
                        cout<<"Ordinary ticket issued for adult"<<endl;
                    }
                    else
                    cout<<"Invalid Amount"<<endl;
                    break;
                case 2:
                    cout<<"Enter Ordinary Ticket fair(10 rs/-) for child"<<endl;
                    cin>>rs;
                    if(rs>=10)
                    {
                        rs-=10;
                        cout<<"Ordinary ticket issued for child"<<endl;
                    }
                    else
                    cout<<"Invalid Amount"<<endl;

            }
        }
        if(rs!=0&&ch1<4)
        cout<<"Return amount\t"<<rs<<"\trs/-"<<endl;

    }while(ch1<4);
    getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Address
{
    int hno;
    char city[100];
    char dist[100];
    int pin;
    public:
    void a_read()
    {
        cout<<"Enter hno city district and pin code"<<endl;
        cin>>hno;
        flushall();
        gets(city);
        flushall();
        gets(dist);
        flushall();
        cin>>pin;
    }
    void a_display()
    {
        cout<<"\t*******Address Information**********\n\tH.no\t"
        <<hno<<"\n\tCity\t"<<city<<"\n\tDistrict\t"<<dist
        <<"\n\tPin code\t"<<pin<<endl;
    }
};
class Student:public Address
{
    int rno;
    char name[100];
    char degree[100];
    public:
    void s_read()
    {
        cout<<"Enter the rno name and degree"<<endl;
        cin>>rno;
        flushall();
        gets(name);
        flushall();
        gets(degree);
    }
    void s_display()
    {
        cout<<"\t**********Student details************\n\tR.no\t"
        <<rno<<"\n\tName\t"<<name<<"\n\tDegree\t"<<degree<<endl;
    }
};
void main()
{
    Student so;
    clrscr();
    so.s_read();
    so.a_read();
    so.s_display();
    so.a_display();
    getch();
}
=======================================================================
include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Address
{
    int hno;
    char city[100];
    char dist[100];
    int pin;
    public:
    void a_read()
    {
        cout<<"Enter hno city district and pin code"<<endl;
        cin>>hno;
        flushall();
        gets(city);
        flushall();
        gets(dist);
        flushall();
        cin>>pin;
    }
    void a_display()
    {
        cout<<"\t*******Address Information**********\n\tH.no\t"
        <<hno<<"\n\tCity\t"<<city<<"\n\tDistrict\t"<<dist
        <<"\n\tPin code\t"<<pin<<endl;
    }
};
class Student:public Address
{
    int rno;
    char name[100];
    char degree[100];
    public:
    void s_read()
    {
        cout<<"Enter the rno name and degree"<<endl;
        cin>>rno;
        flushall();
        gets(name);
        flushall();
        gets(degree);
    }
    void s_display()
    {
        cout<<"\t**********Student details************\n\tR.no\t"
        <<rno<<"\n\tName\t"<<name<<"\n\tDegree\t"<<degree<<endl;
    }
};
void main()
{
    Student so;
    clrscr();
    so.s_read();
    so.a_read();
    so.s_display();
    so.a_display();
    getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
template<class T>
class list
{
    T *ptr;
    int n;
    public:
    //dynamic constructor function declarations
    list();
    list(int n);
    //copy constructor function declaration
    list(list &rl);
    //destructor
    ~list()
    {
        cout<<"Destructor executed"<<endl;
        delete(ptr);
    }
    void read();
    void display();
};
//dynamic constructor function implementions
template<class T>
list<T>::list()
{
    int i;
    ptr=new T[10];
    for(i=0;i<10;i++)
    *(ptr+i)=0;
    n=10;
}
template<class T>
list<T>::list(int size)
{
    int i;
    ptr=new T[size];
    for(i=0;i<size;i++)
    *(ptr+i)=0;
    n=size;
}
//copy constructor function implemention
template<class T>
void list<T>::read()
{
    cout<<"Enter list elements"<<endl;
    for(int i=0;i<n;i++)
    cin>>*(ptr+i);
}
template<class T>
void list<T>::display()
{
    int i;
    for(i=0;i<n;i++)
    cout<<"\t"<<*(ptr+i);
}
void main()
{
    list<int> lo1(10);
    clrscr();
    lo1.read();
    lo1.display();

    list<char> lo2(10);
    lo2.read();
    lo2.display();

    getch();
}
=======================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
    int mat[100][100],i,j,rows,cols,temp,d;
    clrscr();
    cout<<"Enter rows and columns"<<endl;
    cin>>rows>>cols;
    cout<<"Enter Table values"<<endl;
    for(i=0;i<rows;i++)
    for(j=0;j<cols;j++)
        cin>>mat[i][j];
    if(rows<cols)
        d=rows;
    else
        d=cols;
    for(i=0;i<d;i++)
    for(j=0;j<i;j++)
    {
        temp=mat[i][j];
        mat[i][j]=mat[j][i];
        mat[j][i]=temp;
    }
    if(rows!=cols)
    {
        if(rows<cols)
        {
            for(i=0;i<rows;i++)
            for(j=rows;j<cols;j++)
            mat[j][i]=mat[i][j];
        }
        else
        {
            for(i=cols;i<rows;i++)
            for(j=0;j<cols;j++)
            mat[j][i]=mat[i][j];
        }
    }
    cout<<"The table values are"<<endl;
    for(i=0;i<cols;i++)
    {
        for(j=0;j<rows;j++)
        cout<<"\t"<<mat[i][j];
        cout<<"\n"<<endl;
    }
    getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
class complex
{
     int real;
     int img;
     public:
     void read()
     {
     cout<<"Enter real and imaginary parts of the complex number"<<endl;
     cin>>real>>img;
     }
     void display()
     {
        cout<<real;
        if(img<0)
        cout<<"\t-i"<<-(img)<<endl;
        else
        cout<<"\t+i"<<img<<endl;
     }
     complex operator-()
     {
        complex temp;
        temp.real=-(real);
        temp.img=-(img);
        return temp;
     }
    friend complex operator+(complex co);
};
complex operator+(complex co)
{
    complex temp;
    if(co.real<0)
    temp.real=-(co.real);
    else
    temp.real=co.real;
    if(co.img<0)
    temp.img=-(co.img);
    else
    temp.img=co.img;
    return temp;
}
void main()
{
    complex co1,res;
    clrscr();
    co1.read();
    cout<<"complex number\n\n"<<endl;
    co1.display();
    res=-co1;

    cout<<"result for nagative operator(-ve)\n\n"<<endl;
    res.display();
    res=+(co1);
    cout<<"result for positive operator(+ve)\n\n"<<endl;
    res.display();
    getch();
}
=======================================================================
#include<iostream.h>
#include<conio.h>
class A
{
    int a;
    public:
    void a_read()
    {
        cout<<"Enter the a value"<<endl;
        cin>>a;
    }
    void a_display()
    {
        cout<<"The a value is\t"<<a<<endl;
    }
};
class B:virtual public A
{
    int b;
    public:
    void b_read()
    {
        cout<<"Enter the b value"<<endl;
        cin>>b;
    }
    void b_display()
    {
        cout<<"The b value is\t"<<b<<endl;
    }
};
class C:virtual public A
{
    int c;
    public:
    void c_read()
    {
        cout<<"Enter the c value"<<endl;
        cin>>c;
    }
    void c_display()
    {
        cout<<"The c value is\t"<<c<<endl;
    }
};
class D:public B,public C
{
    int d;
    public:
    void d_read()
    {
        cout<<"Enter the d value"<<endl;
        cin>>d;
    }
    void d_display()
    {
        cout<<"The d value is\t"<<d<<endl;
    }
};
void main()
{
    D d;
    clrscr();
    d.a_read();
    d.b_read();
    d.c_read();
    d.d_read();
    d.a_display();
    d.b_display();
    d.c_display();
    d.d_display();
    getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
class A
{
    int a;
    public:
    virtual void read()
    {
        cout<<"Enter the a value"<<endl;
        cin>>a;
    }
    virtual void display()
    {
        cout<<"The a value is\t"<<a<<endl;
    }
};
class B:public A
{
    int b;
    public:
    void read()
    {
        cout<<"Enter the b value"<<endl;
        cin>>b;
    }
    void display()
    {
        cout<<"The b value is\t"<<b<<endl;
    }
};
void main()
{
    A ao;
    B bo;
    clrscr();
    A *ptr;
    ptr=&ao;
    ptr->read();
    ptr->display();
    ptr=&bo;
    ptr->read();
    ptr->display();
    getch();
}
======================================================================
#include<iostream.h>
#include<conio.h>
class A
{
    int a;
    int b;
    public:
    void read()
    {
        cout<<"Enter a and b values"<<endl;
        cin>>a>>b;
    }
    void display()
    {
        cout<<"The a and b values are\t"<<a<<"\t"<<b<<endl;
    }
    friend int pvsum(A ao);
};
int pvsum(A ao)
{
    int s=ao.a+ao.b;
    return s;
}
void main()
{
    A ao;
    clrscr();
    ao.read();
    ao.display();
    int s=pvsum(ao);
    cout<<"\nao object private members(a,b) sum is\t"<<s<<endl;
    getch();
}
========================================================================
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
class Employee
{
    int eno;
    char name[100];
    char desig[100];
    long bsal;
    long hra;
    long ta;
    long da;
    long tsal;
    public:
    void e_read()
    {
     cout<<"Enter Employeee number name designation and basic salary"<<endl;
    cin>>eno;
    flushall();
    gets(name);
    flushall();
    gets(desig);
    flushall();
    cin>>bsal;
    salcal();
    }
    void salcal()
    {
        hra=bsal/10;
        ta=bsal/10;
        da=bsal/10;
        tsal=bsal+hra+da+ta;
    }
    void e_display()
    {
        cout<<"\t*************Employee Details*************"
        <<"\n\tE.no\t"<<eno<<"\n\tName\t"<<name<<"\n\tDesignation\t"
        <<desig<<"\n\tBasic salary\t"<<bsal<<"rs/-\n\tHra\t"<<hra
        <<"rs/-\n\tDa\t"<<da<<"rs/-\n\tTa\t"<<ta<<"\n\tTotalsalary\t"
        <<tsal<<"rs/-"<<endl;
    }
    friend int incomtax(Employee eobj);
};
int incomtax(Employee eobj)
{
    int tax=eobj.tsal/10;
    return tax;
}
void main()
{
    Employee eo;
    clrscr();
    eo.e_read();
    eo.e_display();
    int tax=incomtax(eo);
    cout<<"Incomtax\t"<<tax<<"rs/-"<<endl;
    getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
class A
{
    int a;
    int b;
    public:
    void read()
    {
        cout<<"Enter a and b values"<<endl;
        cin>>a>>b;
    }
    void display()
    {
        cout<<"The a and b values are\t"<<a<<"\t"<<b<<endl;
    }
    friend class B;
};
class B
{
    public:
    int AMdifference(A ao)
    {
        int d=ao.a-ao.b;
        return d;
    }
    int AMproduct(A ao)
    {
        int p=ao.a*ao.b;
        return p;
    }
};
void main()
{
    A ao;
    clrscr();
    ao.read();
    ao.display();
    B bo;
    int d=bo.AMdifference(ao);
    cout<<"ao member variables difference is\t"<<d<<endl;
    int p=bo.AMproduct(ao);
    cout<<"ao member variables product is\t"<<p<<endl;
    getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
class A
{
    int a;
    int b;
    public:
    void read()
    {
        cout<<"Enter the a and b values"<<endl;
        cin>>a>>b;
    }
    void display()
    {
        cout<<"\n\tThe a and b values are\t"<<a<<"\t"<<b<<endl;
    }
    friend class B;
};
class B
{
    public:
    int sum(A ao)
    {
        int s=ao.a+ao.b;
        return s;
    }
};
void main()
{
    A ao;
    B bo;
    clrscr();
    ao.read();
    cout<<"Ao private variables sum is\t"<<bo.sum(ao)<<endl;
    getch();
}
=========================================================================
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class Employee
{
    int eno;
    char name[100];
    char desig[100];
    long bsal;
    long hra;
    long ta;
    long da;
    long tsal;
    public:
    void e_read()
    {
     cout<<"Enter Employeee number name designation and basic salary"<<endl;
    cin>>eno;
    flushall();
    gets(name);
    flushall();
    gets(desig);
    flushall();
    cin>>bsal;
    salcal();
    }
    void salcal()
    {
        hra=bsal/10;
        ta=bsal/10;
        da=bsal/10;
        tsal=bsal+hra+da+ta;
    }
    void e_display()
    {
        cout<<"\t*************Employee Details*************"
        <<"\n\tE.no\t"<<eno<<"\n\tName\t"<<name<<"\n\tDesignation\t"
        <<desig<<"\n\tBasic salary\t"<<bsal<<"rs/-\n\tHra\t"<<hra
        <<"rs/-\n\tDa\t"<<da<<"rs/-\n\tTa\t"<<ta
        <<"\trs/-\n\tTotalsalary\t"
        <<tsal<<"rs/-"<<endl;
    }
    friend long incomtax(Employee e);
};
long incomtax(Employee eobj)
{
    long it=eobj.tsal/10;
    return it;
}
void main()
{
    Employee eo;
    clrscr();
    eo.e_read();
    eo.e_display();
    cout<<"Incomtax is\t"<<incomtax(eo)<<"\trs/-"<<endl;
    getch();
 }
=========================================================================
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Student
{
    int rno;
    char name[100];
    char degree[100];
    public:
    void s_read();
    void s_display();
};
void Student::s_read()
{
    cout<<"Enter the rno name and degree"<<endl;
    cin>>rno;
    flushall();
    gets(name);
    flushall();
    gets(degree);
}
void Student::s_display()
{
    cout<<"\t**********Student details************\n\tR.no\t"
    <<rno<<"\n\tName\t"<<name<<"\n\tDegree\t"<<degree<<endl;
}
void main()
{
    Student so;
    clrscr();
    so.s_read();
    so.s_display();
    getch();
}
=======================================================================
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Address
{
    int hno;
    char city[100];
    char dist[100];
    int pin;
    public:
    void a_read()
    {
        cout<<"Enter hno city district and pin code"<<endl;
        cin>>hno;
        flushall();
        gets(city);
        flushall();
        gets(dist);
        flushall();
        cin>>pin;
    }
    void a_display()
    {
        cout<<"\t*******Address Information**********\n\tH.no\t"
        <<hno<<"\n\tCity\t"<<city<<"\n\tDistrict\t"<<dist
        <<"\n\tPin code\t"<<pin<<endl;
    }
};
class Student:public Address
{
    int rno;
    char name[100];
    char degree[100];
    public:
    void s_read()
    {
        cout<<"Enter the rno name and degree"<<endl;
        cin>>rno;
        flushall();
        gets(name);
        flushall();
        gets(degree);
    }
    void s_display()
    {
        cout<<"\t**********Student details************\n\tR.no\t"
        <<rno<<"\n\tName\t"<<name<<"\n\tDegree\t"<<degree<<endl;
    }
};
class Employee:public Address
{
    int eno;
    char name[100];
    char desig[100];
    long bsal;
    long hra;
    long ta;
    long da;
    long it;
    long tsal;
    long gsal;
    public:
    void e_read()
    {
     cout<<"Enter Employeee number name designation and basic salary"<<endl;
    cin>>eno;
    flushall();
    gets(name);
    flushall();
    gets(desig);
    flushall();
    cin>>bsal;
    salcal();
    }
    void salcal()
    {
        hra=bsal/10;
        ta=bsal/10;
        da=bsal/10;
        it=bsal/20;
        tsal=bsal+hra+da+ta;
        gsal=tsal-it;
    }
    void e_display()
    {
        cout<<"\t*************Employee Details*************"
        <<"\n\tE.no\t"<<eno<<"\n\tName\t"<<name<<"\n\tDesignation\t"
        <<desig<<"\n\tBasic salary\t"<<bsal<<"rs/-\n\tHra\t"<<hra
        <<"rs/-\n\tDa\t"<<da<<"rs/-\n\tTa\t"<<ta<<"\n\tIt\t"<<it
        <<"rs/-\n\tTotalsalary\t"
        <<tsal<<"rs/-\n\tGross salary\t"<<gsal<<endl;
    }
};
void main()
{
    Student so;
    clrscr();
    so.s_read();
    so.a_read();
    so.s_display();
    so.a_display();
    Employee eo;
    eo.e_read();
    eo.a_read();
    eo.e_display();
    eo.a_display();
    getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
inline int checkup(char *name,char *pass);
void main()
{
    char name[100],pass[100];
    clrscr();
    cout<<"Enter user name and pass word"<<endl;
    gets(name);
    flushall();
    gets(pass);
    flushall();
    int r=checkup(name,pass);
    if(r==0)
    cout<<"Valid account"<<endl;
    else
    cout<<"Not valid account"<<endl;
    getch();
}
int checkup(char *name,char *pass)
{
    int flag=1;
    char user[]="scott";
    char word[]="tiger";
    int r1=strcmp(name,user);
    int r2=strcmp(pass,word);
    if((r1==0)&&(r2==0))
          flag=0;
    return flag;
}
========================================================================
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Item
{
    static char company[100];
    static char city[100];
    static char state[100];
    int ino;
    char name[100];
    int cp;
    float sp;
    public:
    static void cdreading()
    {
        cout<<"Enter the company name city and state"<<endl;
        gets(company);
        flushall();
        gets(city);
        flushall();
        gets(state);
        flushall();
    }
    static void cddisplay()
    {
        cout<<"********Company Details******\n\t Name\t:"<<company<<"\n\tCity\t:"<<city<<"\n\tState\t:"<<state<<endl;
    }
    void read()
    {
        cout<<"Enter the Item no name cost price"<<endl;
        cin>>ino;
        flushall();
        gets(name);
        flushall();
        cin>>cp;
    }
    void findsp(int per)
    {
        sp=(float)cp+(per*(cp/100));
    }
    void display()
    {
        cout<<"\n\t******Item Details********\n\tItem .no\t:"<<ino<<"Name\t:"<<name<<"\n\tCost price\t:"<<cp<<"\trs/-\n\tSelling price\t:"<<sp<<"\trs/-"<<endl;
    }
};
char Item::company[100];
char Item::city[100];
char Item::state[100];
void main()
{
    Item io1,io2;
    clrscr();
    Item::cdreading();
    io1.read();
    io2.read();
    io1.findsp(10);
    io2.findsp(20);
    io1.display();
    Item::cddisplay();
    io2.display();
    Item::cddisplay();
    getch();
}
/*
    local classes:-

    we can define classes inside function or block.
    That are called local classes.

    The following are the restrictions

    1.local classes can access global variables with scope resolution
    operator.

    2.These can access static variables which are
    declared inside the function.

    3.C++ doest not allows to access local variables of the
    function inside classes.

    4.C++ doest not allows to declare static data members inside
    the local classes.

    5.Enclosing functions can not access private members of the
    local classes.

    syntax:-

    returntype functionname(type arg1,type arg2,.....)
    {
        stmt1;
        stmt2;

        -----
        class classname
        {
            type member1;
            type member2;
            ------------
            ------------
            public:
            returntype mfunctionname(type arg1,type arg2,.....)
            {
            stmt1;
            stmt2;
            -----
            -----
            }
        };
        classname obj1,obj2........;
    }
*/
========================================================================
#include<iostream.h>
#include<conio.h>
class list
{
    int *ptr;
    int n;
    public:
    //dynamic constructor function declarations
    list();
    list(int n);
    ~list()
    {
        cout<<"Destructor executed"<<endl;
        delete(ptr);
    }
    void display();
};
//dynamic constructor function implementions
list::list()
{
    int i;
    ptr=new int[10];
    for(i=0;i<10;i++)
    *(ptr+i)=0;
    n=10;
}
list::list(int size)
{
    int i;
    ptr=new int[size];
    for(i=0;i<size;i++)
    *(ptr+i)=0;
    n=size;
}
void list::display()
{
    int i;
    for(i=0;i<n;i++)
    cout<<"\t"<<*(ptr+i);
}
void main()
{
    int n2,n3;
    clrscr();
    cout<<"Enter second list size"<<endl;
    cin>>n2;
    cout<<"Enter third list size"<<endl;
    cin>>n3;
    list lo1,lo2(n2),lo3(n3);
    cout<<"\nFirst object list contents"<<endl;
    lo1.display();
    cout<<"\nSecond object list contents"<<endl;
    lo2.display();
    cout<<"\nThird object list contents"<<endl;
    lo3.display();
    getch();
}
=========================================================================
#include<iostream.h>
#include<conio.h>
class list
{
    int *ptr;
    int n;
    public:
    //dynamic constructor function declarations
    list();
    list(int n);
    //copy constructor function declaration
    list(list &rl);
    //destructor
    ~list()
    {
        cout<<"Destructor executed"<<endl;
        delete(ptr);
    }
    void read();
    void display();
};
//dynamic constructor function implementions
list::list()
{
    int i;
    ptr=new int[10];
    for(i=0;i<10;i++)
    *(ptr+i)=0;
    n=10;
}
list::list(int size)
{
    int i;
    ptr=new int[size];
    for(i=0;i<size;i++)
    *(ptr+i)=0;
    n=size;
}
//copy constructor function implemention
list::list(list &rl)
{
    int i;
    ptr=new int[rl.n];
    for(i=0;i<rl.n;i++)
    *(ptr+i)=*(rl.ptr+i);
    n=rl.n;
}
void list::read()
{
    cout<<"Enter list elements"<<endl;
    for(int i=0;i<n;i++)
    cin>>*(ptr+i);
}
void list::display()
{
    int i;
    for(i=0;i<n;i++)
    cout<<"\t"<<*(ptr+i);
}
void main()
{
    int n1;
    clrscr();
    cout<<"Enter list size"<<endl;
    cin>>n1;
    list lo1(n1);
    cout<<"\nlo1 object list contents"<<endl;
    lo1.display();
    cout<<"Copy constructor function demonstration"<<endl;
    lo1.read();
    list lo2=lo1;
    cout<<"lo1 list contents after reading"<<endl;
    lo1.display();
    cout<<"\nlo2 list contents"<<endl;
    lo2.display();
    getch();
}
=======================================================================
#include<iostream.h>
#include<conio.h>
class A
{
    int a;
    public:
    void a_read()
    {
        cout<<"Enter a value"<<endl;
        cin>>a;
    }
    void a_display()
    {
        cout<<"The a value is\t"<<a<<endl;
    }
};
class B:public A
{
    int b;
    public:
    void b_read()
    {
        cout<<"Enter b value"<<endl;
        cin>>b;
    }
    void b_display()
    {
        cout<<"The b value is\t"<<b<<endl;
    }
};
class C:public B
{
    int c;
    public:
    void c_read()
    {
        cout<<"Enter c value"<<endl;
        cin>>c;
    }
    void c_display()
    {
        cout<<"The c value is\t"<<c<<endl;
    }
};
void main()
{
    C cobj;
    clrscr();
    cobj.a_read();
    cobj.b_read();
    cobj.c_read();
    cobj.a_display();
    cobj.b_display();
    cobj.c_display();
    getch();

}
========================================================================
#include <iostream.h>
#include <conio.h>
#include<stdio.h>
class Address
{
    char city[100];
    char dist[100];
    int pin;
    public:
    void a_read()
    {
        cout<<"Enter city district and pin code"<<endl;
        flushall();
        gets(city);
        flushall();
        gets(dist);
        flushall();
        cin>>pin;
    }
    void a_display()
    {
        cout<<"\t*******Address Information**********\n\t\n\tCity\t"
        <<city<<"\n\tDistrict\t"<<dist
        <<"\n\tPin code\t"<<pin<<endl;
    }
};
class Company:public Address
{
    char company[100];
    int d;
    int m;
    int y;
    public:
    void c_read()
    {
        cout<<"Enter the company name and established date"<<endl;
        gets(company);
        flushall();
        cin>>d>>m>>y;
    }
    void c_display()
    {
        cout<<"********Company Details******\n\t Name\t:"<<company<<"\n\tEstablished Date\t:"<<d<<"-"<<m<<"-"<<y<<endl;
    }
};
class Item:public Company
{
    int ino;
    char name[100];
    int cp;
    float sp;
    public:

    void i_read()
    {
        cout<<"Enter the Item no name cost price"<<endl;
        cin>>ino;
        flushall();
        gets(name);
        flushall();
        cin>>cp;
        findsp();
    }
    void findsp()
    {
        sp=(float)cp+(cp/10);
    }
    void i_display()
    {
        cout<<"\n\t******Item Details********\n\tItem .no\t:"<<ino<<"Name\t:"<<name<<"\n\tCost price\t:"<<cp<<"\trs/-\n\tSelling price\t:"<<sp<<"\trs/-"<<endl;
    }
};
void main()
{
        Item io;
        clrscr();
        io.c_read();
        io.i_read();
        io.a_read();
        io.i_display();
        io.c_display();
        io.a_display();
        getch();
}
=======================================================================
#include<iostream.h>
#include<conio.h>
class A
{
    int a;
    public:
    void a_read()
    {
        cout<<"Enter a value"<<endl;
        cin>>a;
    }
    void a_display()
    {
        cout<<"The a value is\t"<<a<<endl;
    }
};
class B
{
    int b;
    public:
    void b_read()
    {
        cout<<"Enter b value"<<endl;
        cin>>b;
    }
    void b_display()
    {
        cout<<"The b value is\t"<<b<<endl;
    }
};
class C:public A,public B
{
    int c;
    public:
    void c_read()
    {
        cout<<"Enter c value"<<endl;
        cin>>c;
    }
    void c_display()
    {
        cout<<"The c value is\t"<<c<<endl;
    }
};
void main()
{
    C co;
    clrscr();
    co.a_read();
    co.b_read();
    co.c_read();
    co.a_display();
    co.b_display();
    co.c_display();
    getch();

}
=========================================================================
#include<iostream.h>
#include<conio.h>
int add(int a,int b);
int add(int a,int b,int c);
int add(int a,int b,int c,int d);
void main()
{
    int a,b,c,d,s;
    clrscr();
    cout<<"Enter the a b c and d values"<<endl;
    cin>>a>>b>>c>>d;
    s=add(a,b);
    cout<<a<<" and "<<b<<" sum is\t"<<s<<endl;
    s=add(a,b,c);
    cout<<a<<" "<<b<<" and "<<c<<" sum is\t"<<s<<endl;
    s=add(a,b,c,d);
    cout<<a<<" "<<b<<" "<<c<<" and "<<d<<" sum is\t"<<s<<endl;
    getch();
}
int add(int a,int b)
{
    int s=a+b;
    return s;
}
int add(int a,int b,int c)
{
    int s=a+b+c;
    return s;
}
int add(int a,int b,int c,int d)
{
    int s=a+b+c+d;
    return s;
}
==========================================================================
#include<iostream.h>
#include<conio.h>
int max(int a,int b);
int max(int a,int b,int c);
int max(int a,int b,int c,int d);
void main()
{
    int a,b,c,d,m;
    clrscr();
    cout<<"Enter the a b c and d values"<<endl;
    cin>>a>>b>>c>>d;
    m=max(a,b);
    cout<<a<<" and "<<b<<" maximum is\t"<<m<<endl;
    m=max(a,b,c);
    cout<<a<<" "<<b<<" and "<<c<<" maximum is\t"<<m<<endl;
    m=max(a,b,c,d);
    cout<<a<<" "<<b<<" "<<c<<" and "<<d<<" maximum is\t"<<m<<endl;
    getch();
}
int max(int a,int b)
{
    int m=a>b?a:b;
    return m;
}
int max(int a,int b,int c)
{
    int m=a>b?a:b;
     m=m>c?m:c;
    return m;
}
int max(int a,int b,int c,int d)
{
    int m=a>b?a:b;
     m=m>c?m:c;
    m=m>d?m:d;
    return m;
}
========================================================================
#include<iostream.h>
#include<conio.h>
class A
{
    int a;
    public:
    A()
    {
        a=10;
    }
    A(int a1)
    {
        a=a1;
    }
    void a_display()
    {
        cout<<"The a value is\t"<<a<<endl;
    }
};
class B:public A
{
    int b;
    public:
    B():A()
    {
        b=20;
    }
    B(int a1,int b1):A(a1)
    {
        b=b1;
    }
    void b_display()
    {
        cout<<"The b value is\t"<<b<<endl;
    }
};
class C:public B
{
    int c;
    public:
    C():B()
    {
        c=30;
    }
    C(int a1,int b1,int c1):B(a1,b1)
    {
        c=c1;
    }
    void c_display()
    {
        cout<<"The c value is\t"<<c<<endl;
    }
};
void main()
{
    C co(100,200,300);
    clrscr();
    co.a_display();
    co.b_display();
    co.c_display();
    getch();

}
========================================================================
#include<iostream.h>
#include<conio.h>
class A
{
    int a;
    public:
    A()
    {
        a=10;
    }
    A(int a1)
    {
        a=a1;
    }
    void a_display()
    {
        cout<<"The a value is\t"<<a<<endl;
    }
};
class B:public A
{
    int b;
    public:
    B():A()
    {
        b=20;
    }
    B(int a1,int b1):A(a1)
    {
        b=b1;
    }
    void b_display()
    {
        cout<<"The b value is\t"<<b<<endl;
    }
};
class C:public B
{
    int c;
    public:
    C():B()
    {
        c=30;
    }
    C(int a1,int b1,int c1):B(a1,b1)
    {
        c=c1;
    }
    void c_display()
    {
        cout<<"The c value is\t"<<c<<endl;
    }
};
void main()
{
    C co(100,200,300);
    clrscr();
    co.a_display();
    co.b_display();
    co.c_display();
    getch();

}
========================================================================
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class PassBook
{
    int ano;
    char name[100];
    long amount;
    static long tamount;
    public:
    void read()
    {
        cout<<"Enter a/c no name and initial amount"<<endl;
        cin>>ano;
        flushall();
        gets(name);
        flushall();
        cin>>amount;
        tamount+=amount;
    }
    void deposit(int amou)
    {
        amount+=amou;
        tamount+=amou;
    }
    void withDraw(int amou)
    {
        if(amou>amount)
        {
            cout<<"Invalid amount"<<endl;
        }
        else
        {
            amount-=amou;
            tamount-=amou;
        }
    }
    void display()
    {
        cout<<"\nPass Book Details\n\nA.cno\t"<<ano<<"\nName\t"<<name<<"\nAmount\t"<<amount<<"\trs/-"<<endl;
    }
    static void bankAmount()
    {
            cout<<"Total Bank amount\t"<<tamount<<"\trs/-"<<endl;
    }
};
long PassBook::tamount;
void main()
{
        PassBook po1,po2;
        clrscr();
        po1.read();
        po2.read();
        long amou;
        int ch;
        do
        {
        cout<<"1.Deposit"<<endl;
        cout<<"2.With draw"<<endl;
        cout<<"3.Display"<<endl;
        cout<<"4.Total bank amount"<<endl;
        cout<<"Enter choice"<<endl;
        cin>>ch;
        switch(ch)
        {
            case 1:
                    cout<<"Enter deposit amount"<<endl;
                    cin>>amou;
                    po1.deposit(amou);
                    break;
                case 2:
                    cout<<"Enter with draw amount"<<endl;
                cin>>amou;                    po1.withDraw(amou);
                    break;
                case 3:
                    po1.display();
                    break;
                case 4:
                    PassBook::bankAmount();
                    break;
                default:
                    cout<<"No match found"<<endl;
        }
        }while(ch<5);
    }

========================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
int i,n;
clrscr();
cout<<"enter a value"<<endl;
for(i=n/2;i>2;i--)
if(n%i==0)
break;
if(i!=1)
cout<<n<<"n is not a prime"<<endl;
else
cout<<n<<"n is a prime number"<<endl;
getch();
}
========================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
int n,r=0;
clrscr();
cout<<"enter a value"<<n<<endl;
cin>>n;
while(n>0)
{
r=r*10+n%10;
n=n/10;
}
cout<<"the reverse number is\t"<<r<<endl;
getch();
}
=======================================================================
#include<iostream.h>
#include<conio.h>
void main()
{
int i,n,r=0;
clrscr();
cout<<"enter the value"<<endl;
cin>>n;
for(i=0;i<=n;i++)
r=r+i*i;
cout<<n<<"numbers squares sum is\t"<<r<<endl;
getch();
}
========================================================================
#include <iostream.h>
#include<conio.h>
class Person
{
    protected:
    char name[100];
    char city[100];
    public:
    void read()
    {
        cout<<"Enter name and city of the Personn"<<endl;
        cin>>name>>city;
    }
    virtual void display()
    {
        cout<<"\nPerson details\nName\t:"<<name<<"\nCity\t:"
        <<city<<endl;
    }
};
class Employee:public Person
{
    int eno;
    char desig[100];
    long sal;
    public:
    void e_read()
    {
        cout<<"\nEnter the employee no desig and sal"<<endl;
        cin>>eno>>desig>>sal;
    }
    void display()
    {
    cout<<"\nEmployee Details\nEpno\t:"<<eno<<"\nName\t:"<<name<<"\nDesignation\t:"<<desig<<"\nSalary\t"<<sal<<"\nAddress\nCity\t:"<<city<<endl;
    }
};
void main()
{
    Employee eobj;
    clrscr();
    eobj.read();
    eobj.e_read();
    eobj.display();
    Person p;
    p.read();
    p.display();
    getch();
}


No comments:

Post a Comment