Showing posts with label Inline Function. Show all posts
Showing posts with label Inline Function. Show all posts

Monday, April 17, 2017

C++ code for finding the Cube of a Number using Inline Function

This is the solution for finding Cube of a given number using Inline Function in C++ (T.U. 2066)

#include <iostream>

using namespace std;

class cube
{
    int a, acube;
public:
    void geta();
    inline void cubea();
    void show();
};

void cube::geta()
{
    cout << endl << "Enter a number:" ;
    cin >> a ;
}

void cube::cubea()
{
    acube = a*a*a ;
}

void cube::show()
{
    cout << endl << "Entered number(a)=" << a << endl << "Cube of a=" << acube << endl ;
}


int main()
{
    cube c1;
    c1.geta();
    c1.cubea();
    c1.show();
    return 0;
}

C++ code for finding the Square of a Number using Inline Function

This is the solution for finding Square of a number using Inline Function (T.U. 2067, 2068)

#include <iostream>

using namespace std;

class square
{
    int a, asqr ;
public:
    void geta();
    inline void squarea();
    void print();
};

void square::geta()
{
    cout << endl << "Enter a:" ;
    cin >> a ;
}

void square::squarea()
{
    asqr = a*a ;
}

void square::print()
{
    cout << endl << "Entered number(a)=" << a << endl << "Square of a=" << asqr << endl ;
}

int main()
{
    square s1;
    s1.geta();
    s1.squarea();
    s1.print();
    return 0;
}