Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 18.1, Problem 3STE
Suppose v is a
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a for loop to print all NUM_VALS elements of vector courseGrades, following each with a space (including the last). Print forwards, then backwards. End with newline. Ex: If courseGrades = {7, 9, 11, 10}, print:7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = courseGrades.size() - 1 (Notes)C++
without using std::
Note: These activities may test code with different test values. This activity will perform two tests, both with a 4-element vector (vector<int> courseGrades(4)). See "How to Use zyBooks".Also note: If the submitted code has errors, the test may generate strange results. Or the test may crash and report "Program end never reached", in which case the system doesn't print the test case that caused the reported message.
#include <iostream>#include <vector>using namespace std;
int main() { const int NUM_VALS = 4; vector<int> courseGrades(NUM_VALS); int i;
for (i = 0; i < courseGrades.size(); ++i) { cin >>…
import numpy as np
import torch
import matplotlib.pyplot as plt
Quiz Preparation Question
1. Write a function that generates a random tensor of n x n (n is the input). The output is the mean of the tensor.
= 2, 4, 8, 16, ... 1024 and generate a vector
2. Write a code (for loop) that call that calls the function above with n =
M(n).
Plot the vector as a function of the log of n.
3. Given an n x m array write a code
that replaces every element that is larger than 0.5 with 0.5.
4. The second derivative of a function can be approximated by the finite difference
1
ƒ"(x₂) = 73 (ƒ(£;+1) — 2ƒ(x;) + f(x;-1))
Given a vector f with values f = [f(xo),..., f(n) write a code that computes the approximation to f"(x)
5. The power method is a method to compute the largest eigenvalue of a matrix.
Your google search is using this method every time you perform a google search.
The method consists of the iteration
Vj+1 =
Av;
|| Avi||
where v; is a vector with chosen as a random vector, and A is the matrix…
Write a for loop to print all NUM_VALS elements of vector courseGrades, following each with a space (including the last). Print forwards, then backwards. End with newline. Ex: If courseGrades = {7, 9, 11, 10}, print:7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = courseGrades.size() - 1 (Notes)C++Note: These activities may test code with different test values. This activity will perform two tests, both with a 4-element vector (vector<int> courseGrades(4)). See "How to Use zyBooks".Also note: If the submitted code has errors, the test may generate strange results. Or the test may crash and report "Program end never reached", in which case the system doesn't print the test case that caused the reported message.
#include <iostream>#include <vector>using namespace std;
int main() { const int NUM_VALS = 4; vector<int> courseGrades(NUM_VALS); int i;
for (i = 0; i < courseGrades.size(); ++i) { cin >> courseGrades.at(i);…
Chapter 18 Solutions
Problem Solving with C++ (10th Edition)
Ch. 18.1 - If v is a vector, what does v.begin() return? What...Ch. 18.1 - If p is an iterator for a vector object v, what is...Ch. 18.1 - Suppose v is a vector of ints. Write a for loop...Ch. 18.1 - Suppose the vector v contains the letters 'A',...Ch. 18.1 - Suppose the vector v contains the letters 'A',...Ch. 18.1 - Suppose you want to run the following code, where...Ch. 18.2 - Prob. 7STECh. 18.2 - Prob. 8STECh. 18.2 - Prob. 9STECh. 18.2 - Prob. 10STE
Ch. 18.2 - Prob. 11STECh. 18.2 - Prob. 12STECh. 18.2 - Prob. 13STECh. 18.2 - Prob. 14STECh. 18.2 - Prob. 15STECh. 18.2 - Prob. 16STECh. 18.3 - Prob. 17STECh. 18.3 - Prob. 18STECh. 18.3 - Prob. 19STECh. 18.3 - Suppose v is an object of the class vectorint. Use...Ch. 18.3 - Prob. 21STECh. 18.3 - Can you use the copy template function with vector...Ch. 18.3 - Prob. 23STECh. 18 - Prob. 1PCh. 18 - Prob. 2PCh. 18 - Prob. 3PCh. 18 - Prob. 4PCh. 18 - Write a program that allows the user to enter any...Ch. 18 - Prob. 3PPCh. 18 - Prob. 5PPCh. 18 - Solution to Programming Project 18.6 In this...Ch. 18 - Prob. 7PPCh. 18 - You have collected a file of movie ratings where...Ch. 18 - Prob. 9PPCh. 18 - Prob. 11PPCh. 18 - Write a program that uses regular expressions to...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Explain what can be done with primary keys to eliminate key ripple effects as a database evolves.
Modern Database Management (12th Edition)
What is the output of the following code? const int SIZE 5 ; int count; int time[SIZE] = speed[SIZE] = dist[SIZ...
Starting Out with C++: Early Objects (9th Edition)
Write a program to print the value of EOF.
C Programming Language
Private Sub Handles btnOutput.Click
End Sub
Introduction To Programming Using Visual Basic (11th Edition)
A loop that evaluates its test expression before each repetition is a(n) _______ loop.
Starting Out with C++ from Control Structures to Objects (8th Edition)
Suppose the memory cells at addresses 0x00 through 0x05 in the Vole contain the following bit patterns: Address...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
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
- True or False: The initial loop is more efficient than its vecotized equivalent?arrow_forwardCreate a vector v = (15.9,21.4,19.9,21.9,20.0,16.5,17.9,17.5). What is the smallest valuc inv? What is the largest value? How many are greater than 18? Make a new vector with only those bigger than 18.arrow_forwardInteger inputSize is read from input. Then, integers and strings are read and stored into integer vector quantityList and string vector foodList, respectively. Lastly, integer quantityAsked is read from input. Find quantityAsked in quantityList and output the following: • "The quantity" • the value of quantityAsked • 'is matched with food' • the element in foodList at the index of quantityAsked in quantityList and is at index" • the index of quantityAsked in quantityList End with a newline. Ex: If the input is: 4 44 lettuce 48 chicken 59 guava 40 pineapple 48 Then the output is: The quantity 48 is matched with food chicken and is at index 1 Note: quantityAsked is an element in quantityList. 6 int inputSize; 7 int quantityAsked; unsigned int i; cin >> inputSize; vector quantityList (inputSize); 13 vector foodList (inputSize); 8 9 10 1121841516181928122 17 for (i = 0; i > quantityList.at(i); cin>> foodList.at(i); 20 cin >> quantityAsked; 21/ Your code goes here */ return 0: 7arrow_forward
- Integer numin is read from input. Given the integer vector yearlySalary with the size of numin, write a for loop to initialize the first half of yearlySalary with the remaining integers read from input. Ex: If the input is 6 116 132 134 then the output is: 116 132 134 0 0 0 Note: The vector size is always even. 5 int main() { 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21} vector yearlySalary; unsigned int i; int numIn; cin >> numIn; // Creates a vector of size numIn and initialize all values to 0 yearlySalary.resize(numIn); /* Your code goes here */ for (i = 0; i < yearlySalary.size(); ++i) { cout << yearlySalary.at (i) << " "; } return 0;arrow_forwardCould you correct the errorarrow_forwardWhat is the solution of this problem using java language?arrow_forward
- Using JavaScriptDefine a function getMonth which accepts number from 1 to 12 as an argument and return the descriptive name of the month. For example: getMonth(1) should return January while getMonth(12) returns December, finally getMonth(-1) returns null. Use array or object to define a list of names for the month and refrain from using if statement to check the argument if it's 1, 2, etc.arrow_forwardOutput each floating-point value with two digits after the decimal point, which can be achieved by executingcout << fixed << setprecision(2); once before all other cout statements. Also output the total weight, by summing the vector's elements.arrow_forwardWrite code for determining the index of a value in an OrderedVector. Be aware that if the value is not in the Vector, the routine returns the ideal location to insert the value. This may be a location that is outside the Vector(use java)arrow_forward
- Complete the drawTriangle() function in script.js that draws a triangle with asterisks (*) based on the triangleSize parameter. Ex: drawTriangle(4) outputs to the console a triangle with triangleSize 4, so the longest side (4 asterisks) appears on the bottom line: * ** *** **** Hint: Use a loop inside a loop to complete drawTriangle(). The outer loop is responsible for outputting each asterisk line, and the inner loop is responsible for building the asterisk line with the appropriate length by concatenating asterisks to a single string. To test the JavaScript in your web browser, call drawTriangle() from the JavaScript console.arrow_forwardFill in the blanks of initialization of std::vector of int type, an_int_vec with content (1, 2, 3). std Then fill in the blanks in such a way that the following for loops simply prints 1, 2, 3, to standard output. for(int i = 0; i an_int_vec {1, 2, 3); an_intem: [an int vec₁) U 61 (); i++){ D<< ""; • you must assume using namespace std; has not being used • assume the regular for loop pattern in the question abovearrow_forwardWhich loop outputs all of the elements of vector v(20)? int i; for( i = 0;i <= 20; ++i) cout << v.at(i) <« endl; } int i; for( i = 0; i< 20; ++i) cout << wat(i) << endl; int i; for( i = 0; i < 20; ++i) cout << vector.at(i) << endl; int i; for( i = 0; i <= 20; ++i) cout << vector.at(i) < endl;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
9.1: What is an Array? - Processing Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=NptnmWvkbTw;License: Standard Youtube License