Parallel arrays:
Arrays are used to group related data types together. The elements in two arrays with different variables that are related to their position are known as parallel arrays.
Establishing relationship between two parallel arrays:
Consider two arrays named “strMonth []” and “intBonus []” arrays are declared as follows:
string strMonth[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int intBonus[] = {25000, 26000, 27000, 29000, 31000, 34000, 36000, 37000, 38000, 40000, 41000, 45000};
Based on the above example, the relationship is established by using the same subscript for both the arrays. “strMonth[index]” have relationship on “intBonus[index]”. That is, the bonus amount of January month is 25000, February month is 26000, and so on.
Trending nowThis is a popular solution!
Chapter 8 Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
- (Statistics) Write a program that includes two functions named calcavg() and variance(). The calcavg() function should calculate and return the average of values stored in an array named testvals. The array should be declared in main() and include the values 89, 95, 72, 83, 99, 54, 86, 75, 92, 73, 79, 75, 82, and 73. The variance() function should calculate and return the variance of the data. The variance is obtained by subtracting the average from each value in testvals, squaring the values obtained, adding them, and dividing by the number of elements in testvals. The values returned from calcavg() and variance() should be displayed by using cout statements in main().arrow_forwardAn array is a collection of similar data elements stored at contiguous memory locations. It is the simplest data structure where each data element can be accessed directly by only using its index number. The following is an array of unsorted numbers called NumArr. NumArr: 24 56 78 79 34 75 2 23arrow_forwardAssignment Write a program that reads a 2D array of chars, checks, and corrects each char within this array, and print out the corrected 2D array. First the program will read the row count (rowCount) and column count (columnCount) of the 2D array, both as int values. Then, the chars constituting the 2D array will be read on a row-by-row basis. After reading the 2D array, the program will check and correct each char within the 2D array according to the rules below. This process MUST be done by using a void function by sending the appropriate cell of the 2D array with a call-by-reference fashion. • If the row index is an even number, a char can only be a lowercase English value. • If the row index is an odd number, a char can only be ?, 7', or X'. • Any incorrect value MUST be changed into Finally, the checked and corrected 2D array will be printed out to the screen. NOTE: Checking the correctness of a char and correcting it (if necessary) MUST be done in the function with a…arrow_forward
- Using C Language write a program: An instructor gives a multiple choice test which consists of 5 questions, each of which is answered by a choice of one of the numbers one to five. Write a program to call function TEST that accepts as input student name and the set of their test answers as one dimensional array. The program should grade the test. If the student choice is 1 give 1 point. If the choice is 2, give 2 points. 3 points if choice answer is 3 and 4 pints for answer 4 and choice 5 is 5 points. Otherwise no point is given to other choices. Print out the average score of the student in the test.SAMPLE RUN 1:INPUT : Enter student name : LYNNEEnter Answer # 1? 2Enter Answer # 2? 3Enter Answer # 3? 5Enter Answer # 4? 5Enter Answer # 5? 4OUTPUT : LYNNE, your total score is 19 and your average score is 3.8.SAMPLE RUN 2:INPUT : Enter student name : ROSEEnter Answer # 1? 2Enter Answer # 2? 3Enter Answer # 3? 767Enter Answer # 4? 5Enter Answer # 5? 4OUTPUT : ROSE, your total score is 14…arrow_forwardThe index type of an array can be any data type. True or false?arrow_forwardAssume an array is defined as int[] nums = {7, 15, 23, 5};. Which of the following would place the values in the array in descending numeric order? a. Array.Reverse(nums); b. Array.Reverse(nums); Array.Sort(nums); c. Array.Sort(nums); d. Array.Sort(nums); Array.Reverse(nums);arrow_forward
- 2. Design a program using pseudocode with two parallel arrays: a String array named people and an String array named phoneNumbers. The program allows you to search for a person's name in the people array. If the name is found, it displays that person's phone number otherwise it should prompt the user the name was not found. The program should use the binary search algorithm.arrow_forwardWrite a program that creates a 5 by 5, two-dimensional array that store 25 integers and the program will call five functions. Function display(): the program will display all the integers (in the 5 by 5 format) Function calculateTotal(): the program will return the total of the 25 integers Function totalRow(): returns and displays a 5-element array with each of the element showing the total of all the elements of the same row in the 5 by 5 array. Function totalColumn(): returns and displays a 5-element array with each of the element showing the total of all the elements of the same column in the 5 by 5 array Function maximum(): returns the largest value in the 5 by 5 arrayarrow_forwardRedo Programming Exercise 7 of Chapter 8 using dynamic arrays. The instructions have been posted for your convenience. You must ask the user for the number of candidates and then create the appropriate arrays to hold the data Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is below: Candidate Votes Received % of Total Votes Johnson 5000 25.91 Miller 4000 20.73 Duffy 6000 31.09 Robinson 2500 12.95 Ashtony 1800 9.33 Total 19300 The Winner of the Election is Duffy Format your output with setprecision(2) to ensure the proper number of decimals for testing!arrow_forward
- In C++ language Write a function that takes a 2 Demensional array and returns the position of the first row with an odd sum. Assume that the column size is fixed at 4. If no sum is odd, return -1.arrow_forwardWrite a program that will use a two-dimensional arrays named : Record[50][4]. The 1St column of the Record Array will store the Student Number, the grades Q1, Q2, PE and FE will be stored on the 2nd 3rd 4th and 5th column of the Record array, and the last column will store the average grade of 50 students. The data for Student Number, Q1, Q2, PE, and FE are to be entered from the keyboard while the average grade is to be computed using the equation : AVE = (Q1 + Q2 + 2 *PE + 2 * FE)/ 6 Print the content of Record Array in tabulated form with the header : Q2 STUDENT NO. Q1 PE FE AVE Make another print out of the Record Array, but this time the ave column of the Record array (that is, the las t column) must be sorted in descending order, with the same header as before. Create a function named PrintArray for printing its content both when the average grade is not yet sorted and when the average grade had been sorted.arrow_forwarda C++ program that creates a two-dimensional integer array (4x3) initialized with user given data. The program should have the following functions: • Print the sum of all values in the array. • Print the average of all the values in the array. • Take row number from user and print the sum of the values in that specified row.(use loop and no if statement) • Take column number from user and print the sum of the values in that specified column.(use loop and no if statement)arrow_forward
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,