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 3P
Write a function named swapFrontBack that takes as input an array of integers and an integer that specifies how many entries are in the array. The function should swap the first element in the array with the last element in the array. The function should check if the array is empty to prevent errors. Test your function with arrays of different length and with varying front and back numbers.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
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
The 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( );…
Write a function called FindMyChar that receives three parameters:
. the name of the array
• the array size
• a character ch
The function must return the index number in which the character ch is in your array.
If the character ch is not found of the array, insert ch in the last index of the array and return that index
number.
This index number will be printed from your main( ).
For the toolbar, press ALT+F10 (PC) or ALT+FN+F10 (Mac).
BIUS
Paragraph
Arial
14px
A v
...
Click Save and Submit to save and submit. Click Save All Answers to save all answers.
Save All Answers
Save and Submit
梦 $
耳
a
911A
S/19/20
hp
12
->
ort sc
home
delete
nd
%24
4.
&
7.
6
8
num
%3D
backspace
lock
R
Y.
home
4.
enter
pause
1 shift
end
alt
ctrl
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
What is the difference between virtual memory and main memory?
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Indexing can clearly be very beneficial. Why should you not create an index for every column of every table of ...
Modern Database Management
Why do some standard SQL-92 statements fail to run successfully in Microsoft Access?
Database Concepts (8th Edition)
A new class of objects can be created conveniently bythe new class (called the subclass) starts with the charac...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Determine the resultant couple moment acting on the pipe assembly.
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
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
- you need to insert only the even index values to an array named intArray[]. Now send that array to a function named int sumOfallArrayElements(int *intArrayLocal) where you need to sum all the elements of all the array elements and return back to the main function. PLEASE DO NOT USE ANY INDEX TO ACCESS ELEMENTS OF THE ARRAY. Sample Output:Elements of intArray: 0 2 4 6 8 10 12 14 16 18Sum of all evenindex elements is: 40arrow_forwardWrite 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 .…arrow_forwardusing 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_forward
- 1.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_forwardcreate a flowchart from the user-defined array for any size n determined/chosen by the user to the function that determines the perfect squares in an array. Display theresult as an ordered pair (u, v) where u is a perfect square and v is its corresponding squareroot. Call this function to find all perfect squares of the array.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_forward
- Write down a function that will take an array, its size and an integer M as parameters and return the summation of integers that are greater than M. Then write a main function that asks the user to enter an integer X and N integers. Store N integers in an array and use the above function to compute the summation of the integers that are greater than X and display the resultarrow_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_forwardHelp me write a program that utilizes two functions for input and output. The first function, readChars( ) prompts the user for a count and reads in count characters from the keyboard into a data array. The characters are space delimited. The second function, printReverse( ), prints the characters out in reverse order. All array bounds must be checked. The maximum character count is 25. If the user enters a value greater than 25, an error should be output and the program should exit. Notes: main( ) should only contain variable declarations and the calls to the two functions. All user input output must be performed in the functions. The following is an example of how the program should run: How many chars: 7 a 1 b 2 c 3 d d 3 c 2 b 1 a How many chars: 53 Error-max chars 25arrow_forward
- You are required to ONLY write the code for the body of a function that takes as input a 1D array and it size, and returns an array result.. You MUST NOT write the main subroutine nor add any other functions. Your code inside the function accepts two values from the user. The first value N is an integer number of elements to work on from the array, and the second is a character operation code. • If the number N is larger than the array size or negative, the code should output wrong • If the operation code is invalid, the code should output invalid If the operation code is @: you are required to count the even numbers in odd-numbered elements and print the count on the screen. • If the operation code is &: You are required to multiply each value by the one to its right and store it at the corrosponding location inside the array result. The last element remains the same. The code will print the new array on one line with each number separated by exactly one space.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_forwardWrite 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…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
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