Constructor with Default Arguments


#include <iostream.h>
#include<conio.h>
class real
{
        int integer_part;
        int fractional_part;
    public :
        real(int, int);
        void print_data();
};
real::real(int in, int fr=0) // Constructor with default argument
{
    integer_part = in;
    fractional_part = fr;
}
void real::print_data()
{
    cout << "Number : " << integer_part << ".";
    cout << fractional_part << "\n";
}
void main(void)
{ clrscr();
    real A1(12);
    real A2(121,34);
    A1.print_data();
    A2.print_data();
}

0 comments:

Post a Comment

 
 
 
 


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