146k views
5 votes
A variable like user_num can store a value like an integer. Extend the given program as indicated. Output the user's input. (2 pts) Output the input squared and cubed. Hint: Compute squared as user_num * user_num. (2 pts) Get a second user input into user_num2, and output the sum and product. (1 pt)

1 Answer

6 votes

Answer:

The answer to this question is given below in the explanation section. It is noted that this program is written in C++ using online C++ compiler.

Step-by-step explanation:

#include <iostream>

using namespace std;

int squared(int num)// this is the function to compute square

{

return num*num;

}

int cube(int num)// this is the function to compute cube

{

return num*num*num;

}

int main()

{

int user_num, user_num2; // variable declaration

cout<<"Enter the first number: ";//prompt user to enter the number

cin>>user_num;//store the user entered number into variable

cout<<"\\Enter the second number: ";//prompt the user to enter the second number

cin>>user_num2;//store the user entered number into variable

cout<<"\\Squared of first number is: "<<squared(user_num);//compute square of user_num and display

cout<<"\\Cube of first number is: "<<cube(user_num);//compute the cube of the user_num and display

cout<<"\\Square of second number is: "<<squared(user_num2);//compute the square of user_num2 and display

cout<<"\\Cube of second number is: "<<cube(user_num2);//compute the cube of user_num2 and display

cout<<"\\Sum of number 1 and number 2 is: "<<user_num2 + user_num2;//display the sum of user_num2 and user_num

cout<<"\\Product of number 1 and number 2 is: "<<user_num2 * user_num;//display the product of user_num and user_num2

return 0;//terminate the program

}

User Refilon
by
4.7k points