------------------------------------------------------------------------------
MC logo
C++ Int Stack Driver
[^] Names and Scope
------------------------------------------------------------------------------
[Ch. 1: Overview and History] [Syntax] [Names and Scope] [Types and Type Systems] [Semantics] [Functions] [Memory Management] [Imperitive Programs and Functional Abstraction] [Modular and Class Abstraction] [Functional Programming] [Logic Programming]
[Java Class Scope] [Ada Int Stack Package] [Ada Int Stack Impl] [Ada Int Stack Driver] [Java Int Stack Class] [Java Int Stack Driver] [C++ Int Stack Class] [C++ Int Stack Impl] [C++ Int Stack Driver]
driver.cpp
/*
 * A simple client of the IntStack package.
 */

#include <iostream>
using namespace std;

#include "intstack.h"

int main(int argc, char **argv)
{
        IntStack s1, s2;        // Two test stacks.
        int cnt = 1;            // Uh...  A counter.

        // Read in integers until -1, and push each on one stack, and each
        // times the input ordinal on the other.
        int intin;              // Integer read in.
        while(true) {
                cout << "> ";
                cin >> intin;
                if(intin == -1) break;
                s1.push(intin);
                s2.push(cnt*intin);
                ++cnt;
        }

        // Pop 'em and print 'em
        while(!s1.isEmpty()) {
            int inout1 = s1.pop();
            int inout2 = s2.pop();
            cout << inout1 << " " << inout2 << endl;
        }
}