Sunday, 18 August 2013

Character With Get() and Put()

#include<iostream.h>
#include<conio.h>
void main()
{
    clrscr();
    int count=0;
    char c;

    cout<<"\n Enter Text : ";
    cin.get(c);

    while(c!='\n')
    {
        cout.put(c);
        count++;
        cin.get(c);
    }
    cout<<"\n Number of characters = "<<count;
    getch();
}

Here Is The Output :)


String using write ♥♥♥

#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
    clrscr();
    char *s=" Bhavna";
    int n=strlen(s);
   
    for(int i=1;i<n;i++)
    {
        cout.write(s,i);
        cout<<"\n";
    }
    for(i=n;i>0;i--)
    {
        cout.write(s,i);
        cout<<"\n";
    }
    getch();
}

Here Is The Output :)


Saturday, 17 August 2013

Overloading + Operator

#include<iostream.h>
#include<conio.h>
class mahi
{
    float x,y;
    public:
        mahi()
        {}
        mahi(float real,float image)
        {
            x=real;
            y=image;
        }
        mahi operator+(mahi);
        void display(void);
};
mahi mahi::operator+(mahi c)
{
    mahi temp;
    temp.x=x+c.x;
    temp.y=y+c.y;
    return (temp);
}
void mahi::display(void)
{
    cout<<x<<" And "<<y<<"\n";
}
void main()
{
    clrscr();
    mahi m1,m2,m3;
    m1=mahi(2.5,3.5);
    m2=mahi(1.4,2.6);
    m3=m1+m2;

    cout<<"\n M1= ";
    m1.display();
    cout<<"\n M2= ";
    m2.display();
    cout<<"\n M3= ";
    m3.display();

    getch();
}

Here Is The Output :)


Thursday, 15 August 2013

Inheritance Example :)

#include<iostream.h>
#include<conio.h>
class mahi
{
    public:
        char name1[20],name2[20];
        void putdata()
        {
            cout<<"\n Enter The Name1: ";
            cin>>name1;
            cout<<"\n Enter The Name2: ";
            cin>>name2;
        }
};
class bhavna: public mahi
{
    public:
        int age1,age2;
        void putdata1()
        {
            cout<<"\n Enter Age of "<<name1<<" : ";
            cin>>age1;
            cout<<"\n Enter Age of "<<name2<<" : ";
            cin>>age2;
        }
};
class all:public bhavna
{
    public:
        void show()
        {
            cout<<"\n Name1 : "<<name1;
            cout<<"\n Age1  : "<<age1;
            cout<<"\n name2 : "<<name2;
            cout<<"\n Age2  : "<<age2;
        }
};
void main()
{
    clrscr();
    all a1;
    a1.putdata();
    a1.putdata1();
    a1.show();
    getch();
}

Here IS The OUTPUT :)


Wednesday, 14 August 2013

Hybrid Inheritance :)

#include<iostream.h>
#include<conio.h>
class parent
{
    protected:
        char f_name[20],m_name[20];
    public:
        void getdata()
        {
            cout<<"\n Enter Father Name: ";
            cin>>f_name;
            cout<<"\n Enter Mother Name: ";
            cin>>m_name;
        }
};
class child1:public parent
{
    protected:
        char ch_name1[20];
    public:
        void getdata()
        {
            parent::getdata();
            cout<<"\n Enter First Childs' Name: ";
            cin>>ch_name1;
        }
};
class child2
{
    protected:
        char ch_name2[20];
        char f1_name[20],m1_name[20];
    public:
        void getdata()
        {
            cout<<"\n Enter Father Name: ";
            cin>>f1_name;
            cout<<"\n Enter Mother Name: ";
            cin>>m1_name;
            cout<<"\n Enter Second Child Name: ";
            cin>>ch_name2;
        }
};
class son:public child1,public child2
{
    protected:
        char son_name[20];
    public:
        void getdata()
        {
            child1::getdata();
            child2::getdata();
            cout<<"\n Enter The Son's Name: ";
            cin>>son_name;
        }
        void display()
        {
            cout<<"\n Father's Name: "<<f_name;
            cout<<"\n Mother's Name: "<<m_name;
            cout<<"\n Child1's Name:  "<<ch_name1;
            cout<<"\n Father1's Name: "<<f1_name;
            cout<<"\n Mother1's Name: "<<m1_name;
            cout<<"\n Child2's Name: "<<ch_name2;
            cout<<"\n Son's Name:  "<<son_name;
        }
};
void main()
{
    clrscr();
    son m;
    m.getdata();
    m.display();
    getch();
}

Here Is The Output :)