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 :)


Wednesday, 7 August 2013

Strcat

#include <iostream.h>
#include<stdio.h>
#include<conio.h>
#include <string.h>
int main ()
{
    clrscr();
    char str[80];
    strcpy(str,"Hello ");
    strcat(str,"I ");
    strcat(str,"Am ");
    strcat(str,"Mahi ");
    puts(str);
    getch();
    return 0;
}

Here Is The Output :)

 

Multiple Inheritance(6)

#include<iostream.h>
#include<conio.h>
class mahi
{
    public:
        char *name;
        void put1()
        {
            name="MaHi";
        }
        void show1(void);
};
void mahi::show1()
{
    cout<<"\n 1. "<<name;
}
class bipin:public mahi
{
    public:
        void put2()
        {
            name="Bipin";
        }
        void show2(void);
};
void bipin::show2()
{
    cout<<"\n 2. "<<name;
}
class ashish:public bipin
{
    public:
        void put3()
        {
            name="Ashish";
        }
        void show3(void);
};
void ashish::show3()
{
    cout<<"\n 3. "<<name;
}
class dhananjay:public ashish
{
    public:
        void put4()
        {
            name="Dhananjay";
        }
        void show4(void);
};
void dhananjay::show4()
{
    cout<<"\n 4. "<<name;
}
class satish:public dhananjay
{
    public:
        void put5()
        {
            name="Satish";
        }
        void show5(void);
};
void satish::show5()
{
    cout<<"\n 5. "<<name;
}
void main()
{
    clrscr();
    cout<<"\n Topers"<<endl<<endl;
    satish m1;
    m1.put1();
    m1.show1();
    m1.put2();
    m1.show2();
    m1.put3();
    m1.show3();
    m1.put4();
    m1.show4();
    m1.put5();
    m1.show5();
    getch();
}

Here is The Output:))

 

Constructor : Student Marks

#include<iostream.h>
#include<conio.h>
class student
{
    protected:
        char* name;
        int rollnumber;
    public:
        student()
        {
            name="MaHi";
            rollnumber=1025;
        }
        void setnumber(int no)
        {
            rollnumber=no;
        }
        int getrollnumber()
        {
            return rollnumber;
        }
        void show1()
        {
            cout<<"\n Roll Number= "<<rollnumber;
            cout<<"\n Name= "<<name;
        }
};
class anualtest:public student
{
    protected:
        int mark1,mark2;
    public:
        anualtest(int m1,int m2)
        {
            mark1=m1;
            mark2=m2;
        }
        int getmarks()
        {
            return mark1;
            return mark2;
        }
        void show()
        {
            cout<<"\n Mark1= "<<mark1;
            cout<<"\n mark2= "<<mark2;
        }
};
void main()
{
    clrscr();
    anualtest a1(90,90);
    a1.show1();
    a1.show();
    getch();
}

Here Is The Output :))

 

Multiple Inheritance(5)

#include<iostream.h>
#include<conio.h>
class a
{
    protected:
        int m;
    public:
        void get1(int);
};
class b
{
    protected:
        int p;
    public:
        void get2(int);
};
class c:public a,public b
{
    public:
        int c;
        void display(void);
};
void a::get1(int x)
{
    m=x;
}
void b::get2(int y)
{
    p=y;
}
void c::display()
{
    c=m+p;
    cout<<"\n Addition= "<<c;
}
void main()
{
    clrscr();
    c c1;
    c1.get1(10);
    c1.get2(10);
    c1.display();
    getch();
}

Here is The Output :)


Write program of additon ♥♥♥

#include<iostream.h>
#include<conio.h>
class mahi
{
    public :
        int c;
        void add(int a,int b)
        {
            c=a+b;
            cout<<"\n"<<"   "<<c;
        }
        void getname(char *s)
        {
            cout<<"\n"<<s;
        }
};
void main()
{
    clrscr();
    mahi m1;
    m1.getname(" Addition");
    cout<<"\n";
    m1.getname("  A + B");
    cout<<"\n";
    m1.add(10,20);
    getch();
}

Here Is The Output :))


Name Return

#include<iostream.h>
#include<conio.h>
class mahi
{
    public :
        void getname(char *s)
        {
            cout<<"\n Name= "<<s;
        }
};
void main()
{
    clrscr();
    mahi m1;
    m1.getname("MaHi");
    getch();
}

Here Is The Output :)

 

Tuesday, 6 August 2013

Multiple Inheritance(4)

