Code in C++ and \"you are forbidden from using standard APIs that would otherwis
ID: 3751796 • Letter: C
Question
Code in C++ and "you are forbidden from using standard APIs that would otherwise implement Stacks, Queues, or Sorting algorithms. Any data structure used must be programmed on your own and submitted with the assignment."
a. Write a function ProblemFourA0 that reverses a string. Use an appropriate data structure, implemented by yourself but not publicly available to the client calling the API. i. Example ProblemFourA("what the?") returns ("eht tahw") Write a function ProblemFourB() that takes an int[III array of arbitrary size and finds all integers that sum to an arbitrary value. ProblemFourB( [1 2:3 41. 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 b. 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;
}
}
}
Hope you have understood the above written functions. ProblemFourC() needs more explanation. Have a good day!