1. Introduce a call-by-value function that computes the volume of a box. Hint: L
ID: 3881800 • Letter: 1
Question
1. Introduce a call-by-value function that computes the volume of a box. Hint: Length, width, and height of a box is needed. 2. 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. 3. 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. 4. Introduce an integer vector. Then introduce a function to reverse this vector. (Do not use reverse library provided by C++ 5. 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. 6. Read/run the following code and see whether you can interpret/understand the results Demo how to use debugger to see the result int a = 5; //assume thata is located at 1000· a's pointer is located at seee int &b; = a; a 10; coutExplanation / Answer
1)
/*call by value to find volume of box*/
#include<iostream.h>
void volume(int ,int ,int);
void main()
{
int length,breadth,height;
cout<<”Enter the length of box:”<<” ”;
cin>>length;
cout<<”Enter the breadth of box:”<<” ;
cin>>breadth;
cout<<”Enter the height of box:”<<” ”;
cin>>height;
volume(length,breadth,height);
}
void volume(int l,int b,int h)
{
int volume;
volume=l*b*h;
cout<<”Volume of box=”<<volume<<” ”;
}
2)
/*call by reference to find square of integer*
#include<iostream.h>
void square(int &);
void main()
{
int integer;
cout<<”Enter the integer:”<<” ”;
cin>>integer;
square(&integer);
}
void square(int &n)
{
int square;
square=n*n;
cout<<”Square of Integer=”<<square<<” ”;
}
3)/*call by pointer to find square of integer*
#include<iostream.h>
void sqr(int *);
void main()
{
int integer1,*ptr;
cout<<”Enter the integer:”<<” ”;
cin>>integer1;
ptr=&integer1;
cout<<”Integer value in Main function=:”<<integer1<<” ”;
sqr(ptr);
}
void sqr(int *n)
{
int square1;
square1=n*n;
cout<<”Integer value in Square function=:”<<*n<<” ”;
cout<<”Square of Integer=”<<square1<<” ”;
}
4) and 5)
/*To find reverse of integer and check if its palindrome*/
#include<iostream.h>
void main()
{
int i,n,rem,rev;
cout<<”Enter an integer:”<<” ”;
cin>>n;
i=n;
rev=0;
while(n!=0)
{
Rem=n%10;
Rev=rev*10+rem;
N=n/10;
}
cout<<”The reverse of integer=”<<rev<<” ”;
if(rev==i)
cout<<”The integer is Palindrome”<<” ”;
else
cout<<”Not Palindrome”<<” ”;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.