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 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++ (10th 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 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_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_forward
- In C language pleasearrow_forwardFunctions with 1D Arrays in Java Write a program that has a function vowelCount() that accepts a character array and counts the number of vowel in character array. Output Number of vowels: 5arrow_forwardQ / write a program in Fortran language to find the number of readings whose values exceed 70 mm and the percentage of these readings, as well as find the number of readings that are less than 40 mm and the percentage of these readings in the matrix AN (7 + AN if your number (N) is odd, or from the array (8 +8). AN if your number is (N) even. Notes: 1- N represents your number (meaning the student's number in the department. 2- The program must be complete (ie include FORMAT phrases) with each reading and writing statement 3- Reading items from an external file His name is the first 3 letters of the first name of your name 4- Print the elements in an external file whose name is the first 3 letters of the third name of your name 5- The answer is by printing the required program and not a picture of the solution for the purpose of correction #my number is (n=14)arrow_forward
- In 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_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_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 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_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 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_forwardPrigraming in Python Problem 6.3 Purpose: Write array functions to solve a mathematical problem. I'm sure you have all heard of Euclidean distance. In two dimensions, the Euclidean distance between (x1, x2) and (y1, y2) is the square root of (x1-y1)2 + (x2-y2)2, or ((x1-y1)2 + (x2-y2)2)1/2. For example, the distance between (3,1) and (1,1) is ((3-1)2+(1-1)2)1/2 = 2 and the Euclidean distance between (1,1) and (0,0) is ((1-0)2+(1-0)2)1/2 ~= 1.4142. The Euclidean norm of a vector is just its Euclidean distance to the origin, (0,0). Therefore, the Euclidean norm of (1,1) is ~= 1.4142. This notion of Euclidean norm can easily be extended to vectors of arbitrary dimension. Indeed, if x is a vector of dimension n (versus dimension 2), then its Euclidean norm, which we will denote by |x|2, is given by |x|2 = ( Σ i = 1 to n |xi|2 )1/2 = (|x1|2+|x2|2+ ... + |xn|2 )1/2 There, Σ is a shorthand for "sum," as we saw in lecture and |xi| is just the absolute value of the real number xi. By the way,…arrow_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