Modify the attached program by writing the following functions (please also rena
ID: 3715441 • Letter: M
Question
Modify the attached program by writing the following functions (please also rename the file to include your name). You do not need to modify the main function.
Write a sort function: This function should take 2 int parameters (passed by reference), and sort them from smallest to largest.In other words, if the 1st parameter is larger than the 2nd parameter, swap them. Otherwise, do nothing.
Write a remove2nd function: This function should take 1 int parameter and return the result of removing the 2nd digit. You may assume that the number will have at least 2 digits.For example, if you pass 3456 as a parameter, the function should return 356.
Hint: Use recursion.
Write an ascending function: This function should take 1 int parameter and return true if every digit is <= the digit to its right. Otherwise, return false.For example, 3345 is ascending but 3545 is not ascending.
Hint: 3345 is ascending because 334 is ascending AND 4 <= 5.
Sample output:
3 6
3 6
356
3345 is ascending
3545 is not ascending
#include using namespace std; // Swaps the parameters if the 1st parameter is larger than the 2nd parameter void sort(...)tI/ Fill in the parameters (don't forget to pass by reference) I Fill in // Returns the result of the removing the 2nd digit int remove2nd (int n) - // Returns true if every digit is >-the digit to its left, otherwise returns false bool ascending(int n) f int main ) t int x - 6, y- 3; sort (x, y); sort (x, y); coutExplanation / Answer
#include<iostream>
#include<cmath>
using namespace std;
void sort(int &first ,int &second)
{
int temp;
if(first > second)
{
temp=first;
first=second;
second=temp;
}
}
void isascending(int n)
{
while(n/10!=0)
{
int a=n%10;
n=n/10;
int b=n%10;
if(a<b)
{
cout<<"Not ascending";
return ;
}
}
cout<<"ascending ";
}
int remove2nd(int input)
{
int leftDivider = (int) pow(10.0, 2);
int rightDivider = (int)pow(10.0, 2 - 1);
int leftSide = input / leftDivider;
int rightSide = input % rightDivider;
return leftSide * rightDivider + rightSide;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.