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

Use C++ instructions as 1b. 4. Problem Solving. Write a function ProblemFourA()

ID: 3752365 • Letter: U

Question

Use C++

instructions as 1b. 4. Problem Solving. Write a function ProblemFourA() that reverses a string. Use an appropriate data structure, implemented by yourself but not publicly available to the client calling the API a. i. Example ProblemFourA("what the?") returns ("eht tahw") b. Write a function ProblemFourB() that takes an int[ll array of arbitrary size and finds all integers that sum to an arbitrary value. ProblemFourB( [1 2;3 4], 5) should return (2,3) and (1,4). Design an algorithm that can be called with ProblemFourC that uses one of the data structures we've discussed so far to find the Nth smallest number that takes the form c. i. Example ProblemFourC(0) returns 1, ProblemFourC(1) returns 7, and so forth.

Explanation / Answer

1. ProblemFourA() - Reversing a string :

The below program is used to reverse a string, by swaping the characters

through a loop.

char* ProblemFourA(char* string)

{

int i,n;

char temp;

n = strlen(string); //to find the length of the given string

for(i=0; i<=(n/2) ;i++)

{

temp = string[i];

string[i] = string[n-i-1];

string[n-i-1] = temp;

}

return string;

}

2. ProgramFourB() - All integers that sum to an arbitrary value :

The below implemented code calculates the pair of integers that sum to

an arbitrary value.

void addOtherElements(int mat[][10], int element, int arbitrary, int r, int c); // prototype

void ProgramFourB(int mat[][10], int arb, int rowsize, int colsize)

{

int i,j;

for(i=0; i<rowsize; i++)

{

for(j=0; j<colsize; j++)

{

addOtherElements(mat, mat[i][j], arb, rowsize, colsize);

}

}

}

void addOtherElements(int mat[][10], int element, int arbitrary, int rowsize, int colsize)

{

int i,j,sum;

for(i=0; i<rowsize; i++)

{

for(j=0; j<colsize; j++)

{

sum = mat[i][j] + element;

if(sum == arbitrary)

cout<<"("<<element<<","<<mat[i][j]<<")"<<endl;

}

}

}

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