#include<iostream.h>
#include<conio.h>
class student
{
    public:
        int rn;
        void putn(int);
        void shown(void);
};
void student::putn(int a)
{
    rn=a;
}
void student::shown()
{
    cout<<"\n Roll Number= "<<rn;
}
class marks:public student
{
    public:
        int m1,m2,m3;
        void putm(int,int,int);
        void showm(void);
};
void marks::putm(int a,int b,int c)
{
    m1=a;
    m2=b;
    m3=c;
}
void marks::showm()
{
    cout<<"\n Marks of Basic: "<<m1;
    cout<<"\n Marks of C language: "<<m2;
    cout<<"\n Marks of Java: "<<m3;
}
class t:public marks
{
    public:
        int total,avg;
        void t1(void);
        void showt(void);
};
void t::t1()
{
    total=m1+m2+m3;
    avg=total/3;
}
void t::showt()
{
    cout<<"\n Total= "<<total;
    cout<<"\n Average= "<<avg;
}
class g:public t
{
    public:
        int grade;
        void g1(void);
};
void g::g1()
{
    if(avg>=80)
        cout<<"\n Distinction";
    else if(avg>=60 && avg<80)
        cout<<"\n First Class";
    else if(avg>=45 && avg<60)
        cout<<"\n Second Class";
    else if(avg>=35 && avg<45)
        cout<<"\n Pass Class";
    else
        cout<<"\n Fail";
}
void main()
{
    clrscr();
    g rup;
    rup.putn(331);
    rup.shown();
    rup.putm(95,95,95);
    rup.showm();
    rup.t1();
    rup.showt();
    rup.g1();
    getch();
}

Here Is The Output :)

 

Multiple Inheritance(3)

#include<iostream.h>
#include<conio.h>
class add
{
    public:
        int c;
        void put(int,int);
        void show(void);
};
void add::put(int a,int b)
{
    c=a+b;
}
void add::show()
{
    cout<<"\n Addition= "<<c;
}
class sub:public add
{
    public:
        void put1(int,int);
        void show1(void);
};
void sub::put1(int a,int b)
{
    c=a-b;
}
void sub::show1()
{
    cout<<"\n Subtraction= "<<c;
}
class mul:public sub
{
    public:
        void put2(int,int);
        void show2(void);
};
void mul::put2(int a,int b)
{
    c=a*b;
}
void mul::show2()
{
    cout<<"\n Multiplication= "<<c;
}
class div:public mul
{
    public:
        void put3(int,int);
        void show3(void);
};
void div::put3(int a,int b)
{
    c=a/b;
}
void div::show3()
{
    cout<<"\n Division= "<<c;
}
void main()
{
    clrscr();
    cout<<endl<<endl;
    div d;
    d.put(10,5);
    d.show();
    d.put1(10,5);
    d.show1();
    d.put2(10,5);
    d.show2();
    d.put3(10,5);
    d.show3();
    getch();
}

Here Is The Output :)

 

Inheritance For Loop(2)

#include<iostream.h>
#include<conio.h>
class mahi
{
    public:
        int n,i,j,k;
        void put(int);
        void loop(void);
};
class prince:public mahi
{
    public:
        void put1(int);
        void loop1(void);
};
void mahi::put(int a)
{
    n=a;
}
void mahi::loop()
{
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=i;j++)
        {
            cout<<"*";
        }
        cout<<"\n";
    }
}
void prince::put1(int b)
{
    n=b;
}
void prince::loop1()
{
    for(i=1;i<=n;i++)
    {
        for(k=1;k<=n-i;k++)
        {
            cout<<" ";
        }
        for(j=1;j<=i;j++)
        {
            cout<<"*";
        }
        cout<<"\n";
    }
}
void main()
{
    clrscr();
    prince p,p1;
    p.put(5);
    p.loop();
    p.put1(5);
    p.loop1();
    p1.put(5);
    p1.loop();
    p1.put1(5);
    p1.loop1();
    getch();
}

Here Is The Output :))


Inheritance For Loop(1)

#include<iostream.h>
#include<conio.h>
class mahi
{
    public:
        int i,j,n;
        void put(void);
        void set(int);
        void show(void);
};
void mahi::put()
{
    cout<<"\n WELCOME\n\n\n";
}
void mahi::set(int c)
{
    n=c;
}
void mahi::show()
{
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=i;j++)
        {
            cout<<" "<<"*";
        }
        cout<<"\n";
    }
}
void main()
{
    clrscr();
    mahi m1;
    m1.put();
    m1.set(5);
    m1.show();
    getch();
}

Here Is The Output :)

Sunday, 4 August 2013

Multiple Inheritance(2)

#include<iostream.h>
#include<conio.h>
class mahi
{
    public:
        int m;
        void getm(int);
};
class joshi
{
    public:
        int j;
        void getj(int);
};
class mj:public mahi,public joshi
{
    public:
        void display(void);
};
void mahi::getm(int h)
{
    m=h;
}
void joshi::getj(int v)
{
    j=v;
}
void mj::display()
{
    cout<<"\n M= "<<m;
    cout<<"\n J= "<<j;
    cout<<"\n M*J= "<<m*j;
};
void main()
{
    clrscr();
    mj m1;
    m1.getm(10);
    m1.getj(5);
    m1.display();
    getch();
}

Here Is The Output :)


Multiple Inheritance :: Student Details

#include<iostream.h>
#include<conio.h>
class pupil
{
    int rn;
    public:
        void putno(int);
        void getno(void);
};
void pupil::putno(int r)
{
    rn=r;
}
void pupil::getno()
{
    cout<<"\n Roll Number: "<<rn;
}
class marks:public pupil
{
    public:
    int guj,eng;
        void putmarks(int,int);
        void getmarks(void);
};
void marks::putmarks(int m1,int m2)
{
    guj=m1;
    eng=m2;
}
void marks::getmarks()
{
    cout<<"\n Marks Of Gujarati: "<<guj;
    cout<<"\n Marks Of English: "<<eng;
}
class result:public marks
{
    int total,avg;
    public:
        void display(void);
};
void result::display()
{
    total=guj+eng;
    avg=total/2;
    getno();
    getmarks();
    cout<<"\n Total Marks: "<<total;
    cout<<"\n Average Marks: "<<avg;
}
void main()
{
    clrscr();
    result r1;
    r1.putno(331);
    r1.putmarks(95,95);
    r1.display();
    getch();
}

Here Is The Output :)


Multiplae Inheritance: Worker Details

#include<iostream.h>
#include<conio.h>
class worker
{
    int cno;
    public:
        void putno(int);
        void getno(void);
};
void worker::putno(int c)
{
    cno=c;
}
void worker::getno()
{
    cout<<"\n Worker Number= "<<cno;
}
class money:public worker
{
    public:
    int salary,exp;
        void putmoney(int,int);
        void getmoney(void);
};
void money::putmoney(int s,int e)
{
    salary=s;
    exp=e;
}
void money::getmoney()
{
    cout<<"\n Basic Salary= "<<salary;
    cout<<"\n Expence= "<<exp;
}
class month:public money
{
    int total;
    public:
        void display(void);
};
void month::display(void)
{
    total=salary-exp;
    getno();
    getmoney();
    cout<<"\n Monthly Salary= "<<total;
}
void main()
{
    clrscr();
    month t;
    t.putno(1);
    t.putmoney(5000,1000);
    t.display();
    getch();
}

Here Is The Output :)


Private Single Inheritance

#include<iostream.h>
#include<conio.h>
class mahi
{
    int a;
    public:
        int b;
        void getdata();
        int get_a(void);
        void show_a(void);
};
class pal:private mahi
{
    int c;
    public:
        void mul(void);
        void display(void);
};
void mahi::getdata(void)
{
    cout<<"\n Enter The Value of A: ";
    cin>>a;
    cout<<"\n Enter The Value of B: ";
    cin>>b;
}
int mahi::get_a()
{
    return a;
}
void mahi::show_a()
{
    cout<<"\n A= "<<a;
}
void pal::mul()
{
    getdata();
    c=b*get_a();
}
void pal::display()
{
    show_a();
    cout<<"\n b= "<<b;
    cout<<"\n c= "<<c;
};
void main()
{
    clrscr();
    pal p;
    p.mul();
    p.display();
    p.mul();
    p.display();
    getch();
}

Here is the output :)


Inheritance Example(3)

#include<iostream.h>
#include<conio.h>
class mahi
{
    public:
        int a,b;
    void putdata()
    {
        cout<<"\n Enter The Value of A= ";
        cin>>a;
        cout<<"\n Enter The Value of B= ";
        cin>>b;
    }
    int set(void);
    int show(void);
};
class pal:public mahi
{
    public:
        int mul(int,int);
        int div(int,int);
        int display(void);
};
int mahi::set()
{
    return a;
    return b;
}
int mahi::show()
{
    cout<<"\n A= "<<a;
    cout<<"\n B= "<<b;
}
int pal::mul(int x,int y)
{
    a=x;
    b=y;
}
int pal::div(int x,int y)
{
    a=x;
    b=y;
}
int pal::display()
{
    cout<<"\n A=X= "<<a;
    cout<<"\n B=Y= "<<b;
    cout<<"\n A*b= "<<a*b;
    cout<<"\n A/b= "<<a/b;
}
void main()
{
    clrscr();
    pal p;
    p.putdata();
    p.show();
    p.display();
    getch();
}

