Question: You will implement a C + + program to add integers into a dynamic array class that you will create. You must use a dynamic

You will implement a C++ program to add integers into a dynamic array class that you will create. You must use a dynamic array class (no vectors or other containers). You will also need to create 4 recursive functions inside that dynamic array class based on the commands given in the command file. This homework will focus on dynamic array implementation and recursive techniques. When submitting this assignment, please name the folder on the server as "hw1".
2. Input Files
- The input file will have the size of the array on the first line and a list of integers separated by a comma on the second line.
Example input:
5
1,2,3,4,5
- While reading the input, In and \(\backslash r \) should be removed before processing the string of integers.
3. Command Files
- There will be 4 types of commands you will have to implement as functions in your dynamic array class. These must be recursive. They are: AddNums, FindNum, Replace, IsSorted, Print.
- AddNums(index)
- The AddNums command will be followed by an integer inside the parenthesis (representing the number of first elements you should add). For example:
\[
\text { Array }=[1,2,3,4,5,6]
\]
AddNums(3) should output "6" to the output file as \(1+2+3=6\).
- If the Index \(=0,0\) should be outputted as we are adding the first 0 elements.
- If the index >= size of the array, "Invalid index" should be outputted.
- FindNum(target)
- The FindNum function should output "true" or "false" depending on if the target element is inside the array.
- Replace(value, newvalue)
- The Replace function replaces "value" in the array with "newvalue". If "value" is not found in the array, output "(value) is not in the array" (view example section below).
For example:
Array \(=[32,4,20,40,10]\)
Replace \((20,22)\)
\[
\text { Array }=[32,4,22,40,10]
\]
- IsSorted
- The IsSorted function outputs "true" or "false" depending on if the array was input sorted or not.
- Print
- The Print function prints the array to the output file. This will need to be the same as when inputted in the input.txt file. (see example below)
Example:
- The command file can be empty
- While reading the command file, In and Vr should be removed before processing the string.
4. Output Files
- The output file must match exactly with the answer file for credit to be awarded. Be sure to check for small things like leading spaces and newline characters.
Input file contents example:
6
30,12,14,100,50,76
Command File example:
AddNums(7)
AddNums(4)
IsSorted
Replace(10,100)
Expected Output File For this Example:
Invalid index
156
false
(10) is not in the array
You will implement a C + + program to add

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!