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

Write a function called reverseInt which takes one integer parameter and changes

ID: 3844941 • Letter: W

Question

 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: 1.Write a recursive function countEven that returns the count of even digits in the integer parameter.  2.Write a recursive function removeEven that returns a new number with all the even digits removed from the integer parameter.  3.Write a recursive function hasEven that returns true if the integer parameter contains an even digit, false otherwise. 

Explanation / Answer

1.Program:


#include <iostream>
#include <string>
using namespace std;
class Rec
{
public:
int x;
int Even=0;
int countEvenDigits(int num)
{
  
x=num%10;
if(x%2==0)
{
Even++;
}

num=num/10;
  
if(num!=0)
countEvenDigits(num);
  
return Even;   
}

};
int main()
{
int val,count;
Rec obj;
cout<<"Enter a number ";
cin>>val;
count=obj.countEvenDigits(val);
cout<<"No of Even Digits are "<<count;
}

Output:

Enter a number 243

No of Even Digits are 2

2. Progarm:

#include <iostream>
#include <string>
using namespace std;
class Rec
{
public:
int x;

string val="";


string removeEven(int num)
{
  
x=num%10;
//cout<<x;
if(x%2!=0)
{
  
  
  
val.append(to_string(x));
}

num=num/10;
  
if(num!=0)
removeEven(num);

return val;   
}

};
int main()
{
int val;
string value;
Rec obj;
cout<<"Enter a number ";
cin>>val;
value=obj.removeEven(val);

int n = value.length();
  
for (int i=0; i<n/2; i++)
swap(value[i], value[n-i-1]);
cout<<value;

}

Output:

Enter a number

783

73

3.Program:

#include <iostream>

#include <string>
using namespace std;
class Rec
{
public:
int x;

bool val=false;
bool returnTrueForEven(int num)
{

x=num%10;
if(x%2==0)
{
val=true;
}


num=num/10;
  
if(num!=0)
returnTrueForEven(num);
  
  
return val;   
}

};
int main()
{
int val;
bool value;
Rec obj;
cout<<"Enter a number ";
cin>>val;
value=obj.returnTrueForEven(val);
cout<<"IS Even Digit Exists 0-> False 1-> True "<<value;
}

Output:

Enter a number 999

IS Even Digit Exists

0-> False 1-> True

0

Enter a number 246

IS Even Digit Exists

0-> False 1-> True

1

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