Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 18.1, Problem 4STE
Suppose the
vector<char>::iterator i = v.begin(); i++; cout << *(i + 2) << " "; i−−; cout << i[2] << " "; cout << *(i + 2) << " "; |
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
6. A three-dimensional vector has the form:
A = (x, y, z)
can be represented as:
given the vectors:
Example:
Their sum is:Example:
struct VECTOR { double x; double y; double z; };
A = ( a, b, c ) (5, 6, 2)
and
B = ( d, e, f ) (3, 1,9)
A + B = ( a + d, b + e, c + f ) (5 + 3, 6 + 1, 2 + 9)
= (8, 7,11)A B = a x d + b x e + c x f
Their scalar product is:(result is a scalar) example: 5 x 3 + 6 x 1 + 2 x 9 = 39
Write the complete definition code for the functions:
a. calc_sum computes and returns the sum of two vectors
b. scalar_prod computes and returns the scalar product of two vectors
Using R software, create a function that returns the square root of a vector x. However, it uses a tryCatch statement so that if x has negative numbers, then it returns x as it is and issues a warning that x contains negative numbers. Otherwise, it returns the square root of x
Question: Take a look at the following two code examples for printing a vector:
Sample Code 1:
vector vec;
/*
.... ...
for (auto itr = vec.begin(); itr != vec.end(); itr++) {
itr->print();
}
Sample Code 2:
vector vec;
/* . */
...
for (auto itr = vec.begin(); itr !=vec.end(); ++itr) {
itr->print();
}
Is there any advantage of using one over the other?
Chapter 18 Solutions
Problem Solving with C++ (9th 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. 9PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What Ada construct provides support for abstract data types?
Concepts Of Programming Languages
Write an if statement that assigns 20 to the variable y. and assigns 40 to the variable z if the variable x is ...
Starting Out with Python (4th Edition)
A file that contains a Flash animation uses the __________ file extension. a. .class b. .swf c. .mp3 d. .flash
Web Development and Design Foundations with HTML5 (8th Edition)
Leap Year Detector Design a program that asks the user to enter a year, and then displays a message indicating ...
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Assume that the reference variable r refers to a serializable object. Write code that serializes the object to ...
Starting Out with Java: From Control Structures through Objects (6th Edition)
Circuit Board Profit An electronics company sells circuit boards at a 40 percent profit. If you know the retail...
Starting Out with Java: From Control Structures through Data Structures (3rd 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
- 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_forwardWrite a function that removes duplicates from a vector. For example, if remove duplicates is called with a vector containing 1 4 9 16 9 7 4 9 11 (use these numbers) then the vector is changed to 1 4 9 16 7 11arrow_forwardCreate a function set(v, i, j) that makes vector v contain the integers i through j. The original contents of v is deleted. The vector is left empty ifj < i. The argument v is a vector of integers.arrow_forward
- in C++ mathematical functions languagearrow_forward3. Use two vectors and make them into one. Use the following vectors:Vector#1 {1, 1, 5, -3, 0}Vector#2 {9,7,2}Return a vector containing 1, 1, 5, -3, 0, 9, 7, 2 (in that order)arrow_forwardimport 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…arrow_forward
- t. Given a string as a parameter to the function, return a square grid filled with all the characters of the string from left to right. Fill empty spaces in the grid with '_'. Sample Input: stringtogrid Output: {{s, t, r, i}, {n, g, t, o}, {g, r, i, d}, {_, _, _, _}} Complete the function: vector<vector<int> formGrid(string s){}arrow_forwardin C++ 3D Vector languagearrow_forwardWhy is the code in (a) wrong, but the code in (b) correct?arrow_forward
- This in C++.arrow_forwardC++arrow_forwardConsider the following code: int main (void) ( std::vector intVector(0); } intVector.pushback(1); intVector.pushback(2); intVector.pushback(3); // Vector of 0 ints a. Draw the memory layout of intVector when the code is finished. b. Where in memory is intVector allocated?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