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...
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, 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".
Implement a function named printRange that, given the pointer to the root of a BST, a...
Implement a function named printRange that, given the pointer to the root of a BST, a low key value, and a high key value, prints in sorted order all records whose key values fall between the two given keys (inclusive). Function printRange should visit as few nodes in the BST as possible. Here is the start code (in Java 8) for this problem. Input Format Three lines. The first line includes the number of keys to be put in the...
In R studio Write a function that takes as an input a positive integer and uses...
In R studio Write a function that takes as an input a positive integer and uses the print() function to print out all the numbers less than the input integer. (Example: for input 5, the function should print the numbers 1,2,3,4 { for input 1, the function should not print a number.) Use the lapply function, do not use any of the loop commands in your code.
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++, using pass by reference
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++
Write a function named "characters" that takes a string as a parameter and returns the number...
Write a function named "characters" that takes a string as a parameter and returns the number of characters in the input string
In C++ Create a dynamic array of 100 integer values named myNums. Use a pointer variable...
In C++ Create a dynamic array of 100 integer values named myNums. Use a pointer variable (like ptr) which points to this array. Use this pointer variable to initialize the myNums array from 2 to 200 and then display the array elements. Delete the dynamic array myNums at the end. You just need to write part of the program.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT