Saturday, 23 March 2019

CPP-EX35

Write a C++ program using class to calculate square and cube of given number using inline function.

#include<iostream.h>
#include<conio.h>
#include<math.h>
class math
{
    int x;
    public: void accept(int a)
    {
         x=a;
    }
    inline int sqr()
    {
        return(x*x);
    }
    inline int cube()
    {
        return(x*x*x);
    }
};

int main()
{
    clrscr();
    math m;
    m.accept(2);
    cout<<"Square of the no.:";
    cout<<m.sqr()<<"\n";
    cout<<"Cube of the no.:";
    cout<<m.cube()<<"\n";
    getch();
    return(0);

}