Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 7, Problem 2P
Write a function named countNum2s that takes as input an array of integers and an integer that specifies how many entries are in the array. The function should return the number of 2’s in the array. Test your function with arrays of different length and with varying number of 2’s.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a program that creates a two-dimensional array initialized with test data. Use any data type you wish. The program should have the following functions:a. getTotal . This function should accept a two-dimensional array as its argument and return the total of all the values in the array.b. getAverage . This function should accept a two-dimensional array as its argument and return the average of all the values in the array.c. getRowTotal . This function should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The function should return the total of the values in the specified row.d. getColumnTotal . This function should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The function should return the total of the values in the specified column.e. getHighestInRow .…
Write a function named swapFrontback that takes as input an array ofintegers and an integer that specifies how many entries are in the array. Thefunction should swap the first element in the array with the last elements inthe array. The function should check if the array is empty to prevent errors.The header file for the swapFrontback() is:swapFrontback.h:double swapFrontback (int [] arr,int size);Write a driver (main.c) to test your function with arrays of different lengthand with varrying front and back numbers. Print the array elements beforeand after the swap in the main.c.Sample Run: Original Array: 1 2 3 4 5 6 FrontBack Array: 6 2 3 4 5 1
Write a program that creates a 2D array of integers of size nXn initialized with test data.The program should have the following functions:● getTotal. This function should accept a 2D array as an argument and returnthe total of all the values in the array.● getAverage. This function should accept a 2D array as an argument and returnthe average of all the values in the array.● getRowTotal. This function should accept a 2D array as the first argument andan integer as its second argument. The second argument should be the subscriptof a row in the array. The function should return the total of the values in thespecified row.● getColumnTotal. This function should accept a 2D array as the first argumentand an integer as its second argument. The second argument should be thesubscript of a column in the array. The function should return the total of thevalues in the specified column.● getHighestInRow. This function should accept a 2D array as the firstargument and an integer as its second…
Chapter 7 Solutions
Problem Solving with C++ (10th Edition)
Ch. 7.1 - Prob. 1STECh. 7.1 - In the array declaration double score(5); state...Ch. 7.1 - Identity any errors in the following array...Ch. 7.1 - What is the output of the following code? char...Ch. 7.1 - What is the output of the following code? double a...Ch. 7.1 - What is the output of the following code? int i,...Ch. 7.1 - Prob. 7STECh. 7.1 - Suppose we expect the elements of the array a to...Ch. 7.1 - Prob. 9STECh. 7.1 - Suppose you have the following array declaration...
Ch. 7.2 - Consider the following function definition: void...Ch. 7.2 - Prob. 12STECh. 7.2 - Write a function definition for a function called...Ch. 7.2 - Consider the following function definition: void...Ch. 7.2 - Insert const before any of the following array...Ch. 7.2 - Write a function named outOfOrder that takes as...Ch. 7.3 - Write a program that will read up to ten...Ch. 7.3 - Write a program that will read up to ten letters...Ch. 7.3 - Following is the declaration for an alternative...Ch. 7.4 - Prob. 20STECh. 7.4 - Write code that will fill the array a (declared...Ch. 7.4 - Prob. 22STECh. 7 - Write a function named firstLast2 that takes as...Ch. 7 - Write a function named countNum2s that takes as...Ch. 7 - Write a function named swapFrontBack that takes as...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - There are three versions of this project. Version...Ch. 7 - Hexadecimal numerals are integers written in base...Ch. 7 - Solution to Programming Project 7.3 Write a...Ch. 7 - Prob. 4PPCh. 7 - Write a program that reads in a list of integers...Ch. 7 - Prob. 6PPCh. 7 - An array can be used to store large integers one...Ch. 7 - Write a program that will read a line of text and...Ch. 7 - Write a program to score five-card poker hands...Ch. 7 - Write a program that will allow two users to play...Ch. 7 - Write a program to assign passengers seats in an...Ch. 7 - Prob. 12PPCh. 7 - The mathematician John Horton Conway invented the...Ch. 7 - Redo (or do for the first time) Programming...Ch. 7 - Redo (or do for the first time) Programming...Ch. 7 - A common memory matching game played by young...Ch. 7 - Your swim school has two swimming instructors,...Ch. 7 - Your swim school has two swimming instructors,...Ch. 7 - Prob. 19PPCh. 7 - The Social Security Administration maintains an...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Specify the orientation of the corresponding element at the point with respect to the original element. Sketch ...
Mechanics of Materials (10th Edition)
For the circuit shown, use the node-voltage method to find v1, v2, and i1.
How much power is delivered to the c...
Electric Circuits. (11th Edition)
Distinguish among data definition commands, data manipulation commands, and data control commands.
Modern Database Management
Determine the magnitude of F2 which will cause the reaction C, at the bearing C to be equal to zero. The bearin...
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
ICA 8-28
If the pressure is 250 feet of water [ft H2O], what is the pressure in inches of mercury [in Hg]?
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
2D Array Operations Write a program that creates a two-dimensional array initialized with test data. Use any da...
Starting Out with C++ from Control Structures to Objects (9th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write a function that converts a number in 14th base to decimal number. The function should take a character array as argument and return an integer as result. Hint: You can use strlen(str) to find the length of a character array, assume that a user enters a number not more than the length of 10. You should also write a main program that will ask user to enter 5 numbers in 14th base (a character array). Store correspondina decimal numbers in an inteaer arrav. Finallv display the output in a format similar to below. Number in 14th Base Corresponding Decimal Number D109 35877 ... ... ...arrow_forwardWrite a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions: Part a: Function getData: This function reads and stores data in the two- dimensional array. Part b: Function averageHigh: This function calculates and returns the aver- age high temperature for the year. Part c: Function averageLow: This function calculates and returns the average low temperature for the year. Part d: Function indexHighTemp: This function returns the index of the highest high temperature in the array. Part e: Function indexLowTemp: This function returns the index of the lowest low temperature in the array. (These functions must all have the appropriate parameters.) #include <iostream> using namespace std; const int NO_OF_MONTHS = 12; void getData(int twoDim[][2], int…arrow_forward1.Enter a positive integer value n (6 <= n < 30) and take n integers from the user as input and store them in array a. Then move the elements of this array one step to the left and make the first element of the array the last element of the array. Shift this array with a function. Display integer value n, the array elements in original order and the array elements in modified order (after shifting). For example, if the original order of the array a is like below : a: 33 45 67 89 12 7 After shifting one step to the left, you should get the following order of the array а: a: 45 67 89 12 7 33arrow_forward
- Write a function that determines the average of the values in an array. In the main() function declare a floating point array with a length of 8 elements, and have the user enter the value of each element using a loop. The program should then call and pass the array to the function, then display the average.arrow_forwardWrite a program that stores first n prime numbers in a two-dimensional integer array. You should ask user to input row and column values of two-dimensional array. You should also write a function isPrimeNumber to check whether a number is a prime number or not. First n prime numbers should be found by multiplying row and column values entered by a user. Finally display the two dimensional array in a pretty form in reverse order of prime numbers. Note: You should NOT use built-in functions (except the most common ones) for finding prime numbers or displaying results.arrow_forwardThe purpose of this program is to write a series of function to manipulate a two-dimension array. ArrayData method: It will allocate a block of memory which represents a two-dimension array based on the input values supplied by the user. Ask the user to enter the number of rows and column for 2D array that the user want to manipulate. The number of rows and columns that the user enters may or may not define a square matrix (when the number of rows equals the number of columns). The array will have exactly rows time columns (m * n) elements. It will not contain any extra or empty cells. Initialize the “matrix” by rows with random number between 1 to 100. Pass two arguments by out reference so that you can assign the number of row and columns of data to the first and second arguments. This is return 2D array method after allocating new memory for 2D array and initialize it with random value. Generate random number code in C# as following: Random randnum = new Random( );…arrow_forward
- Create an array of N integers. Ask from the user how many elements he/she wants to input in the array. Determine the following: (you may define a function for each item below) sum of all numbers INPUTTED the average of all numbers, count how many are EVEN numbers(excluding zero), how many are odd numbers and how many zeroes were inputted? At the end, print the accumulated and counted values (for items a-e given above) In the array.arrow_forwardWrite a function called GradientCount that accepts as parameter a two-dimensional array called Matrix of size 6 by 6. The function returns how many numbers in the Matrix are gradient numbers. A number in the Matrix is considered a gradient number if it matches the following two rules: 1. The numbers to the left and above the number are smaller. 2. The numbers to the right and below the number are larger.arrow_forwardIn statistics the mode of a set of values is the value that occurs most often. Write a program that determines how many pieces of pie most people eat in a year. Set up an integer array that can hold responses from 30 people. For each person, enter the number of pieces they say they eat in a year. Then write a function that finds the mode of these 30 values. This will be the number of pie slices eaten by the most people. The function that finds and returns the mode should accept two arguments, an array of integers, and a value indicating how many elements are in the array.arrow_forward
- using c++ Create a function that accepts the integer array described above returns the standard deviation of the values in a. The standard deviation is a statistical measure of the average distance each value in an array is from the mean. To calculate the standard deviation, (http://en.wikipedia.org/wiki/Standard_deviation ) you first call a second mean function that you need to write (do not use a built in gadget. Then sum the square of the difference of each value in the array a and that mean. The standard deviation is the square root of that sum divided by the number of elements in the array. Pay attention to what type of function your standard deviation and mean functions should be. As part of testing the functions, your main should display your test array in a square. (create an integer array with 100 randomly generated values between 0 and 99; pass this array into all subsequent functions. Place code in your main to call all the methods and demonstrate they work correctly.)arrow_forwardWrite a function that accepts an int array and the array’s size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file named data into an array. The program then passes the array to your array expander function, and displays the values of the new expanded array, one value per line. You may assume that the file data has at least N values. There are no prompts for the integer and no labels for the expanded reversed array that is printed out. If the integer read in from standard input exceeds 50 or is less than 0 the program terminates silently.arrow_forwardWrite a function that takes as an argument an array of integers and the size of the array and returns the average of the input values. Int= avrg(int * array, int size)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License