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 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
5. Write a Python function that inputs an array of integers and returns the maximum value in this array. Do not use the max method on array class.
6. Write a Python program that inputs a sentence string by the user and counts the number of words in the sentence
Debugging challenge: Consider the code example below. This program is designed to compare the
contents of two arrays: if they are equal, the program should display "TRUE," if the arrays are not
equal, the program should display "FALSE".
However, even when the arrays have the same value, the program always prints "FALSE", regardless of
the values in arrays a and b.
What is going on here? What about the program causes the comparison to always fail?
int a[4]
{1, 2, 3, 4};
int b[4]
= {1, 2, 3, 4};
if (a == b) {
display ("TRUE");
else {
display ("FALSE");
4. Write a Python program that inputs integers until a 0 is encountered and then prints the maximum value entered up to that point.5. Write a Python function that inputs an array of integers and returns the maximum value in this array. Do not use the max method on array class
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
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
- Part 1 Javaarrow_forwardWrite pseudocode that will a.) initialize an array with 5 values and declare a second empty array of the same size. b.) copy the contents of the first array into the second array. (Hint: use a loop.) Java 1 public class FinalGrade2 {3 public static void main(String args[])4 {5 //variable declarations and initialization6 String studentName = "Nicholas Simoneaux";7 final double QUIZ_PERCENTAGE = 0.5;8 final double TEST_PERCENTAGE = 0.5;910 double quizOne = 98.5;11 double quizTwo = 77.0;12 double quizAverage;13 double testOne = 85.0;14 double testTwo = 67.0;15 double testAverage;16 double extraCredit = 10.0;17 double finalGrade;1819 //calculations20 quizAverage = quizOne + quizTwo / 2;21 testAverage = testOne + testTwo / 2;2223 finalGrade = (quizAverage * QUIZ_PERCENTAGE) + (testAverage * TEST_PERCENTAGE) + extraCredit; 24 25 //output26 System.out.println("Student…arrow_forwardIn Java (Single-Dimensional Arrays) // need a different solution than what's already in Chegg's solution Write a program that reads and fills an array with 20 integers. Then, using the array elements, calculate the data to find and display: The highest value entered. The lowest value entered. The average of the numbers entered. The sum of the numbers entered. Display this information in a readable display making the data easy to understand.arrow_forward
- Assignment A scientist has developed a mathematical model for a physical process, and he wants to check how good is model is. To evaluate the correctness of his model, he wants to test the results of his model under certain parameters and compare them with experimental results. Write a program that first reads the number of tests (testCount) as an int followed by the results of each test according to the model as a double array (testModel) and finally the results of each test according to experiments as a double array (testExperiment). Then, the program should calculate the error of the model by evaluating the average of the absolute values (i.e., mutlak değer) of the differences between the model result and experimental result (see formula below) using a function. ItestModel,- textExperiment, testCount NOTE: Individual absolute value of the difference between the model value and the experiment value calculations MUST be done in the function. Every other functionality MUST be done in…arrow_forwardAssignment A scientist has developed a mathematical model for a physical process, and he wants to check how good is model is. To evaluate the correctness of his model, he wants to test the results of his model under certain parameters and compare them with experimental results. Write a program that first reads the number of tests (testCount) as an int followed by the results of each test according to the model as a double array (testModel) and finally the results of each test according to experiments as a double array (testExperiment). Then, the program should calculate the error of the model by evaluating the average of the ratio of absolute values (i.e., mutlak değer) of the differences between the model result and experimental result to the model result (see formula below) using a function. testCount testModel, - textExperiment, testModel, Error= Input testCount NOTE: Individual ratio of absolute value of the difference between the model value and the experiment value to the model…arrow_forwardProblems: 1. Write a program to define an array of size 10, ask the user to enter the array elements. Replace all EVEN elements by 1 and ODD by 0. The output, for example: Enter 10 elements, please: 2474518 11 206 The array after the replacement: 1101001011 2. Write a program to define two arrays: A and B. each array is of size 3 x 3. Fill array A as follow: 2 4 6. Read array B from the user and calculate the sum of every row in both arrays A and B. For example, if the user enters B as: 2. 3. 1. The output will be: The sum of row 1 in A and B= 0+1+2+2+3+1=9 The sum of row 2 in A and B = 3+4+5+5+6+3= 26 The sum of row 3 in A and B = 6+7+8+948+0= 29 +arrow_forward
- Use C Language Create an array of N integers. Ask from the user how many elements he/she wants to input in the array. Determine the sum of all numbers, the average of all EVEN numbers and count how many are odd numbers and how many zeroes were inputted? At the end, print the accumulated and counted values of the array.arrow_forwardProblem Description Given the following array as an example: int A[10]= {10,3,2,1,6,5,7,8,9,1}; A. Write a recursive function that will print the contents of a given array as shown in the following example Sample output 10 3 2 1 6 5 7 8 9 1 10 3 2 1 6 5 7 8 9 10 3 2 1 6 5 7 8 10 3 2 1 6 5 7 10 3 2 1 6 5 10 3 2 1 6 10 3 2 1 10 3 2 10 3 10 B. Modify the above recursive function so that it will print the contents of a given array as shown in the following example 10 3 2 1 6 5 7 8 9 1 3 2 1 6 5 7 8 9 2 1 6 5 7 8 1 6 5 7 6 5arrow_forwardCode in java pleasearrow_forward
- Study 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_forwarddo in javaarrow_forwardWrite a program which should consists of a user defined function “maximum ()”. Pass 1D array to the function, along with number of elements of array. Find out the maximum element in 1D array using this function.[Note: Array should be passed using by reference approach] C languagearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
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