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 vector of ints. Write a for loop that outputs all the elements of v, except for the first element.
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
How are the spot welds produced by gas tungsten arc spot welding different from those made by conventional resi...
Degarmo's Materials And Processes In Manufacturing
Consider the following program: a. What output does the program produce? b. What output would the program produ...
Java: An Introduction to Problem Solving and Programming (8th Edition)
Cookie Calories A bag of cookies holds 40 cookies. The calorie information on the bag claims that there are 10 ...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Suppose the registers 0x4 and 0x5 in the Vole contain the bit patterns 0x3A and 0xC8, respectively. What bit pa...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
ESP Game Write a program that tests your ESP (extrasensory perception). The program should randomly select the ...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Why is the study of database technology important?
Database Concepts (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 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)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); }…arrow_forwardGiven two arrays A and B of equal size N, the task is to find a vector containing only those elements which belong to exactly one array - either A or B - but not both. That is, if some element x appears in both A and B it should not be included in the output vector. Complete the implementation of "getVector(vector<ll>A, vector<ll>B, int N)" function. Example: Input: 1 3 5 7 1 3 2 4 6 7 8 Output: 3 5 1 3 2 4 6 8 The driver codes are attached in the images below. DO NOT CHANGE THE PROVIDED DRIVER CODES AT ALL, LEAVE THEM EXACTLY THE SAME. ONLY ADD CODE TO THE "getVector(vector<ll>A, vector<ll>B, int N)" FUNCTIONarrow_forwardWrite a function that accepts a number, N, and a vector of numbers, V. The function will return two vectors which will make up any pairs of numbers in the vector that add together to be N. Do this with nested loops so the the inner loop will search the vector for the number N-V(n) == V(m). n and m are indices in the vector of numbers. Example A = [1,2,3,4,5,6, 7] Google(5, A) Return [1,2,3,4] and [4,3,2,1] being the pairs that sum to 5. Notice that each pair appears twice. Try to write code that does not do this.arrow_forward
- numStudents is read from input as the number of input values in the vector that follow. Use two for loops to output all numStudents elements of vector walkingLogs that are: even integers • odd integers ● For both loops, follow each element with a space, including the last element, and end with a newline. Ex: If the input is 8 11 30 70 39 69 29 138 162, then the output is: 30 70 138 162 11 39 69 29 3 using namespace std; 4 5 int main() { 6 7 8 9 10 11 12 13 14 15 16 17 18 19} int numStudents; int i; cin >> numStudents; vector walkingLogs (numStudents); for (i = 0; i > walkingLogs.at(i); } * Your code goes here */ return 0; ►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_forwardnumMembers is read from input as the size of the vector. Then, numMembers elements are read from input into the vector bikingRoster. Use a loop to access each element in the vector and if the element is less than averageMembers, output the element followed by a space. Ex: If the input is 8 193 102 3 86 38 161 169 153, then the output is: Average: 113 Numbers less than average: 102 3 86 38 1 #include 2 #include 3 using namespace std; 4 5 int main() { 6 7 unsigned int i; 8 double averageMembers; 9 int sumElementData = 0; 10 11 12 13 14 15 16 int numMembers; cin >> numMembers; vector bikingRoster (numMembers); for (i = 0; i > bikingRoster.at(i); sumElement Data + bikingRoster at(i):arrow_forward
- answer properlyyarrow_forwardDeclare a vector of 15 doubles. Using a loop, set all the elements of your vector to 140.041. Write a function named print Vector that returns nothing and takes by constant reference a vector of doubles. The function should print every element of the vector, followed by a newline. Use this function to print out your vector from Assignment 1 above. Using the at() function, change the value of the first two elements to -1.0. Using the push_back () function to add two new elements at the end of the vector with values -10.3 and -20.3. Now use the sort () function on the vector. Using your function from Assignment 2, print the vector. Write a program that takes keyboard input from a user and puts what they type into a string. Print out the number of characters they just typed. Change the first character of the string to 'x'. Now append "<- you typed this!" to the string. Now print the modified string with cout. Caign Declare a vector of 5 strings. In a loop, read from the keyboard into each…arrow_forwardInteger numValues is read from input. Then numValues integers are read and stored in vector weeklyRentList. Write a loop that outputs each element in weeklyRentList that is less than 100, and assigns the element with twice the element's current value. End each output with " is corrected to twice the current value' followed by a newline. Ex: If the input is 3 31 143 105, then the output is: Raw weekly rent: 31 143 105 31 is corrected to twice the current value Adjusted weekly rent: 62 143 105 1 #include 2 #include 3 using namespace std; 4 5 int main() { 6 int numValues; 7 unsigned int i; 0 vector weeklyRentList; cin >> numValues; 10 11 weeklyRentList.resize(numValues); for (i = 0; i > CS Scanned 12 13 14 17 18 cout << "Raw weekly rent: " ローローarrow_forward
- Integer 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/arrow_forwardInteger 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_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