Question

Use only C++ for all function Introduce a call-by-value function that computes the volume of a...

Use only C++ for all function

Introduce a call-by-value function that computes the volume of a box. Hint: Length, width, and height of a box is needed.

Introduce a call-by-reference function with void output. that computes the square of an integer. Please double check the value of the function input before and after function call.

Introduce a call-by-pointer function with void output. that computes the square of an integer. Please double check the value of the function input before and after function call.

Introduce an integer vector. Then introduce a function to reverse this vector. (Do not use reverse library provided by C++.

Introduce an integer vector. Then introduce a function to check whether this vector is palindrome. If yes, please return true. If not, please return false.

Read the following code and see whether you can interpret/understand the results. Copy the code to your IDE. Use debugger to see the if the result is the same as your interpreted results.
int a = 5; //assume that a is located at 1000. a’s pointer is located at 5000

int &b = a; a = 10;

cout<<&b<<endl;

int *c = &b;

cout<<c<<endl;

int** cPtrPtr = &c;

cout<<*c<<endl;

cout<<cPtrPtr<<endl;

int d = 20; int* dPtr = &d;

int** dPtrPtr = &dPtr;

dPtr= *cPtrPtr;

cout<<*dPtr<<endl;

cout<<dPtrPtr<<endl;

cout <<d<<endl;

Introduce a main function that calls all the functions above

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code

#include<bits/stdc++.h>
using namespace std;
double calVolume(double len,double wid,double height){
   return len*wid*height;
}
void squrr(int &x){
   x=x*x;
}
void squrp(int *x){
   *x=*x*(*x);
}
void rev(std::vector<int> &v){
   int i=0,n=v.size()-1;
   while(i<=n){
       swap(v[i],v[n]);
       i++;
       n--;
   }

}
bool ispali(std::vector<int> &v){
   int i=0,n=v.size()-1;
   while(i<=n){
       if(v[i]!=v[n]){
           return false;
       }
       i++;
       n--;
   }

   return true;

}
int main(){
cout<<"volume ="<<calVolume(1,2.3,5)<<endl;
int x=2;
cout<<"x= "<<x<<endl;
squrr(x);
cout<<"x= "<<x<<endl;
squrp(&x);
cout<<"x= "<<x<<endl;
std::vector<int> v1={1,2,3,4,5};
rev(v1);
for(auto i:v1){
    cout<<i<<" ";
}
cout<<endl;
std::vector<int> v={1,2,2,1};
cout<<(ispali(v)?"palindrome": "not palindrome")<<endl;
  
}

screenshot

sample output

output question explanation:

cout<<&b<<endl; // print address a of ie 1000

cout<<c<<endl; // print pointer c which store address of a

cout<<*c<<endl;    //prints value of a   

cout<<cPtrPtr<<endl; // prints 5000 ie address of pointer of a


cout<<*dPtr<<endl; // prints address of d

cout<<dPtrPtr<<endl; // prints address of dptr

cout <<d<<endl; // prints value of d

please upvote if it helped. Feel free to ask any query.

Add a comment
Know the answer?
Add Answer to:
Use only C++ for all function Introduce a call-by-value function that computes the volume of a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ only : Use an integer pointer returning function which would determine the sum of square...

    C++ only : Use an integer pointer returning function which would determine the sum of square of each of two integer pointer variables used as argument of the function. Call the function in the main() using pointer variables and dynamic allocation Question 4: Print both the strings using string double-pointer only in the main() void print(string ** s){ **s = "University of Oregon"; cout<< **s <<endl; } void print(string *x){ *x = "Portland"; cout<<*x<<endl; }

  • 81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5...

    81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5 );                    int BoxVolume(int length = {1}, int width = {1}, int height = {1});                                                     T__   F__                                                                     82. The following function is implemented to swap in memory the          argument-values passed to it:         void swap(int a, int b)                   {           int temp;             temp = a;             a = b;             b = temp;        ...

  • c++ please no global varaible write a value returning function input data to dynamically allocate a...

    c++ please no global varaible write a value returning function input data to dynamically allocate a short array of size elements and store the input data entered from the disk file into array.Return the base address of the array allocated.Read the data from the text file Hello.txt and store the data in reverse order in the array.the size of the data set will be in the file size 10 and the data was 1 2 3 4 5 6 7...

  • C++ Write a recursive function that reverses the given input string. No loops allowed, only use...

    C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. #include <iostream> #include <string> using namespace std; //Write a recursive function 'void reverse(string &str)' that reverses the given input string. void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sherry";    reverse(name);    cout << name << endl; //should...

  • C++ Create a program that finds the dot product of two vectors. I'm currently trying to...

    C++ Create a program that finds the dot product of two vectors. I'm currently trying to display the dot product by calling the dotProduct member function however I am confused as to how to do this. What would be the proper way to display the dot product? I don't believe my dotProduct member function is set up correctly to access the proper data. Feel free to modify the dotProduct member function to allow for it to work with the other...

  • c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input:...

    c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input: an int output: boolean function: Return true if the number is a prime number and return false otherwise */ //TO DO ************************************** /* Write a function checkPrime such that input: an array of int and size of array output: nothing function: Display the prime numbers of the array */ //TO DO ************************************** /* Write a function SumofPrimes such that input: an int output: nothing...

  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

  • answer in c++ Using the table below, complete the C++ code to write the function prototype...

    answer in c++ Using the table below, complete the C++ code to write the function prototype statement, and the void function header. The void function should receive three double variables: the first two by value and the last one by reference. Name the formal parameters num1, num2 and answer. The function should divide the num1 variable by the num2 variable and then store the result in the answer variable. Name the function calcQuotient. Also write an appropriate function prototype for...

  • Consider the following C++code snippet and what is the output of this program? # include<iostream> using...

    Consider the following C++code snippet and what is the output of this program? # include<iostream> using namespace std; void arraySome (int[), int, int); int main () const int arraysize = 10; int a[arraysize]-1,2,3,4,5, 6,7,8,9,10 cout << "The values in the array are:" << endl; arraySome (a, 0, arraySize) cout<< endl; system ("pause") return 0; void arraySome (int b[], int current, int size) if (current< size) arraySome (b, current+1, size); cout << b[current] <<""; a) Print the array values b) Double...

  • Hi!, having trouble with this one, In this class we use visual studio, C++ language --------------------------------------------------------------...

    Hi!, having trouble with this one, In this class we use visual studio, C++ language -------------------------------------------------------------- Exercise #10 Pointers - Complete the missing 5 portions of part1 (2 additions) and part2 (3 additions) Part 1 - Using Pointers int largeArray (const int [], int); int largePointer(const int * , int); void fillArray (int * , int howMany); void printArray (const char *,ostream &, const int *, int howMany); const int low = 50; const int high = 90; void main()...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT