Question: UPDATE** Template Classes Chapter 12 1. Write an example of a template function t hat can swap 2 generic elements (page 462 code example 12.8).

UPDATE**

Template Classes Chapter 12

1. Write an example of a template function that can swap 2 generic elements (page 462 code example 12.8).
2. Create a C++ class vector using the class diagram shown in Figure 12.2. in Liangs textbook. Do not use the C++ provided header file
3. Write a test that unit tests the public interface of this class (Look at listing 12.8 on page 472).

 UPDATE** Template Classes Chapter 12 1. Write an example of a
template function that can swap 2 generic elements (page 462 code example
12.8). 2. Create a C++ class vector using the class diagram shown

72 Chapter 12 Templates. Vectors, and Stacks vectorcelementType> +vectorO +vector(size: +vector (size: Constructs an empty vector with the specified element type Constructs a vector with the initial size, filled with default vales Constructs a vector with the initial size, filled with specified valus int) int, defaultValue: elementType) +push_backCelement: elementType): voi +pop backO: void +sizeO: unsigned const +at Cindex: int): elementType const +emptyO: bool const +clear): void +swap(v2: vector): void Appends the element in this vector Removes the last element from this vector. Returns the number of the elements in this vector Returns the element at the specified index in this vector Returns true if this vector is empty. Removes all elements from this vector. Swaps the contents of this vector with the specified vector FIGURE 12.2 The vector class functions as a resizable array You can also create a vector with the initial size, filled with default values. For the following code creates a vector of initial size 10 with default values 0 vectorcint> intVector

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!