← Back to Book Detail

Practice: Arrays (37/26) -- Programming Fundamentals

Browse
142%

Practice: Arrays

Practice: Arrays Kenneth Leroy Busbee Review Questions True / False - The array data type is one of the standard data types in C++. - Arrays can have more than one dimension. - For loops are often used to display the members of an array. - When defining an array, it is preferable to specify how many members are in the array. - Arrays are rarely used to represent data. - Linear searches require complex algorithms. - Functions are often created for searching for the max and min values in an array. - The bubble sort is an easy way to arrange data an array. - There is only one method of bubble sorting. - Sorting an array is frequently done. Answers: - false - true - true - false - false - false - true - true - false - true Short Answer - Briefly explain what an array is and list the two common operators used with arrays. - Give a short explanation of bubble sorting. Activities Complete the following activities using pseudocode, a flowcharting tool, or your selected programming language. Use separate functions for input, each type of processing, and output. Avoid global variables by passing parameters and returning results. Create test data to validate the accuracy of each program. Add comments at the top of the program and include references to any resources used. Defined-Value Arrays - Review MathsIsFun: Leap Years. Create a program that displays the number of days in a given month. Start by asking the user to enter a year and month number. Use a defined array to look up the corresponding month name (January, February, etc.). Use another defined array to look up the corresponding number of days in the month (January = 31, February = 28 or 29 depending on year, etc.). Display results similar to the following: February 2020 has 29 days - Review Wikipedia: Zeller’s congruence. Create a program that asks the user for their birthday (year, month, and day) and then calculate and display the day of the week on which they were born. Use a defined array to look up the numeric day of the week and display the corresponding string representation (Monday, Tuesday, Wednesday, etc.). Fixed-Length Arrays - Review MathsIsFun: Definition of Average. Create a program that asks the user to enter grade scores. Start by asking the user how many scores they would like to enter. Then use a loop to request each score and add it to a static (fixed-size) array. After the scores are entered, calculate and display the high, low, and average for the entered scores. - If your programming language supports it, use a built-in sort function to sort the grade scores from the activity above and display the array in order from highest score to lowest score. - Review Wikipedia: Monty Hall problem. Create a program that uses an array to simulate the three doors. Use 0 (zero) to indicate goats and 1 (one) to indicate the car. Clear each “door” and then use a random number function to put the number 1 in one of the array elements. Then use the random number function to randomly select one
← Previous Chapter Next Chapter →