Search & Find out

Sunday, December 6, 2009

Adding two numbers using single level inheritance


#include "iostream.h"
#include "conio.h"
class one
{
    private:
        int c;
    protected:
        int a,b;
    public:
        void cal ();
};
class two : public one
{
    public:
        void accept ()
        {
            cout << "Welcome to add two no.s using single inheritance\n\n";
            cout << "Enter 2 numbers: ";
            cin  >> a >> b;
        }
};
void one :: cal ()
{
    c = a + b;
    cout << "Sum = " << c;
}
void main ()
{
    clrscr ();
    two T;
    T.accept ();
    T.cal ();
getch ();
}



Get the executable ( .exe ) file for this program..
Download

0 comments:

Post a Comment

 

My Blog List

Term of Use