Problem Solving with C++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (9th Edition)
9th Edition
ISBN: 9780133862225
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 9.2, Problem 13STE
What is the output of the following code fragment? The code is assumed to be embedded in a correct and complete
int array_size = 10;
int *a;
a = new int [array_size];
int *p = a;
int i;
for (i = 0; i < array_size; i++)
a [i] = i;
p[0] = 10;
for (i = 0; i < array_size; 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
Question 1. (-)
Analyze the below code:
#include <stdio.h>
int main(void) {
int array1[9];
printf("Enter Array1 elements:");
for(int i=0;i<9;i++)
scanf("%d",&array1[i]);
for(int i=0;i<9;i++)
printf("%d ",array1[i]);
return 0;
}
Add code line to print your name (Ghadeer) and take a screenshot for the program output
Array elements should be given as: (-)
3
5
7
11
13
17
19
23
31
Explain the code in your own words in details -)
Update the code to have float array elements of size 8. (-)
Take a screenshot for the program output. Array elements should be given as : (-)
2.3
4…
I need this program in java please.
#Given Arrayarray=[1,1,1,2,2,2,2,2,4,5,5,6,6,6]
#Insert valuevalue=3
index=0for x in array: if value<x: #inserting to the array in the position index array.insert(index,value) print ("Output :",array) break #Incrementing position by 1 index=index+1
Write a Program for insertion and deletion from an array without replacement of element from the arrays. Also, write a program to search the array for the presence of a given element from an array. Write the sub-functions in the provided test case in text form and upload the same.
#include<stdio.h> #include<stdlib.h> int cmpfunc (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } int insert_function(int *data, int n, int p, int x) { /* input data: array, n: size of array, p: position of insertion, x: element to insert*/ /*output:-1 indication error or 0 if successful /* write the function for inserting element into a position*/ } int delete_function(int *data, int n, int p, int x) { /* input data: array, n: size of array, p: position of deletion, x: element to deletion*/ /*output:-1 indication error or 0 if successful /* write the function for delete element into a position*/ } int linear_search_function(int *data, int n, int x) { /*write the function to…
Chapter 9 Solutions
Problem Solving with C++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (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
A single alternative decision structure tests a condition and then takes one path if the condition is true, ano...
Starting Out with Python (4th Edition)
(BitOutputStream) Implement a class named BitOutputStream, as shown in Figure 17.22, for writing bits to an out...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
What is the value of x after each of the following statements is executed? double x = Math.floor(7.5);
Java How To Program (Early Objects)
What characteristic of Rubys arithmetic operators makes them unique among those of other languages?
Concepts Of Programming Languages
Define the term database.
Database Concepts (7th Edition)
Write a cout statement so the variable divSales is displayed in a field of 8 spaces, in fixed-point notation, w...
Starting Out with C++ from Control Structures to Objects (8th 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 program that accepts two integer values, called "arraySize" and "multiplier", as user input. Create an array of integers with arraySize elements. Set each array element to the value i*multiplier, where i is the element's index. Next create two functions, called PrintForward() and PrintBackward(), that each accept two parameters: (a) the array to print, (b) the size of the array. The PrintForward() function should print each integer in the array, beginning with index 0. The PrintBackward() function should print the array in reverse order, beginning with the last element in the array and concluding with the element at index 0. As output, print the array once forward and once backward.arrow_forwardAnalyze the below code and answer the questions: #include <stdio.h> void add10 (int A[],int m); int main(void) { int Array2 [5]={11,21,31,41,51}; add10(Array2,5); for (int i=0;i<5; i++) { printf("Array2 [%d] after modification = %d \n", i,Array2 [i]); } return 0; } void add10 (int A[],int m){ for (int a = 0;a < m; a++) { A[a] = A[a]+10; } return; } Explain what does this code do? What is the size of Array2 [] ? What is the Array2 [4] value after the modification ? Change the size of Array2 to be 7 elements {……61,71}?arrow_forwardCreate a simple program in C++ that... 1) Returns the maximum value of the given array parameter arr whose length is given by the parameter length int getMax (int arr[], int length); 2) Return the mean/average of the given array. Note: The return type is double, so be careful not to do integer division. double getMean (int arr[], int length);arrow_forward
- Can you help with the following question? Write a Java program that creates and initializes an array of integers. Then it finds and prints theminimum odd value in this array with its index. Assume that all the values < 1,000,000.arrow_forward1. When you are taking java, you are aware that a[] is an array, It can also be evalutated under certain circumstances. if you have x[2*z+4], what do you need to be true to evaluate? a. 3<= x < z.length b. 3<= x < (z.length-1)/2 c 2 <= x < z.length d. 4<= x < z.length/2 2. Given the program solve the problem for (int i=0; i ! lolma.length-1; i= i+1){ lolma[i] = lolma[i]+lolma[i+1] the array looks like from 0-3: 5, 9, 1, -3 What will be the next order a. 5,9,1,-3 b. 11,19,3,-5 c. 14,10,-2,-3 d. 5, 14,10,-2arrow_forwardGiven the Array declaration below, determine the output: int T[8] = {2, 3, 7, 9, -1, 2, 4, 5}; int x = 5; cout << T[x-2] / T[12-2*x]; int y = -3; cout << pow(T[y+4],T[3-y]);arrow_forward
- Let's try defining the size of the array and create the contents of it on our own! And then, to give off a sense of excitement, let's try accessing the value of an array element in a random index position! Input Format The first line contains an integer. The next lines contains a character. The last line contains an integer. Input Sample 4 C o d y 3 Output Format A line containing a character. Output Sample y Another test samples: Input Sample 6 L e a r n 0 Output Sample L Note: Using array without pointers in C programming. Make the code simpler as much as possible. Thank you!arrow_forwardCan someone look at my code and tell me why my sequential access was slower than my random access. I thought random was supposed to be slower most of the time. #include <stdio.h> #include <stdlib.h> #include <time.h> #define ARRAY_SIZE (1 << 24) void sequentialAccess(int* array) { for (int i = 0; i < ARRAY_SIZE; ++i) { array[i] += 1; // Accеssing еach еlеmеnt sеquеntially } } void randomAccess(int* array, int stride) { for (int i = 0; i < ARRAY_SIZE; i += stride) { array[i] += 1; // Accеssing еlеmеnts with a spеcifiеd stridе } } int main() { int* largeArray1 = (int*)malloc(ARRAY_SIZE * sizeof(int)); int* largeArray2 = (int*)malloc(ARRAY_SIZE * sizeof(int)); for (int i = 0; i < ARRAY_SIZE; ++i) { largeArray1[i] = i; largeArray2[i] = i; } clock_t startTimeSeq = clock(); sequentialAccess(largeArray1); clock_t endTimeSeq = clock(); clock_t startTimeRand =…arrow_forwardYou are to write a C program that searches through the an array that contains a sequence of numbers in an and that a end with the number zero. That array should be declared and initialized exactly as follows in your program: int DNA[] = {1, 2, 4, 2, 2, 2, 1, 4, 4, 2, 3, 4, 4, 4, 2, 1, 4, 1, 3, 3, 2, 1, 3, 2, 1, 1, 2, 2, 2, 3, 4, 1, 3, 1, 2, 1, 4, 4, 4, 1, 1, 3, 1, 4, 2, 4, 4, 1, 4, 4, 1, 4, 4, 4, 4, 1, 1, 2, 3, 3, 3, 3, 4, 4, 3, 2, 3, 2, 3, 4, 3, 3, 4, 4, 1, 3, 3, 2, 1, 2, 3, 1, 2, 1, 3, 3, 2, 1, 4, 1, 4, 3, 4, 4, 4, 1, 2, 1, 3, 2, 0}; Your program should repeatedly ask the user for two things: the length of a search sequence, and the search sequence itself. The program should then search through the array “DNA” to find the starting element subscript (index) of all possible matching sequences. The elements of the search sequence may take on one of five characters: 1,2,3,4 and 5. The meaning of the ‘5’ character is that of wild card, i.e. it matches 1,2,3 and 4. The program…arrow_forward
- Your Friendly Array Neighbor Program only in java not in python Create a Java program that takes an array called ar as an input that keeps track of arrays. Every day a new array is produced using the array of the previous day. On the n’th day, the following operations are performed on the array of day n – 1 to produce the array of day n: -If an element is smaller than both left and right neighbor, then this element is incremented -If an element is bigger than both its left neighbor and its right neighbor, then this element is decremented. -The first and last elements should never change Eventually after some days the array will not change, some examples: Example: Input from user: ar = [6,2,3,4] Output from program: [6,3,3,4] After the first day the array is changed from [6,2,3,4] to [6,3,3,4] and no further operations may be completed. Example: Input from user: ar = [1,6,3,4,3,5] Output from program: [1,4,4,4,4,5] After the first day the array is changed from [1,6,3,4,3,5]…arrow_forwardPLEASE ANSWER THE QUESTION IN C! 1) Instead of reading several lines of text, just hard-code the following text in the programa. myString= “The quick Brown ? Fox ? jumps over the Lazy Dog and the !##! LAZY DOG is still sleeping”.b. The program should work with any value assigned to myString.c. Use a very small set of text (like “Ab#C#d” ) to test/debug your program first. Use lots of tracing statements to help you to trace the value of array index and elements.2) The program should use of your own function that converts the text to lower case (do not use the built-in tolower function ) and then perform the analysis in the main function. Ignore any numbers, symbols or special characters, etc in the text if any.Note : It’s easier to create a new string for the result instead of modifying the original string.3) Instead of the three methods outlined in the original question, complete only part a and part b. Assume maximum word length is 10 for part b.4) Turn in one program that contains…arrow_forwardYou’re given an array of integers and another array of three distinct integers. The first array is guaranteed to only contain integers that are in the second array, and the second array represents a desired order for the integers in the first array. For example, a second array of [x, y, z] represents a desired order of [x, x,…,x, y, y,…,y, z, z,…,z] in the first array. Write a program that sorts the first array according to the desired order in the second array. The program should perform this in place (i.e.., it should mutate the input array), and it shouldn’t use any auxiliary space. Note that the desired order won’t necessarily be ascending or descending and that the first array won’t necessarily contain all three integers found in the second array-it might only contain one or two. Please Don't Use Chat GPT Answers Sample input array = [1,0,0,-1,-1,0,1,1] order = [0,1,-1] Sample output [0,0,0,1,1,1-1,-1] Requirements: 1. Implement the above problem statement using C Programming. 2.…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
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License