SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,kenrick Mock
Chapter:
Standard Template Library
Exercise:
Programming Projects
Question:5 | ISBN:9780132846813 | Edition: 5

Question

Continuing Programming Project 19.4, write a function that separates the students in the vector of StudentInfo records into two vectors, one containing records of passing students and one containing records of failing students. (Use a grade of 60 or better for passing.)

You are asked to do this in two ways, and to give some run-time estimates.

a. Consider continuing to use a vector. You could generate a second vector of passing students and a third vector of failing students. This keeps duplicate records for at least some of the time, so do not do it that way. You could create a vector of failing students and a test-for-failing function. Then you push_back failing student records, then erase (which is a member function) the failing student records from the original vector. Write the program this way.

b. Consider the efficiency of this solution. You are potentially erasing O ( N ) members from the middle of a vector. You have to move a lot of members in this case. Erase from the middle of a vector is an O ( N ) operation. Give a big-O estimate of the running time for this program.

c. If you used a list<StudentInfo>, what is the run time for the erase and insert functions? Consider how the time efficiency of erase for a list affects the runtime for the program. Rewrite this program using a list instead of a vector. Remember that a list provides neither indexing nor random access, and its iterators are only bidirectional, not random access.


TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.