Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 17, Problem 74RQE
// This code has an error.
sort(v);
if (binary_search(v, 1))
cout << "The value 1 is found in the vector.\n";
else
cout << "The value 1 is NOT found in the vector.\n"
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
struct remove_from_front_of_vector {
// Function takes no parameters, removes the book at the front of a vector,
// and returns nothing.
void operator()(const Book& unused) {
(/// TO-DO (12) |||||
// //
// Write the lines of code to remove the book at the front of "my_vector".
//
// Remember, attempting to remove an element from an empty data structure is
// a logic error. Include code to avoid that.
//// END-TO-DO (12) /||,
}
std::vector& my_vector;
};
javascript
Define a function, myIncludes, that accepts two parameters: an array and a searchValue.
myIncludes should return true if the searchValue is an element in the array. Otherwise, myIncludes should return false.
example
myIncludes([10, 20, 30], 20); // => true myIncludes(['apples', 'bananas', 'citrus'], 'pears'); // => false
Your program must use the following five function headers exactly as they appear here:
void getVectorSize(int& size); void readData(vector<Highscore>& scores); void sortData(vector<Highscore>& scores); vector<Highscore>::iterator findLocationOfLargest( const vector<Highscore>::iterator startingLocation, const vector<Highscore>::iterator endingLocation); void displayData(const vector<Highscore>& scores);
The size parameter from the given code won't be needed now, since a vector knows its own size.
using namespace std; const int MAX_NAME_SIZE = 24; struct Highscore{ char name[MAX_NAME_SIZE]; int score; }; void getArraySize(int& size); void readData(Highscore highScores[], int size); void sortData(Highscore highScores[], int size); int findIndexOfLargest(const Highscore highScores[], int startingIndex, int size); void displayData(const Highscore highScores[], int size); int main() { Highscore* highScores; int size;…
Chapter 17 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 17.2 - Prob. 17.1CPCh. 17.2 - Prob. 17.2CPCh. 17.2 - Prob. 17.3CPCh. 17.2 - Suppose you are writing a program that uses the...Ch. 17.2 - Prob. 17.5CPCh. 17.2 - Prob. 17.6CPCh. 17.2 - What does a containers begin() and end() member...Ch. 17.2 - Prob. 17.8CPCh. 17.2 - Prob. 17.9CPCh. 17.2 - Prob. 17.10CP
Ch. 17.3 - Write a statement that defines an empty vector...Ch. 17.3 - Prob. 17.12CPCh. 17.3 - Prob. 17.13CPCh. 17.3 - Write a statement that defines a vector object...Ch. 17.3 - What happens when you use an invalid index with...Ch. 17.3 - Prob. 17.16CPCh. 17.3 - If your program will be added a lot of objects to...Ch. 17.3 - Prob. 17.18CPCh. 17.3 - Prob. 17.19CPCh. 17.4 - Prob. 17.20CPCh. 17.4 - Write a statement that defines a nap named myMap....Ch. 17.4 - Prob. 17.22CPCh. 17.4 - Prob. 17.23CPCh. 17.4 - Prob. 17.24CPCh. 17.4 - Prob. 17.25CPCh. 17.4 - Prob. 17.26CPCh. 17.4 - Prob. 17.27CPCh. 17.5 - What are two differences between a set and a...Ch. 17.5 - Write a statement that defines an empty set object...Ch. 17.5 - Prob. 17.30CPCh. 17.5 - Prob. 17.31CPCh. 17.5 - Prob. 17.32CPCh. 17.5 - If you store objects of a class that you have...Ch. 17.5 - Prob. 17.34CPCh. 17.5 - Prob. 17.35CPCh. 17.6 - Prob. 17.36CPCh. 17.6 - What value will be stored in v[0] after the...Ch. 17.6 - Prob. 17.38CPCh. 17.6 - Prob. 17.39CPCh. 17.6 - Prob. 17.40CPCh. 17.6 - Prob. 17.41CPCh. 17.6 - Prob. 17.42CPCh. 17.7 - Prob. 17.43CPCh. 17.7 - Which operator must be overloaded in a class...Ch. 17.7 - Prob. 17.45CPCh. 17.7 - What is a predicate?Ch. 17.7 - Prob. 17.47CPCh. 17.7 - Prob. 17.48CPCh. 17.7 - Prob. 17.49CPCh. 17 - Prob. 1RQECh. 17 - Prob. 2RQECh. 17 - If you want to store objects of a class that you...Ch. 17 - If you want to store objects of a class that you...Ch. 17 - Prob. 5RQECh. 17 - Prob. 6RQECh. 17 - Prob. 7RQECh. 17 - If you want to store objects of a class that you...Ch. 17 - Prob. 9RQECh. 17 - Prob. 10RQECh. 17 - How does the behavior of the equal_range() member...Ch. 17 - Prob. 12RQECh. 17 - When using one of the STL algorithm function...Ch. 17 - You have written a class, and you plan to store...Ch. 17 - Prob. 15RQECh. 17 - Prob. 16RQECh. 17 - Prob. 17RQECh. 17 - Prob. 18RQECh. 17 - Prob. 19RQECh. 17 - Prob. 20RQECh. 17 - Prob. 21RQECh. 17 - A(n) ___________ container stores its data in a...Ch. 17 - _____________ are pointer-like objects used to...Ch. 17 - Prob. 24RQECh. 17 - Prob. 25RQECh. 17 - The _____ class is an associative container that...Ch. 17 - Prob. 27RQECh. 17 - Prob. 28RQECh. 17 - A _______ object is an object that can be called,...Ch. 17 - A _________ is a function or function object that...Ch. 17 - A ____________ is a predicate that takes one...Ch. 17 - A __________ is a predicate that takes two...Ch. 17 - A __________ is a compact way of creating a...Ch. 17 - T F The array class is a fixed-size container.Ch. 17 - T F The vector class is a fixed-size container.Ch. 17 - T F You use the operator to dereference an...Ch. 17 - T F You can use the ++ operator to increment an...Ch. 17 - Prob. 38RQECh. 17 - Prob. 39RQECh. 17 - T F You do not have to declare the size of a...Ch. 17 - T F A vector uses an array internally to store its...Ch. 17 - Prob. 42RQECh. 17 - T F You can store duplicate keys in a map...Ch. 17 - T F The multimap classs erase() member function...Ch. 17 - Prob. 45RQECh. 17 - Prob. 46RQECh. 17 - Prob. 47RQECh. 17 - Prob. 48RQECh. 17 - T F If two iterators denote a range of elements...Ch. 17 - T F You must sort a range of elements before...Ch. 17 - T F Any class that will be used to create function...Ch. 17 - T F Writing a lambda expression usually requires...Ch. 17 - T F You can assign a lambda expression to a...Ch. 17 - Prob. 54RQECh. 17 - Write a statement that defines an iterator that...Ch. 17 - Prob. 56RQECh. 17 - The following statement defines a vector of ints...Ch. 17 - Prob. 58RQECh. 17 - Prob. 59RQECh. 17 - The following code defines a vector and an...Ch. 17 - The following statement defines a vector of ints...Ch. 17 - Prob. 62RQECh. 17 - Prob. 63RQECh. 17 - Prob. 64RQECh. 17 - Look at the following vector definition: vectorint...Ch. 17 - Write a declaration for a class named Display. The...Ch. 17 - Write code that docs the following: Uses a lambda...Ch. 17 - // This code has an error. arrayint, 5 a; a[5] =...Ch. 17 - // This code has an error. vectorstring strv =...Ch. 17 - // This code has an error. vectorint numbers(10);...Ch. 17 - // This code has an error. vectorint numbers ={1,...Ch. 17 - Prob. 72RQECh. 17 - Prob. 73RQECh. 17 - // This code has an error. vectorint v = {6, 5, 4,...Ch. 17 - // This code has an error. auto sum = ()[int a,...Ch. 17 - Unique Words Write a program that opens a...Ch. 17 - Course Information Write a program that creates a...Ch. 17 - Prob. 3PCCh. 17 - File Encryption and Decryption Write a program...Ch. 17 - Prob. 5PCCh. 17 - Prob. 6PCCh. 17 - Prob. 7PCCh. 17 - Prob. 8PC
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
This will happen if you try to use an index that is out of range for a list a. A valuError exception will occur...
Starting Out with Python (3rd Edition)
What does the Java compiler translate Java source code to?
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Can you use writeInt to write a number to a file and then read that number using readLong? Can you read that nu...
Java: An Introduction to Problem Solving and Programming (8th Edition)
The ________ object is assumed to exist and it is not necessary to include it as an object when referring to it...
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
(De Morgans Laws)In this chapter, we discussed the logical operators **&, Ó� Ó�, and !. De Morgan’s Laws can so...
C How to Program (8th Edition)
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th 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
- In C++ Create a function that takes in a vector, triples the size of the vector, sets all the values to random numbers, and returns the vector.arrow_forward#include <iostream> #include <vector> using namespace std; //Function 1 void vectorOutput(vector<double> doubleVector) { cout<<"Current Vector Contents: "; for (inti = 0; i < doubleVector.size(); i++) { cout<<doubleVector.at(i) <<", "; } cout<<endl; } //Function 2 vector<double> reverseVector(vector<double> doubleVector) { intj = 0; for (inti = 0, j = (doubleVector.size() - 1); i < (doubleVector.size() / 2); i++, j--) { doublervector = doubleVector[i]; doubleVector.at(i) = doubleVector.at(j); doubleVector.at(j) = rvector; } returndoubleVector; } //Function 3 vector<double> vectorInput(vector<double> doubleVector) { cout<<"Enter positive double numbers: "<<endl; while (true) { doubleposVector; cin>>posVector; if (posVector < 0) { break; } else { doubleVector.push_back(posVector); } } returndoubleVector; } int main() { vector<double> doubleVector; vector<double> revVector;…arrow_forward1. Loads a vector with at least 60 randomly generated integers in the range of 0 - 49. 2. Create method to display the values in the vector. 3. Use the following STL templates and display the vector contents for each template used. sort() random_shuffle() Display the result of max_element() Display the result of min_element() #include <iostream>#include <vector>#include <ctime>using namespace std; const int MAX_COUNT = 60;const int CEILING = 50; int main() { vector<int>myList;for (int idx = 0; idx < MAX_COUNT; idx++) { int myNbr = (rand() % CEILING);myList.push_back(myNbr);cout << "myNbr = " << myNbr << endl;} cout << "Size = " << myList.size() << endl;return 0;}arrow_forward
- Write in c++ pleasearrow_forwardC++ Vectors Help: write a program using parallel vectors and a function which fills each of them with 500 random numbers between 1 and 100. The program should then pass both vectors to a function which will return an integer indicating a count of how many times both vectors had even numbers in the same location. So if vector01[0] contained 4 and vector02[0] contained 12, you would add one to count.If vector01[1] contained 3 and vector02[1] contained 4, you would not add one to count. main would display something like : The Vectors contain 128 cells where both values are even. Above was the question: I already have the code written: #include<iostream> #include<vector> #include<cstdlib> #include<ctime> using namespace std; int main() { int even = 0; srand(time(0)); vector <int> vector01; vector <int> vector02; for (int i = 0; i < 500; i++) { vector01.push_back(rand() % 100 + 1); vector02.push_back(rand() % 100 + 1); if (vector01[i] % 2 == 0…arrow_forwardIn C++ Language Write a function that takes a 1 Demensional array and an integer n and returns the nubmer of times 'n' appears in the array. if 'n' does not appear in the array, return -1.arrow_forward
- 1- Persistent variables cannot be accessed from outside the function. (True or False 2- Define a 5*1 empty cell array and then fill it with ones. 3- If A=[5 2] and B-[8; 9; 6] then create 3*3 matrix by concatenating A and B. 4- If S=struct([1), then the size(S)= 5- What is the value of I= any([1, 0, 3]&&[0, 8, 0]) in Matlab? I= 6- If K=[2 5 7], then max(K, 5.5)= matlabarrow_forwardIn c++, ask the user to enter numbers to be sorted. Add them to the vector. The user will signal the end of input by giving you a negative number.Then, sort the vector and print it.arrow_forwardmain.cpp 1 #include 2 using namespace std; 4 int main() 5- { vector v = {1,1,2,3,3,3,4,5,6,6,7}; int 1 = 0; 8. v[1] = v[r]; } cout<<"Unique elements of the vector: "; //printing elements upto index l+1 for(int i=0;i<=1;i++){ cout<arrow_forwardc++ A lottery ticket buyer purchases 10 tickets a week, always playing the same 10 5-digit “lucky” combinations. Write a program that initializes an array or a vector with these numbers and then lets the player enter this week’s winning 5-digit number. The program should perform a linear search through the list of the player’s numbers and report whether or not one of the tickets is a winner this week. Here are the numbers: 13579 26791 26792 33445 55555 62483 77777 79422 85647 93121 If the user enters a number that is not in the array, the program should display a message indicating that the number is invalid.arrow_forwardThis one. in c++arrow_forwardC++ Help Integers are read from input and stored into a vector until 0 is read. Output the elements from index n to the last index of the vector, where n is specified by the vector's last element. End each number with a newline. Ex: If the input is 7 12 18 2 0, the vector's last element is 2. Thus, the output is: 18 2 Note: The input has at least three integers, and the vector's last element is always less than the vector's size. #include <iostream>#include <vector>using namespace std; int main() { vector<int> intVect; int value; int i; int n; cin >> value; while (value != 0) { intVect.push_back(value); cin >> value; } // insert code here return 0;}arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License