All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Hire a Tutor
AI Study Help
New
Search
Search
Sign In
Register
study help
computer science
programming principles and practice
Questions and Answers of
Programming Principles and Practice
What is a binary search?
Why use a copy() algorithm when we could “just write a simple loop”?
How does a multimap differ from a map?
How does a set differ from a map?
Why would anyone use an unordered_map when an (ordered) map is available?
How much space per element does a vector take up?
How much space per element does a map take up?
What (roughly) does it mean for a tree to be balanced?
Provide a GUI for the program from the previous exercise.Data from Previous ExerciseWrite a program (using the output from the previous exercise) to answer questions such as: “How many occurrences
What is the basic ordering property of binary tree?
Write a program (using the output from the previous exercise) to answer questions such as: “How many occurrences of ship are there in a file?” “Which word occurs most frequently?” “Which is
Is list an associative container? Why not?
Write a program to “clean up” a text file for use in a word query program; that is, replace punctuation with whitespace, put words into lower case, replace don’t with do not (etc.), and remove
What is an associative container? Give at least three examples.
Provide a GUI interface for querying a file of Orders; e.g., “Find all orders from Joe,” “Find the total value of orders in file Hardware,” and “List all orders in file Clothing.”
What does inner_product() do?
Provide a GUI interface for entering Orders into files.
What does accumulate() do?
Compute the total value of the orders in the two files from the previous exercise. The value of an individual Purchase is (of course) its unit_price*count.Data from Previous ExerciseDefine an Order
What is a predicate?
Define an Order class with (customer) name, address, data, and vector members. Purchase is a class with a (product) name, unit_price, and count members. Define a mechanism for reading and writing
In which ways does a function object differ from a function?
Take the word-frequency example from §21.6.1 and modify it to output its lines in order of frequency (rather than in lexicographical order). An example line would be 3: C++ rather than C++: 3.
What is a function object?
Write a binary search function for a vector (without using the standard one). You can choose any interface you like. Test it. How confident are you that your binary search function is correct? Now
How does an STL algorithm usually indicate “not found” or “failure”?
In the Fruit example in §21.6.5, we copy Fruits into the set. What if we didn’t want to copy the Fruits? We could have a set instead. However, to do that, we’d have to define a comparison
How does an STL algorithm take a container as an output argument?
What would we have to do if we couldn’t return end() to indicate “not found”? Redesign and re-implement find() and count() to take iterators to the first and last elements. Compare the results
How does an STL algorithm take a container as an input argument?
Implement count_if() yourself. Test it.
What does sort(b,e) use as its sorting criterion?
Implement count() yourself. Test it.
What does count_if() do?
Find a reliable source of STL documentation and list every standard library algorithm.
What does find() do? Give at least five examples.
Go through the chapter and do all Try this exercises that you haven’t already done.
What are examples of useful STL algorithms?
What operations are provided by a random-access iterator, but not a bidirectional iterator?
What is an iterator category? What kinds of iterators does the STL offer?
What containers does the STL provide?
What should begin() and end() do for a container?
What is a container?
When would you use a list rather than a vector?
Run a small timing experiment to compare the cost of using vector and list. You can find an explanation of how to time a program in §26.6.1. Generate N random int values in the range [0:N ). As each
When would you use a string rather than a vector?
Define a range-checked iterator for list (a bidirectional iterator).
How do you iterate over a container using the STL?
Define a range-checked iterator for vector (a random-access iterator).
What operations does an iterator for a list provide?
Define an ownership_vector that hold pointers to objects like pvector but provides a mechanism for the user to decide which objects are owned by the vector (i.e., which objects are deleted by the
How do you know if a sequence is empty?
Define an ovector that is like pvector except that the [ ] and * operators return a reference to the object pointed to by an element rather than the pointer.
What does insert() do? What does erase() do?
Define a pvector to be like a vector of pointers except that it contains pointers to objects and its destructor deletes each object.
What is a link (in a linked list)?
Define a singly-linked list, slist, in the style of std::list. Which operations from list could you reasonably eliminate from slist because it doesn’t have back pointers?
What is a linked list? How does it fundamentally differ from a vector?
We don’t really need a “real” one-past-the-end Link for a list. Modify your solution to the previous exercise to use 0 to represent a pointer to the (nonexistent) one-past-the-end Link
What is the STL?
Complete the definition of list from §20.4.1–2 and get the high() example to run. Allocate a Link to represent one past the end.
Given a list as a (by-reference) parameter, make a vector and copy the elements of the list into it. Verify that the copy was complete and correct. Then print the elements sorted in order of
Define a version of the word-counting program where the user can specify the set of whitespace characters.
Define a program that counts the number of words in a Document. Provide two versions: one that defines word as “a whitespace-separated sequence of characters” and one that defines word as “a
Define a function that counts the number of characters in a Document.
Find the lexicographical last string in an unsorted vector.
Write a find-and-replace operation for Documents based on §20.6.2.
Define an input and an output operator (>> and <<) for vector.
Find and fix the errors in the Jack-and-Jill example from §20.3.1 by using STL techniques throughout.
Look at the palindrome examples (§18.7); redo the Jack-and-Jill example from §20.1.2 using that variety of techniques.
Get the Jack-and-Jill example from §20.1.2 to work. Use input from a couple of small files to test it.
What is unique_ptr good for?
What is RAII? What problem does it address?
What is a resource leak?
What is a resource? Define and give examples.
How does resize() differ from reserve()?
Sometimes, it is desirable that an empty vector be as small as possible. For example, someone might use vector>> a lot but have most element vectors empty. Define a vector so that
How does array differ from the built-in array?
Modify the program from the previous exercise to allow the user to mark rooms based on knowledge and guesses, such as “maybe bats” and “bottomless pit.”Data from Previous ExerciseProvide a
How does array differ from vector?
Provide a GUI interface and a bit of graphical output to the “Hunt the Wumpus” game from the exercises in Chapter 18. Take the input in an input box and display a map of the part of the cave
How does generic programming differ from object-oriented programming?
Write a Tracer class where its constructor prints a string and its destructor prints a string. Give the strings as constructor arguments. Use it to see where RAII management objects will do their job
What is generic programming?
Define a File_handle class with a constructor that takes a string argument (the file name), opens the file in the constructor, and closes it in the destructor.
What are the two most useful types of template arguments?
Design and implement a counted_ptr that is a type that holds a pointer to an object of type T and a pointer to a “use count” (an int) shared by all counted pointers to the same object of type T.
What is a template?
Implement a simple unique_ptr supporting only a constructor, destructor, –>, *, and release(). In particular, don’t try to implement an assignment or a copy constructor.
What is the default meaning of copy for class objects?
Re-implement vector::operator=() (§19.2.5) using an allocator (§19.3.7) for memory management.
Which two operations define copy for vector?
Implement an allocator (§19.3.7) using the basic allocation functions malloc() and free() (§B.11.4). Get vector as defined by the end of §19.4 to work for a few simple test cases. Hint: Look up
What is the value of a vector after a copy?
Try your solution to exercise 2 with some Numbers.Data from Exercise 2Write a template function that takes a vector vt and a vector vu as arguments and returns the sum of all vt[i]*vu[i]s.
Which vector operations can change the size of a vector after construction?
Repeat the previous exercise, but with a class Number where T can be any numeric type. Try adding % to Number and see what happens when you try to use % for Number and Number.Data from Previous
When must we copy vector elements to a new location?
Define a class Int having a single member of class int. Define constructors, assignment, and operators +, –, *, / for it. Test it, and improve its design as needed (e.g., define operators <<
How much spare space do we allocate for a new vector?
Showing 1 - 100
of 628
1
2
3
4
5
6
7