1 Chapter 7 Arrays A Review A 1 What is an array? Give at least two examples in our real world and their representations using arrays in the C language A 2 Distinguish a conventional one dimension arr[.]
Chapter 7: Arrays A Review A.1 What is an array? Give at least two examples in our real world and their representations using arrays in the C language A.2 Distinguish a conventional one-dimension array of characters and a string in the C language Give an example for an illustration of their differences A.3 What is a multidimensional array? Give at least two examples in our real world and their representations using multidimensional arrays in the C language A.4 Why is an array passed by reference to a function call? Give an example for illustration B Practice B.1 Determine arrays in each problem in Chapter B.2 Define appropriate arrays for each description below B.2.1 A list of grades of all the courses you study in a year B.2.2 Lists of grades of all the courses all of you study in a year Each list is used for representing the annual grades of each of you B.2.3 A list of locations of places in a country where each location is represented by longitude and latitude B.2.4 Lists of locations of places for all the regions in a country where each location is represented by longitude and latitude and each list is used for each region B.2.5 A list of shopping malls in a city B.2.6 A list of customers each of which includes: customer identifier, name, address, transaction list A transaction list contains the information about all the transactions that each customer had with an enterprise Each transaction list includes: transaction identifier, date, product list, total value A product list contains the information about all the products bought by a customer in a transaction It includes: product identifier, name, branch, unit price, bought amount B.3 Identify errors in the following programs Make changes on them so that they are error-free What are the outputs on screen? B.3.1 B.3.2 B.3.3 B.4 Given a one-dimension array of N floating point numbers (N>0), write a program to return all the positions of the smallest numbers in the array B.5 Given a one-dimension array of N integer numbers (N>0), write functions: B.5.1 To check if all the numbers are in ascending order B.5.2 To check if all the numbers are in descending order B.5.3 To check if all the numbers are different from each other B.5.4 To check if all the numbers are greater than a query number B.5.5 To compute their mean and standard deviation B.5.6 To sort the numbers in ascending order B.5.7 To sort the numbers in descending order B.5.8 To generate a list of even numbers and another list of odd numbers from the given array B.5.9 To find the first position of a query number if it exists in the given array It is considered in two cases: (i) The given array is not sorted (ii) The given array is sorted in ascending order or descending order B.5.10 To find all the positions of a query number if it exists in the given array It is considered in two cases: (i) The given array is not sorted (ii) The given array is sorted in ascending order or descending order After that, write a program to obtain an array of N integer numbers (N>0) from a user or generated randomly and illustrate using the aforementioned functions B.6 Given a one-dimension array of N floating point numbers (N>0), write a program to return all the runs in the array A run is a sequence of M numbers (M>1) in descending order (or ascending order) Input: array = {2, -1, 0, 1, 3, 4, 9, 7, 3} Output: Runs in the array in descending order: Run = {2, -1} Run = {9, 7, 3} Runs in the array in ascending order: Run = {-1, 0, 1, 3, 4, 9} B.7 Generalize your solutions using arrays for the problems B.6, B.7, and B.8 in Chapter B.8 Given two one-dimension arrays representing two sets S1 and S2 of integer numbers, write functions: B.8.1 To check if S1 contains S2 B.8.2 To check if S1 is contained by S2 B.8.3 To check if S1 is the same as S2 B.8.4 To find the difference between S1 and S2 B.8.5 To find the difference between S2 and S1 B.8.6 To find the union of S1 and S2 B.8.7 To find the intersection of S1 and S2 B.8.8 To check if a given query number is a member of a set, either S1 or S2 B.9 Given two matrices, write two functions for matrix addition and matrix subtraction, respectively After that, write a program to obtain two matrices from a user or generated randomly and display the resulting matrices corresponding to addition and subtraction Their compatibility needs to be checked B.10 Given a matrix MxN that can be input by a user or generated randomly, write a program to return all the positions in the matrix where a query number is located Input: A query number is Given a matrix 3x3: -1 Output: (1, 1); (2, 2) B.11 Given a matrix NxN that can be input by a user or generated randomly, write a program to check if the matrix is a symmetric If yes, change all the values above the diagonal to zeros Display the matrix before and after check/change its values Input 1: A matrix 2x2: -1 Output 1: The input matrix is not symmetric Input 2: A matrix 4x4: 3 11 11 -1 Output 2: The input matrix is symmetric and changed as follows: 0 0 0 11 -1 B.12 Given M and N which are natural numbers greater than input by a user, write a program to generate a random matrix MxN whose values are in the range from to 100 Determine a path from cell (M-1, 0) to cell (0, N-1) that has the smallest total sum of the values of the cells in the path Display the smallest path and its sum on screen Input: M = 4, N = Output: A random matrix: 12 15 8 11 29 The smallest path = (3, 0); (2, 1); (1, 2); (2, 3); (1, 4); (0, 4) Sum = + + + + + = 25 B.13 Write a program to generate a spiral-shaped matrix NxN where N is an odd natural number The first number, number 1, starts at row N/2+1 and column N/2+1 Input: N = Output: A spiral-shaped matrix 7x7 is generated and printed as follows: 49 26 27 28 29 30 31 48 25 10 11 12 13 32 47 24 14 33 46 23 15 34 45 22 16 35 44 21 20 19 18 17 36 43 42 41 40 39 38 37 B.14 Given a string input from the keyboard by a user with a function gets() and a query word also input from the keyboard by a user, write a program to return all the word positions where the query word exists in the string Input: A string = If today is Monday, today is not weekend! A query word = today Output: 2, B.15 Given a string input by a user, write a program to toggle each word in the string Input: A string = If today is Monday, today is not weekend! Output: A string = If Today Is Monday, Today Is Not Weekend! B.16 Given a string input by a user, write a program to build a word count list of the string Input: A string = If today is Monday, today is not weekend! Output: A word count list of the input string is as follows: If :1 today :2 is :2 Monday, :1 not :1 weekend! :1 B.17 Given a string to represent an expression, write a program to check if parentheses are used correctly in the expression Input 1: (4-(x*7+9/y)/(2-z) Output 1: Incorrectly used Input 2: ((-x)/y) + 3*y/(-x+10) Output 2: Correctly used B.18 Write a program to tokenize a string based on a set of delimiters given by a user This program is similar to the function strtok() in the standard library However, it results in a multidimensional array so that the user can get the entire set of tokens right after the function call, not in the repetition manner with the function strtok() Input: A delimiter = ' ' A string = If today is Monday, today is not weekend! Output: A token list of the input string is as follows: If today is Monday, today is not weekend! B.19 Check your coding style with the programs you have written Should anything be changed with your programs so that they can be not only executable but also readable? Rewrite your programs if yes