{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lab22 - Lab 22 Source File Input Output Value...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab 22 Due Date: Wednesday, October 12, 2011 Source File: ~/2305/lab22.C Input: under control of main function Output: under control of main function Value: 2 Write a template function whose prototype is given by 1 template<typename T> 2 int NumUnique(const T *array, int n); The function returns the number of unique elements in the range [array, array + n) . A main function for testing your function is shown in Figure 1. The expected output from executing this code is shown in Figure 2. To use the Makefile as distributed in class, add a target of lab22main to targets1srcfile . 1 #include <iostream> 2 #include <string> 3 4 using namespace std; 5 6 // template function prototype 7 template<typename T> 8 int NumUnique(const T *array, int n); 9 10 #include "lab22.C" 11 12 template<typename T> 13 void PrintArray(const T *array, int count) 14 { 15 const T *ptr; 16 const T *const endPtr = array + count; 17 18 for (ptr = array; ptr < endPtr; ptr++) 19 cout << *ptr << " "; 20 21 cout << endl; 22 } 23 24 template<typename T> 25 void PrintAndCountUnique(const T *array, int n, string nameOfArray) 26 { 27
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern