Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise Write a function called reverseInt which takes one integer parameter an

ID: 3844968 • Letter: E

Question

 Exercise  Write a function called reverseInt which takes one integer parameter and changes the  value of this integer parameter to the reverse of the integer.  trace  void function1(int& i, int j){ //What have been passed into these parameters?   if ( i % 3 == 0 || i % 4 != 0 ) i = 5;  //What does this line mean?  Is i changed? Does it affect any other variables?   else i = 2;  // Is i changed here? Does it affect any other variables?   j = 10; //Does this line affect any other variable besides j? } int main (){   int x = 0, y = 0;   while (x <= 10) x += 10; //what does this loop do? What happen to x?   cout << x << " " << y << endl; //What is the output of this line?   function1(x, y); //What is this line?   cout << x << " " << y << endl; //What is the output?   return 0; } Recursive Functions: Write a recursive function countEven that returns the count of even digits in the integer parameter.  Write a recursive function removeEven that returns a new number with all the even digits removed from the integer parameter.  Write a recursive function hasEven that returns true if the integer parameter contains an even digit, false otherwise. 

Explanation / Answer

1. reverseInt frunction is as follows: -

void reverseInt(int n) {
   int reversedNumber = 0, remainder;
   while(n != 0)
{
remainder = n%10;
reversedNumber = reversedNumber*10 + remainder;
n /= 10;
}
cout << "Reversed Number = " << reversedNumber;
}

2. Your explanation is added as comments; -


void function1(int& i, int j){ //a reference to integer i by pass by reference, and integer j using pass by value
if ( i % 3 == 0 || i % 4 != 0 ) i = 5; //if number is multiple of 3 and not 4 , then the value of i is changed to 5.
else i = 2; // if it is not multiple of 3 or is multiple of 4, then the value of i is changed to 2
j = 10; // value of j is changed, other than that no value is changed
}
int main (){
int x = 0, y = 0;
while (x <= 10) x += 10; // the loop runs till value of x becomes 10 by incrementing value of x by 10 in each iteration. at the end value of x becomes 20
cout << x << " " << y << endl; //Output: 20 0
function1(x, y); //this line will call the function function1 with parameters x and y.
cout << x << " " << y << endl; //Output: 2 0
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote