CMPS-2020 Programming II: Data Structures and Algorithms
Lab-12
Log-in to the Odin server. Required: All work for this lab must be done on the Odin server. Do your work in your Odin 2020/c/ folder. You will be modifying some existing programs. See below.
Start with your pairs.cpp program. Copy it to a program named 2020/c/trips.cpp Instead of finding pairs of numbers in an array, you will be looking for triples, three consecutive numbers together in an array. 1. Your program will use a recursive function to count the triples. For example, the array { 1, 2, 3, 3, 3, 5, 6, 7, 8 } has 1 triple. ------- 2. Like your pairs program, fill an array with random 1-digit numbers. Here's how it is different... a. Check your array for the count of triples. b. If there are no triples found, fill the array again with different random numbers and check it again. Do this inside a loop. Stop looping only when you have found an array with 1 or more triples. c. Display the array after exiting the loop. Show a count of how many tries it took. program output might look like this...Lab-12 find triples in an array. Array size? 20 Searching for triples now... Found an array with 2 triples! Array is: 7 8 4 7 5 1 1 1 4 8 3 0 8 4 7 7 7 8 1 0 That took 451 tries.
Write a program named: 2020/c/sortword.cpp This program is similar to the halves.cpp program you wrote. Your word will be divided until each individual letter is a division. Then the divisions will be merged back together. 1. Ask the user to enter a word. 2. Sort the letters of the word in alphabetical order. Use your halves recursive function, and also the merge.cpp program that we wrote in class yesterday. program output should look like this...Lab-12 Sort the letters of a word. Enter a word: bakersfield sorted: abdeefiklrsYou may refer to merge-sort reference materials. Wikipedia merge sort page. Geeks-for-geeks merge sort page. This page shows the merge function we learned in class, and also a complete merge-sort program. You may use the code on this page.
Your instructor will find your work out on Odin.