When calling resize (while implementing some of the member functions) to increase the capacity of the dynamic arrays, use the following resizing rule (unless the new capacity has to be something else higher as dictated by other overriding factors): ● "new capacity" is "roughly 1.5 * old capacity" and at least "old capacity + 1". The latter (at least "old capacity + 1") is a simple way to take care of the subtle case where "1.5"old capacity" evaluates (with truncation) to the same as "old capacity". (TIP: "int(1.5*old capacity) + 1" is a formula you can use to rather painlessly compute "new capacity" satisfying the above.)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
■
DON'T use assert in constructors, destructor, operator= (assignment operator) and resize.
Parameters (that carry preconditions) to be checked for validity and appropriately adjusted where needed.
Example: Parameter (specifying initial capacity) of a one-parameter constructor should be checked and appropriately adjusted where needed to avoid allocating an array sized less than
Example: Parameter (specifying new capacity) of resize should be checked and appropriately adjusted where needed to enable preservation of existing data and avoid allocating an array sized
less than 1.
It's part of caller's responsibility to specify a desired new capacity when calling resize.
·
Obligation to follow certain ad hoc resizing rule (see under Special Requirement above) should be relevant only to the caller.
Implementation of resize should play no part in the enforcement of any such rule.
(In other words, it's not logically sound for implementation to incorporate any aspects of any resizing rule.)
(Implementation of resize should do appropriate checking/adjusting, however, as indicated above.).
Resizing can be expensive so resize should be called sparingly.
·
It's usually unwise to resize to just what's immediately needed.
(This is actually the main reason for the resizing rule specified under Special Requirement above.)
Similarly, one'd call resize to free up some unused capacity only under truly warranted circumstances.
(For simplicity of this excercise, let's NOT do any such resizing at all.)
Transcribed Image Text:■ DON'T use assert in constructors, destructor, operator= (assignment operator) and resize. Parameters (that carry preconditions) to be checked for validity and appropriately adjusted where needed. Example: Parameter (specifying initial capacity) of a one-parameter constructor should be checked and appropriately adjusted where needed to avoid allocating an array sized less than Example: Parameter (specifying new capacity) of resize should be checked and appropriately adjusted where needed to enable preservation of existing data and avoid allocating an array sized less than 1. It's part of caller's responsibility to specify a desired new capacity when calling resize. · Obligation to follow certain ad hoc resizing rule (see under Special Requirement above) should be relevant only to the caller. Implementation of resize should play no part in the enforcement of any such rule. (In other words, it's not logically sound for implementation to incorporate any aspects of any resizing rule.) (Implementation of resize should do appropriate checking/adjusting, however, as indicated above.). Resizing can be expensive so resize should be called sparingly. · It's usually unwise to resize to just what's immediately needed. (This is actually the main reason for the resizing rule specified under Special Requirement above.) Similarly, one'd call resize to free up some unused capacity only under truly warranted circumstances. (For simplicity of this excercise, let's NOT do any such resizing at all.)
When calling resize (while implementing some of the member functions) to increase the capacity of the dynamic arrays, use the following resizing rule (unless the new capacity has to be something else
higher as dictated by other overriding factors):
"new capacity" is "roughly 1.5 * old capacity" and at least "old capacity + 1".
The latter (at least "old capacity + 1") is a simple way to take care of the subtle case where "1.5*old capacity" evaluates (with truncation) to the same as "old capacity".
(TIP: "int(1.5*old capacity) + 1" is a formula you can use to rather painlessly compute "new capacity" satisfying the above.)
Transcribed Image Text:When calling resize (while implementing some of the member functions) to increase the capacity of the dynamic arrays, use the following resizing rule (unless the new capacity has to be something else higher as dictated by other overriding factors): "new capacity" is "roughly 1.5 * old capacity" and at least "old capacity + 1". The latter (at least "old capacity + 1") is a simple way to take care of the subtle case where "1.5*old capacity" evaluates (with truncation) to the same as "old capacity". (TIP: "int(1.5*old capacity) + 1" is a formula you can use to rather painlessly compute "new capacity" satisfying the above.)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY