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 treble that takes a pointer to an integer and triples its value. Note...
Write a function treble that takes a pointer to an integer and triples its value. Note that this function does not return anything. You can test it using the following example or something similar: int i=7; cout << "old value; i="<<i<< "-" treble(&i);cout <<"New Value:i="<< i <<"\n"; Which prints: Old vvalue:i =7 - new value: i=21
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...
in Python3 The ord function in Python takes a character and return an integer that represents...
in Python3 The ord function in Python takes a character and return an integer that represents that character. It does not matter what the integer representing the character actually is, but what matters is this: ord('a') is 1 less than ord('b'), so that: x=ord('a') thisLetter = x+1 # thisLetter is the ord('b') This is a powerful fact that is used in encryption techniques, so data transferred over the web is 'ciphered so it is unreadable to others. To decipher data,...
(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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT