Constructor overloading in c++

#include <iostream.h>
#include<conio.h>
class real
{
        int integer_part;
        int fractional_part;
    public :
        real(){}
        real(int a)
        {
        integer_part=a;
        fractional_part=a;
        }
        real(int a, int b)
        {
        integer_part=a;
        fractional_part=b;
        }
        void sum(real,real);
        void print_data();
};
void real::sum(real r1,real r2)
{
    integer_part=r1.integer_part+r2.integer_part;
    fractional_part=r1.fractional_part+r2.fractional_part;
}
void real::print_data()
{
    cout << "Number : " << integer_part << ".";
    cout << fractional_part << "\n";
}
void main(void)
{
    clrscr();
    real r1;
    real r2(12);
    real r3(121,34);
    r2.print_data();
    r3.print_data();
    r1.sum(r1,r2);
    r1.print_data();
    getch();
}

1 comments:

Anonymous said...

Can I simply just say what a comfort to find somebody that actually knows what they're talking about on the internet. You actually realize how to bring a problem to light and make it important. More people really need to read this and understand this side of your story. I was surprised you're not
more popular since you surely possess the gift.

My blog post: cellulite treatment cream

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|