C++ Program to find square and cube of a number using class and object

In this program, You will learn how to find square and cube of a number using class and object in C++.


class Test{
   //statement;
};

int main(){
  //statement;
};

C++ Program to find square and cube of a number using class and object

Example: How to find square and cube of a number using class and object in C++

#include<iostream>
using namespace std;

class Test {
public:
    int num, square, cube;

    void input() {
        cout << "Enter a number:";
        cin >> num;
    }

    void findSquare() {
        square = num * num;
    }

    void findCube() {
        cube = num * num * num;
    }

    void display() {
        cout << "Square is:" << square;
        cout << "\nCube is:" << cube;

    }
};

int main() {

    Test obj;

    obj.input();
    obj.findSquare();
    obj.findCube();
    obj.display();

    return 0;
}

Output:

Enter a number:3
Square is:9
Cube is:27