Question

In: Computer Science

write a function named as cubeCalculator that takes an integer pointer as function and return its...

write a function named as cubeCalculator that takes an integer pointer as function and return its cube value , you are required to compute the cube of a number using pointer notation , return the result as an integer value , use c++

Solutions

Expert Solution

Program in C++

#include<iostream>
using namespace std;
int cubeCalculator(int *Ptr )
{
*Ptr = *Ptr * *Ptr * *Ptr; // calculate cube of number
return *Ptr; // return cube
}

int main()
{
int number;
cout<<"Enter the number"<<endl;
cin>>number; // enter number
int cube=cubeCalculator( &number ); // call function by reference
   cout<<"Cube of number is : "<<cube;// print cube
return 0;

}

#include<iostream>
using namespace std;
int  cubeCalculator(int *Ptr )
{
   *Ptr = *Ptr * *Ptr * *Ptr; // calculate cube of number
    return *Ptr; // return cube
}

int main()
{
    int number;
    cout<<"Enter the number"<<endl;
    cin>>number; // enter number
    int cube=cubeCalculator( &number ); // call function by reference
        cout<<"Cube of number is : "<<cube;// print cube
    return 0;

}

Output 1:

Output 2:


Related Solutions

Write a function named hasNValues which takes an array and an integer n as arguments. It...
Write a function named hasNValues which takes an array and an integer n as arguments. It returns true if all the elements of the array are one of n different values. If you are writing in Java or C#, the function signature is int hasNValues(int[ ] a, int n) If you are writing in C or C++, the function signature is int hasNValues(int a[ ], int n, int len) where len is the length of a Note that an array...
In MATLAB define a function named primes that takes a non-negative integer, ?, as its only...
In MATLAB define a function named primes that takes a non-negative integer, ?, as its only argument and returns a row vector containing the first ? prime numbers in order. Assume that the first prime number is 2.  Other than the zeros function, the ones function, and the colon (:) operator, you may not use any Matlab built-in array functions.
Write a function named mirror_tree that accepts a pointer to the root of a binary tree...
Write a function named mirror_tree that accepts a pointer to the root of a binary tree of integers. Your function should rearrange the nodes into a mirror tree of the original tree. The mirror tree has the left and right subtrees reversed for each node. Constraints: You must implement your function recursively and without using loops. Do not construct any new BST objects in solving this problem (though you may create as many NODE* pointer variables as you like). Do...
Create a function output() in C that takes the pointer to the array and its size...
Create a function output() in C that takes the pointer to the array and its size and prints the arrays' contests. (function prototype : void output(int *arrayPtr, int size);
C++ Write a toVector function that takes in a C-style pointer of any type and a...
C++ Write a toVector function that takes in a C-style pointer of any type and a size (int) and returns a vector of the same size containing a copy of the elements in the input array. You may assume that the array elements have a valid copy constructor. Please explain every line of code to me
C++ Write a toVector function that takes in a C-style pointer of any type and a...
C++ Write a toVector function that takes in a C-style pointer of any type and a size (int) and returns a vector of the same size containing a copy of the elements in the input array using a template. You may assume that the array elements have a valid copy constructor. Please explain every line of code to me
Write a function convert_date that takes an integer as a parameter and returns three integer values...
Write a function convert_date that takes an integer as a parameter and returns three integer values representing the input converted into days, month and year (see the function docstring). Write a program named t03.py that tests the function by asking the user to enter a number and displaying the output day, month and year. Save the function in a PyDev library module named functions.py A sample run for t03.py: Enter a date in the format MMDDYYYY: 05272017 The output will...
(C++) Write a function that takes as an input parameter an integer that will represent the...
(C++) Write a function that takes as an input parameter an integer that will represent the length of the array and a second integer that represents the range of numbers the random number should generate (in other words, if the number is 50, the random number generator should generate numbers between 0 and 49 including 49. The function then sorts the list by traversing the list, locating the smallest number, and printing out that smallest number, then replacing that number...
Question: Write a method named reduce that: ● Takes a function of type (A, A) =>...
Question: Write a method named reduce that: ● Takes a function of type (A, A) => A ● Returns A ● Combines all the elements of the list into a single value by applying the provided function to all elements ○ You may assume the function is commutative ● If the list has size 1, return that element without calling the provided function Example: If head stores a reference to the List(4, 6, 2) head.reduce((a: Int, b: Int) => a...
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should...
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should display if the argument "is a multiple of 5" or "is not a multiple of 5".
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT