Question: Using C + + Description There is a total of 3 questions in this assignment. For each question, write your answer in a single file

Using C++
Description
There is a total of 3 questions in this assignment. For each question, write your answer in a single file along
with the required information stated in the question. Unless otherwise specified, do not include any pre-
existing libraries in your answers. You can however write your own helper functions. Also, do not print
anything unless the question asks you to. None of these files should contain the main function.
Question 1[5 marks]
Write a function that replaces a specific digit in an int number with another digit and returns the result as
an int. Return the same number if the target/replacement character is not a digit. Use this function header:
int replaceDigits(int number, char target, char replacement)
For example:
replaceDigits(1,'1','2') should return 2
replaceDigits(-232,'3','0') should return -202
replaceDigits(123,'4','5') should return 123
replaceDigits(1223,'?','?') should return 1223
replaceDigits(5670,'5','0') should return 670(leading zero will not be part of the resulting number)
replaceDigits(30400,'0','9') should return 39499
You can assume the number does not have leading zeros (e.g., we will not call replaceDigits(01,'1','2')),
except when the number is actually zero (i.e., we might call replaceDigits(0,?'1',?'1')).
Only include the a1_question.h header file and the function definition (and your helper functions, if any)
in the source file and name it as a1_question1.c. Do not use recursion in your answer.
Question 2[5 marks]
Write a function that takes in 4 parameters: an int array, its size, the left index, and the right index; and
checks if the elements between the left and right index (inclusive) in the int array are sorted in ascending
order. If the left index is larger than the right index, swap them first. Then, if the left index is invalid (e.g.,
negative, larger than the size), use the leftmost valid index of the array; if the right index is invalid, use
the rightmost valid index of the array. Use this function header:
Assignment 1
CMPT 125 Intro. To Computing Science & Programming II
Fall 2024
bool rangedCheckforSorted(int array[], unsigned int size, int leftIndex, int rightIndex)
For example (suppose there is a myIntArray created as -4,3,-12,0,5,72,88,128,1,64):
rangedCheckforSorted(mylntArray,10,-2,3) will check indexes between 0 and 3, and return false
rangedCheckforSorted(mylntArray,10,7,2) will check indexes between 2 and 7, and return true
rangedCheckforSorted(myIntArray,10,5,5) will check indexes between 5 and 5, and return true
rangedCheckforSorted(myIntArray,10,0,9) will check indexes between 0 and 9, and return false
You can assume the array has one or more elements and the size is always correct. Content of the int
array does not change after calling this function.
Only include the a1_question2.h header file, &&3.h
Using C + + Description There is a total of 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!