< previous page page_616 next page >

Page 616
Module Structure Chart:
0616-01.gif
//******************************************************************
// CheckLists program
// There are two lists of integers in a data file, separated by a
// negative integer. This program compares the two lists. If they
// are identical, a message is printed. If not, nonmatching pairs
// are printed. Assumption: The lists are of equal length
//******************************************************************
#include <iostream.h>
#include <iomanip.h>    // For setw()
#include <fstream.h>    // For file I/O
#include "bool.h"        // For Boolean type

const int MAX_NUMBER = 500;      // Maximum in each list

void CompareLists( Boolean&, const int[], int, ifstream& );
void ReadFirstList( int[], int&, ifstream& );

int main()
{
    int      firstList[MAX_NUMBER];  // Holds first list
    Boolean  allOK;                  // True if lists are identical
    int      length;                 // Length of first list
    ifstream dataFile;               // Input file

    dataFile.open("lists.dat");
    if ( !dataFile )
    {
        cout << "** Can't open input file **" <<  endl;
        return 1;
    }

    ReadFirstList(firstList, length, dataFile);
    allOK = TRUE;
    CompareLists(allOK, firstList, length, dataFile);
    if (allOK)
        cout << "The two lists are identical" << endl;

 
< previous page page_616 next page >