Skip to Content
Navigating C++ and Object-Oriented Design
book

Navigating C++ and Object-Oriented Design

by Paul Anderson, Gail Anderson
October 1997
Intermediate to advanced
800 pages
20h 48m
English
Pearson
Content preview from Navigating C++ and Object-Oriented Design

9.8. Exercises

1: Write a template reverse() function to reverse elements of a generic array in place. Can you use the template swap() function from page 391? Write a display() template function to show your results.
// reverse.c - reverse array elements in place 
#include <iostream.h>
#include "String.h"

int main()
{
   static int a[5] = { 12, 47, -33, 101, 56 };
   reverse(a, 5);
   display(a, 5);

   static String b[4] = { "one", "two", "three", "four" };
   reverse(b, 4);
   display(b, 4);
   return 0;
}

$ reverse
56 101 -33 47 12
four three two one
2:Write a template move() function that copies arrays of generic objects for a specific count. Here are several examples of move() with String objects and integers.
 String a[100], b[100]; // a and b are arrays of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Exploring C++20: The Programmer's Introduction to C++

Exploring C++20: The Programmer's Introduction to C++

Ray Lischner

Publisher Resources

ISBN: 0135327482Purchase book