Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 9.2, Problem 14STE
What is the output of the following code fragment? The code is assumed to be embedded in a correct and complete
int arraySize = 10;
int *a;
a = new int[arraySize];
int i;
for (i = 0; i < arraySize; i++)
* (a + i) = i;
for (i = 0; i < arraySize; i++)
cout << a[i] << “ ”;
cout << endl;
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In java there must be at least two calls to the function with different arguments and the output must clearly show the task being performed. (ONLY ARRAYS or ARRAYLIST)
Develop a function that accepts an array and returns true if the array contains any duplicate values or false if none of the values are repeated.
Develop a function that returns true if the elements are in decreasing order and false otherwise.
A “peak” is a value in an array that is preceded and followed by a strictly lower value. For example, in the array {2, 12, 9, 8, 5, 7, 3, 9} the values 12 and 7 are peaks. Develop a function that returns the number of peaks in an array of integers. Note that the first element does not have a preceding element and the last element is not followed by anything, so neither the first nor last elements can be peaks.
Develop a function that finds the starting index of the longest subsequence of values that is strictly increasing. For example, given the array {12, 3, 7, 5, 9, 8,…
Write a function that gets an array as a parameter (address and size) and a number and checks to see if that number exists in the array. The function should report every single occurrence of the number in the array. It should also report how many occurrences were detected in total (use c code)Suggested prototype:
void findnReport(int* ar, int size, int num)
Example of function output:
If array = {2,5,3,5,12,13,14,15,0,5,-1,11,5} and num = 5,
Number 5 found in array index 1
Number 5 found in array index 3
Number 5 found in array index 9
Number 5 found in array index 12
Total of 4 occurrences of number 5
In java there must be at least two calls to the function with different arguments and
the output must clearly show the task being performed.
1. Develop a function that accepts an array and returns true if the array contains any
duplicate values or false if none of the values are repeated.
2. Develop a function that returns true if the elements are in decreasing order and
false otherwise.
3. A "peak" is a value in an array that is preceded and followed by a strictly lower
value. For example, in the array {2, 12, 9, 8, 5, 7, 3, 9} the values 12 and 7 are peaks.
Develop a function that returns the number of peaks in an array of integers. Note that
the first element does not have a preceding element and the last element is not
followed by anything, so neither the first nor last elements can be peaks.
4. Develop a function that finds the starting index of the longest subsequence of
values that is strictly increasing. For example, given the array {12, 3, 7, 5, 9, 8, 1, 4, 6},
the function…
Chapter 9 Solutions
Problem Solving with C++ (9th Edition)
Ch. 9.1 - Prob. 1STECh. 9.1 - Prob. 2STECh. 9.1 - Give at least two uses of the operator. State...Ch. 9.1 - Prob. 4STECh. 9.1 - Prob. 5STECh. 9.1 - Suppose a dynamic variable were created as...Ch. 9.1 - Write a definition for a type called NumberPtr...Ch. 9.1 - Prob. 8STECh. 9.2 - Write a type definition for pointer variables that...Ch. 9.2 - Suppose your program contains code to create a...
Ch. 9.2 - Prob. 11STECh. 9.2 - Prob. 12STECh. 9.2 - What is the output of the following code fragment?...Ch. 9.2 - What is the output of the following code fragment?...Ch. 9.2 - What is the output of the following code fragment?...Ch. 9 - Prob. 1PCh. 9 - Write a program that asks the user to input an...Ch. 9 - Palindrome testing with pointers This Practice...Ch. 9 - Do Programming Project 3 in Chapter 7 in this...Ch. 9 - Do Programming Project 11 in Chapter 7 using a...Ch. 9 - Write a function that takes a C string as an input...Ch. 9 - Prob. 5PPCh. 9 - One problem with dynamic arrays is that once the...Ch. 9 - Prob. 7PPCh. 9 - Write a program that outputs a histogram of...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Modify your printDetai 1 s method to include printing the reference number. However, the method should print th...
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
List the specific functions of a DBMS.
Database Concepts (8th Edition)
How are relationships between tables expressed in a relational database?
Modern Database Management (12th Edition)
Write the function htoi(s), which converts a suing of hexadecimal digits (including an optional 0x or 0X) into ...
C Programming Language
Define the three types of recursive binary relationships, and give an example of each, other than the ones show...
Database Concepts (7th Edition)
Look at the following class: public class Checkpoint { public void message(int x) { System.out.print(This is th...
Starting Out with Java: From Control Structures through Data Structures (3rd 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 C++ program that reads 6 real numbers from the user (negative and positivenumbers) into an array, then it does the following: Display all the values of array in reverse order. Find the sum and average of positive numbers of the array and display them. Count negative numbers of the array and display it. Find the minimum value of the array and display it. Find the index of the minimum value of the array and display it.arrow_forwardPart 1 Javaarrow_forwardOne dimension array in C:Create an array of 100 integer elements and initialize the array elements to zero.Populate the array (using a for loop) with the values 10,20,30,..., 990,1000.Write code (using for loops) to sum all the elements and output the sum to the screen. without using #definearrow_forward
- What benefits do enumeration types provide over a collection of named constants? What benefits does a subrange type have over its base type? When might a string be preferable over a character array?arrow_forwardWrite a function void switchEnds(int *array, int size);that is passed the address of the beginning of an array and the size of the array. The function swaps the values in the first and last entries of the array.arrow_forwardOne dimension array in C:Create an array of 100 integer elements and initialize the array elements to zero.Populate the array (using a for loop) with the values 10,20,30,..., 990,1000.Write code (using for loops) to sum all the elements and output the sum to the screen.arrow_forward
- Write a program in C++ to find the transpose of a 3x3 matrix input by the user, store it in another array and display it. instructions: 1.avoid void function in the program. 2. use int function. 3. avoid copy-pasting and plagiarism 4. write a self-written code 5. give comments with each step. 6. write code with easy and basic steps as I am just a student.arrow_forwardStudy the two functions given below. Both use the same array declared as: static int data[256*256*8]; void function1(){ int i; int j; for (i = 0; i < 32; i++) for (j = 0; j < 256; j++) data[j] = i;}void function2(){ int i; int j; for (i = 0; i < 32; i++) for (j = 0; j < 256; j++) data[j*2048] = i;} Instructions:Assume the following behaviors in a virtual memory system. Reading or writing physical memory requires 50 nanoseconds. Reading or writing disk writing 10 milliseconds. Page size is 8 kilobytes. Presume that the program has 1 megabyte of physical memory available. You may consider everything except the array access itself to take no time. You should also assume that the first 1 megabyte of the array is in physical memory ini-tially. You may ignore any memory used by the program or stack to execute these func-tions. Using this information, answer the following questions. In each case, show the work you use to…arrow_forwardI need a C code of this: Implement the following functions: void createArray(int arr[],int count); /*Asks the user for the elements of the array.*/ int findFather(int arr[],int count); /*returns the largest sum possible*/ int findSon(int arr[],int count); /*returns the smallest sum possible*/ void display(int father, int son); /*displays the largest and smallest sum*/ Input 1. The size of the array Constraints The value is >= 3. 2. The values inside the array Constraints The value is within the range: <= 2147483647 and >= -2147483648 #include<stdio.h>#define SIZE 100int main(void) { int arr[SIZE]; int count; int father; int son; printf("Enter the size: "); scanf("%d",&count); createArray(arr,count); father = findFather(arr,count); son = findSon(arr,count); display(father, son); return 0;} Output should be: Enter the size: 4 Enter the values: 1 2 3 4 Father = 9, Son = 6arrow_forward
- In c++ , perform insertion into the dynamic array at the start, end, and middle as well and perform array resizing as well. ( Drop code in words , explain the code and drop the screenshot of output as well )arrow_forwardUse C++arrow_forwardTwo dimension array in C:Create a two dimension array of integers that is 5 rows x 10 columns.Populate each element in the first 2 rows (using for loops) with the value 5.Populate each element of the last three rows (using for loops) with the value 7.Write code (using for loops) to sum all the elements of the first three columns and output thesum to the screen.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 Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License