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 6STE
Suppose you want to run the following code, where v is a
for (p = v.begin(); p != v.end(); p++) cout << *p << " "; |
Which of the following are possible ways to declare p?
std::vector<int>::iterator p; std::vector<int>::const_iterator p; |
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In c++ iv read from a text file containing integers
Example
11,1
22, 3
12, 4
And stored each colum in a vector
vectorx and vectory
How can i make a class for x integers and class for y integers
I will use this classes to compare these x and y integers
Which of the following is NOT a correct instantiation of the Vector class?
Select one:
a. Vector v1 = new Vector(4);
b. Vector v2 = new Vector(4, 1);
c. Vector v = new Vector();
d. Vector v2 = new Vector(4, 1, 2);
In c++ please
Write the RemoveEvens() function, which receives a vector of integers as a parameter and returns a new vector of integers containing only the odd numbers from the original vector. The main program outputs values of the returned vector.
Hint: If the original vector has even numbers, then the new vector will be smaller in length than the original vector and should have no blank element.
Ex: If the vector passed to the RemoveEvens() function is [1, 2, 3, 4, 5, 6, 7, 8, 9], then the function returns and the program output is:
[1, 3, 5, 7, 9]
Ex: If the vector passed to the RemoveEvens() function is [1, 9, 3], hen the function returns and the program output is:
[1, 9, 3]
#include <iostream>#include <vector>using namespace std;
vector<int> RemoveEvens(vector<int> nums) { /* Type your code here */}
int main() {
vector<int> input(9); input.at(0) = 1; input.at(1) = 2; input.at(2) = 3; input.at(3) = 4; input.at(4) = 5;…
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
Find and correct the error(s) in each of the following segments of code: The following code should output the e...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Why is it necessary to introduce some methods and documentation from plan-based approaches when scaling agile m...
Software Engineering (10th Edition)
Why is the study of database technology important?
Database Concepts (7th Edition)
Write a single pseudocode statement that indicates each of the following: Display the message Enter two numbers...
C How to Program (8th Edition)
When a CPU executes the instructions in a program, it is engaged in what process?
Starting Out with Python (4th Edition)
What common programming language statement, in your opinion, is most detrimental to readability?
Concepts of Programming Languages (11th 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
- Regarding the vector data type in R, which of the following statements is true? A vector can be created by using the v() function. A vector can be created by using the sequence() function. A vector can only contain a single data type at a time. A vector can only contain numbers.arrow_forwardWrite a C++ program that does the following steps: stores 16 integer random numbers in a vector container V. The random numbers range in value (0 – 199). One can generate such numbers by invoking the random number generation function, rand( ) and using the % (mod)operator Prior to using the rand( ) function, initialize the random number generator with the srand(17) Print the entire vector after filling the vector container V Create a function Total(vector iterator, Size) that returns the total sum of the vector V Count the number of values exceeding 85 and print the result Remove all numbers from the vector V that are divisible by 3 Print the entire modified reduced vector after the removal step Create a set S(descending order) from the modified vector V Print Set S Remove the first number in S that is divisible by 4 Print modified Set Sarrow_forwardCreate a function append(v, a, n) that adds to the end of vector v a copy of all the elements of array a. For example, if v contains 1,2, 3, and a contains 4, 5, 6, then v will end up containing 1, 2, 3, 4, 5,6. The argument n is the size of the array. The argument v is a vector ofintegers and a is an array of integers. Write a test driver.arrow_forward
- Create an vector of foods in C++ and then ask user for its favourite food. If favourite food is present then print "your food will be served soon" otherwise print "Sorry".arrow_forward/ Can you explain the output step by step? #include <iostream>#include <vector>using namespace std;int f(int a, int b){cout << a << " " << b << endl;if (b == 0) return a;return f(b, a % b);}struct C{int m = 9;static int s;C(C& c) { m *= c.m; }C(int m) { this->m = m - s; }C() { m++; }C(int m, int n) { m += n; }};int C::s = 2; using namespace std; int main(){cout << f(21, 34) << endl; // (1) -- (10)C w(1, 2), x(3), y, z(w);w.s++; double a = 42, * b = &a, & c = a, d = a;cout << *b << endl; // (16)cout << a-- << endl; // (17)cout << c << endl; // (18)cout << d << endl; // (19)cout << (&c == b) << endl; // (20)return 0;}arrow_forwardWrite a function named addStars that accepts as a parameter a reference to a vector of strings, and modifies the vector by placing a "*" element between elements, as well as at the start and end of the vector. For example, if the vector v contains {"the", "quick", "brown", "fox"}, the call of addStars(v); should modify it to store {"*", "the", "*", "quick", "*", "brown", "*", "fox", "*"}.arrow_forward
- Write a function SwapArrayEnds() that swaps the first and last elements of the function's array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40, 20, 30, 10}. #include <iostream>using namespace std; /* Your solution goes here */ int main() { const int SORT_ARR_SIZE = 4; int sortArray[SORT_ARR_SIZE]; int i; int userNum; for (i = 0; i < SORT_ARR_SIZE; ++i) { cin >> userNum; sortArray[i] = userNum; } SwapArrayEnds(sortArray, SORT_ARR_SIZE); for (i = 0; i < SORT_ARR_SIZE; ++i) { cout << sortArray[i] << " "; } cout << endl; return 0;}arrow_forwardWrite a lambda expression to count odd numbers in the following array, using a seed value of 0. Display your result on Console. int[] array = { 8,2,2,24,5,7,5,3,2,10};arrow_forwardTake a screenshot of your output. write a C++ functions to compute following (Set Theory) #include <iostream>#include <vector>using namespace std;struct rpair {int a;int b;}; void print(std::vector<struct rpair>& R) {for (auto e: R) {cout<<e.a <<" " << e.b <<endl;} } std::vector<int> composition(std::vector<struct rpair>& R, std::vector<struct rpair>& S){} std::vector<struct rpair> cartesian_product(std::vector<int>& a, std::vector<int>& b) { } int main(){//struct rpair x = {10,20};int x = 128;printf("%c\n", x);std::vector<struct rpair> R = {{1, 2}, {1, 6}, {2, 4}, {3, 4}, {3, 6}, {3, 8}};std::vector<struct rpair> S = {{2, 'u'}, {4, 's'}, {4, 't'}, {6, 't'}, {8, 'u'}}; print(R); return 0;}arrow_forward
- In Python please help with the following: a) Write a class in Python called Vector2d whose initializer receives two numbers: x,y.Define an instance method called translateby that receives two numbers: dx and dy and translates the vector by dx and dy. Translating vector v by dx and dy makes the vector's x and y incremented by dx and dy, respectively.For example: (1, 2) translated by 3, and 4 results in (4,6).Define a static method called sum that receives two vectors and returns a newvector whose value equals the sum of the two vectors. B) Test your code by implementing the following:• Create a vector v1, instantiate it with (1, 2).• Create a vector v2, instantiate it with (2, 4).• Calculate the sum of the two vectors in v3.• Translate v3 by 1 and 2.• Print v3's coordinates. It prints 4, 8.arrow_forwardYou have made a device that automatically measures both distance from a magnet and the magnetic field strength at that distance. The device sends the pair of data to your computer as a pair of real numbers. However, the device moves back and forth as it takes data, so neither the field measurement nor the distance measurement arrives in ascending or descending order. Write a code vector_sort that receives a two-dimensional array of numbers and sorts them based on either the first column or the second column (this must be an input to the function. The function must also either sort high-to-low or low-to-high, based on an input value. Write a main function that can read up to twenty pairs of data. The main function must also input whether you want to sort high-to-low or low-to high. It must also input whether you want to sort on magnetic field or distance. Finally the code must print the pair data as originally entered and then, after calling vector_sort, the ordered pair data. C Programarrow_forwardHi doctor I have a homewotk about Vector in java .I don't know anything about it for now, I would like you can help me . He want me to us Vector and print 10 numbers , there sum and the Averagearrow_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