Question: from question 5 to 14 that is where i am having problems 4. Function IsPrime: A prime number is a natural number greater than 1

 from question 5 to 14 that is where i am having
problems 4. Function IsPrime: A prime number is a natural number greater
than 1 (natural numbers include 2, 3, 4, 5....) that is not
divisible by any positive number other than itself and 1. For example,
2 and 3 are both prime but 4 is not. Write a
function isPrime that takes an unsigned integer to Test as an input
parameter and returns O if the value is not prime and 1
if it is prime. You will do this by checking all values
2 to to Test and seeing if to Test is evenly divided
by that number. Next, write a function is PrimeWhile that takes the
from question 5 to 14 that is where i am having problems

4. Function IsPrime: A prime number is a natural number greater than 1 (natural numbers include 2, 3, 4, 5....) that is not divisible by any positive number other than itself and 1. For example, 2 and 3 are both prime but 4 is not. Write a function isPrime that takes an unsigned integer to Test as an input parameter and returns O if the value is not prime and 1 if it is prime. You will do this by checking all values 2 to to Test and seeing if to Test is evenly divided by that number. Next, write a function is PrimeWhile that takes the same input parameter as isPrime and returns the same result. IsPrime and isPrimeWhile should be identical EXCEPT you will write a while loop instead of a for loop to do the same actions. Make sure you add a function header comment describing each of the functions. 5. Create an array inventory . Write a single line comment with the title and description of the current task. 4. Create an array inventory Greate an array of integers called anvent that contains 10 values. but make it so it could be more. The number 10 should only occur once in all of your code. Given that we haven't touched arrays in full, please ask your TAs if you aren't sure how to do this Initialize the values (you can pick the values in a loop (that's the point of this lab) o Compile, run and test your code complex Equations.. Python: Convert hei 6. Print out the values in inventory . . Create a new function called printinventory that takes the inventory array and the size of the array. The parameters could look something like int* inventory and int invSize If pointers are confusing you or we haven't covered them enough in class, feel free to not use a function. Make sure you add a function header describing the function. Write a single line comment with the title and description of the current task. Using a FOR loop, print all the value of inventory Each value should be separated by a space (not a new line). . I 3 Campile run and test your code. 7. Fill inventory with values from the user The code for this section should go in between Step 4 and 5 in your file Write a single line comment with the title and description of the current task using a FOR loop,read values from the user and write them in your inventory, one at a time . Write a single line comment with the title and description of the current task. Using a FOR loop, read values from the user, and write them in your inventory, one at a time. . Compile, run and test your code. 8. (optional) "Refactor" the inventory filling code to be in a new function called fillinventory. . Fill inventory should receive the inventory and the size of the inventory as parameters. Make sure you add a function header (you can just move your comment but it's a good practice to add more information). 9. Search for a specific value & print index when found . Write a single line comment with the title and description of the current task OR (better) make a new function called findValue If you are confused by pointers then DO NOT write findValue. Create a variable called me Initialize it to a number in the invento Using a FOR loop, search for this value in the inventory If you find it, print the index where it was found You should not stop the loop if you find the value. If you are writing findValue (which is great practicel then you set value and send it to find Value Typically would have a function findldx and another function printidx. HOWEVER, since we want to return alt indexes with that value, we are combining this into one function findValue find Value can take the value the inventory and the inventory size as parameters. It should then return the last index that has contents naualto value write a set of numbers (e.g. 4 numbers). That's your array. Write one of those numbers to the side. That's your search value. 4 if you go one number at a time in your set, how can you determine if it's the value you are searching for? Compile, nin and test your code If you don't find it, print out a message indicating so. To do this, create a int variable called dix. Initialize it to 1. If you find the value, change founded to the index/position in the array After the loop. check the value of the and display a message appropriately if foundlux is still Compile run and test your code. Change the content of Test other values in inventory. Testa value not in Inventory Does it behave correctly in inventory, intimitet with two identical th for at value Dos bens In inventory, initialize it with two identical values. Search for that value. Does your code behave correctly? It should output both indexes. 10. While loops: finding the index Finally wrap your "find an index" code in a while loop (or a do while loop). The while loop should continue to ask users for a number for value and should only stop once value can be found in the inventory. 11. Search for a value set by the user Let's modify the code so the user can identify what value they want to search for Locate in your code where you created the variable value. After that line, ask and receive what value the user wants to search. Compile, run and test your code: 12. Search for multiple values The user might want to search for multiple values Let's modify the search part to keep asking for a new number to search until they enter a negative number Create a DO WHILE loop encompassing this code and the search loop below. The do-while loop should check if value is smaller than zero. If the value is positive (or equal to 0), then continue Compilerin and test your code 13. Search for maximum value in Inventory . O 0 Write a single line comment with the title and description of the current task. Find the max in a set of numbers and print the value and index Create a variable to remember the current maximum number (max) Initialize the current maximum to the first value in the array. Create a variable to remember the current maximum number's index (index) & initialize it. Use a loop (you can pick which kind, but a FOR loop is probably best) Use a control statement to check if the current value is larger than the current max. If so, remember the current value. Remember the current index well. At the end of the loop, print out the max value and index. 0 Compile, run and test your code. Does it work if your max is the first value? A middle value? The last value 14. Search for minimum value in inventory Write a single line comment with the title and description of the current task. Find the min in a set of numbers and print the value and index . Compile, run and test your code. Does it work if your min is the first value? A middle value? The last value 15. 2D array . Write a single line comment with the title and description of the current task. Let's create a character array. You can copy the following declaration and initialization: char abc[2][2] = {{'z', 'a'}, {'b', 'c'}}; This is a 2D array of characters: it's basically a 2x2 matrix. We're storing a few letters in it. abc[0][1] abc[0][0] abc[1][0) abc[1][1] 2 b G Write 2 nested for loops to print out the content of abc use the counter i for the outer loop, and the counter for the inner loop. Print the content of each cell by accessing the element like this. abc[i][j]. The content should be displayed all in a row. With a space in between Print a new end of line inside the body of the outer loop, after you've completed the inner loop This shou allow you to print the mate more nicely with rows and columns compilpun and test your code 15. 2D array . Write a single line comment with the title and description of the current task. Let's create a character array. You can copy the following declaration and initialization: char abc[2][2] = {{'z', 'a'}, {'b', 'c'}}; This is a 2D array of characters: it's basically a 2x2 matrix. We're storing a few letters in it. abc[0][0] abc[0][1] abc[1][0] abc[1]11) 2 a b G Write 2 nested for loops to print out the content of abc Use the counter i for the outer loop, and the counter for the inner loop. Print the content of each cell by accessing the element like this: abc[i][jl, The content should be displayed alt in a row with a space in between Print a new end of line inside the body of the outer loop, after you've completed the inner loop This should allow you to print the mateix more nicely, with rows and columns Come on and test your code

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 Databases Questions!