Here is the Output :)


Constructor exp

#include<iostream.h>
#include<conio.h>
class mahi
{
    public:
        int a,b;
    mahi(int,int);
    void show()
    {
        cout<<"\n A+B= "<<a+b;
        cout<<"\n A-B= "<<a-b;
    }
}
mahi::mahi(int x,int y)
{
    a=x;
    b=y;
}
void main()
{
    clrscr();
    mahi m(10,5);
    mahi p(20,10);
    m.show();
    p.show();
    getch();
}

Here is the output :)


Friday, 2 August 2013

Single Inheritance(2)

#include<iostream.h>
#include<conio.h>
class b1
{
    public:
        int a,b;
        void setdata();
        int getdata(void);
        void show(void);
};
class d1:public b1
{
    public:
        int c;
        void display(void);
};
void b1::setdata(void)
{
    a=10;
    b=5;
}
int b1::getdata()
{
    return a;
    return b;
}
void b1::show()
{
    cout<<"\n A= "<<a;
    cout<<"\n B= "<<b;
    cout<<"\n A+B= "<<a+b;
    cout<<"\n A-B= "<<a-b;
    cout<<"\n A*B= "<<a*b;
    cout<<"\n A/B= "<<a/b;
    cout<<"\n A*A= "<<a*a;
    cout<<"\n B*B= "<<b*b;
}
void d1::display()
{
    cout<<"\n A= "<<a;
    cout<<"\n B= "<<b;
    cout<<"\n C= "<<c;
}
void main()
{
    clrscr();
    d1 d2;
    d2.setdata();
    d2.show();
    d2.c=20;
    cout<<"\n";
    d2.display();
    getch();
}

Here Is The Output :)

 

Single Inheritance: Public

#include<iostream.h>
#include<conio.h>
class b1
{
    int a;
    public:
        int b;
        void set_ab();
        int get_a(void);
        void show_a(void);
};
class d1:public b1
{
    int c;
    public:
        void mul(void);
        void display(void);
};
void b1::set_ab(void)
{
    a=5;
    b=10;
}
int b1::get_a()
{
    return a;
}
void b1::show_a()
{
    cout<<"\n A= "<<a;
}
void d1::mul()
{
    c=b*get_a();
}
void d1::display()
{
    cout<<"\n A= "<<get_a();
    cout<<"\n B= "<<b;
    cout<<"\n C= "<<c;
}
void main()
{
    clrscr();
    d1 d2;
    d2.set_ab();
    d2.mul();
    d2.show_a();
    d2.display();
    d2.b=20;
    cout<<"\n";
    d2.mul();
    d2.display();
    getch();
}

Here Is The Output :)

 

Inheritance Example(2)

#include<iostream.h>
#include<conio.h>
class joshi
{
    public:
        int a,b;
        void setdata(int x,int y)
        {
            a=x;
            b=y;
        }
        void show(int z);
};
void joshi::show(int z)
{
    cout<<"\n\t"<<z;
}
class toti:public joshi
{
    public:
        int area()
        {
            return a*b;
        }
};
class sukal:public joshi
{
    public:
        int area()
        {
            return a/b;
        }
};
void main()
{
    clrscr();
    toti t1;
    sukal s1;
    t1.setdata(10,2);
    s1.setdata(10,2);
    t1.show(t1.area());
    s1.show(s1.area());
    getch();
}

Here Is The Output :)

 

Inheritance example ♥

#include<iostream.h>
#include<conio.h>
class value
{
    protected:
        int width,height;
    public:
        void set_values(int a,int b)
        {
            width=a;
            height=b;
        }
};
class coutput
{
    public:
        void output(int i);
};
void coutput::output(int i)
{
    cout<<"\n\t"<<i<< endl;
}
class crectangle: public value, public coutput
{
    public:
    int area ()
    {
        return(width*height);
    }
};
class ctriangle: public value, public coutput
{
    public:
    int area ()
    {
        return(width*height/2);
    }
};
void main()
{
    clrscr();
    crectangle r1;
    ctriangle t1;
    r1.set_values(4,5);
    t1.set_values(4,5);
    r1.output(r1.area());
    t1.output(t1.area());
    getch();
}

Here is the output :)

 

Thursday, 1 August 2013

Randomize();

Write a program to print the name randomly from the given names

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
const int maxlength=50;
int main()
{
    char word[maxlength];
    char words[][maxlength] =
    {
        "Mahi",
        "Priyanka",
        "Pallavi",
        "Bhavna",
        "Tani"
    };
    randomize();
    clrscr();
    int n=random(5);
    strcpy(word,words[n]);

    cout<<"\n\t"<<word;
    getch();
}

Here is the output :)