Personal tools
You are here: Home Projects C++ Cfront releases Release 3.0.3 source demo lang try_array.C
Document Actions

try_array.C

by Michael L Powell last modified 2007-01-26 03:20

Click here to get the file

Size 1.6 kB - File type text/plain

File contents

/*ident	"@(#)cls4:demo/lang/try_array.C	1.1" */
/*#########################################################################
#                       Copyright (c) 1991 AT&T
#                         All Rights Reserved   
#
#                THIS IS PROPRIETARY SOURCE CODE OF AT&T
#       
#                     This code has been published in
#                         C++ Primer, 2nd Edition 
#			    by Stanley Lippman
#                    Addison_Wesley Publishing Company
#
#########################################################################*/
#include "Array.h"

template <class Type>
void try_array( Array<Type> &iA ) 
{ // exercise the array class
    cout << "try_array: initial array values:\n";
    cout << iA << endl;

/*
    Type find_val = iA[iA.getSize()-1];
*/
    iA[iA.getSize()-1] = iA.min(); 

    int mid = iA.getSize()/2;
    iA[0] = iA.max(); iA[mid] = iA[0];
    cout << "try_array: after assignments:\n";
    cout << iA << endl;

    Array<Type> iA2 = iA; 
    iA2[mid/2] = iA2[mid];
    cout << "try_array: memberwise initialization\n";
    cout << iA << endl;

    iA = iA2;
    cout << "try_array: after memberwise copy\n";
    cout << iA << endl;

    iA.grow();
    cout << "try_array: after grow\n";
    cout << iA << endl;

    /* commented out since Demo tests depend on ``correctness''
     * and the ability of diff to compare exactly -- remove if
     * programs are run by hand -- more interesting!!! 

    int index = iA.find(find_val);
    cout << "value to find: " << find_val;
    cout << "\tindex returned: " << index << endl;
    Type value = iA[index];
    cout << "value found at index: " << value << endl;
    */
}
« May 2024 »
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: