Public feed #892188

Miscellany

public text v1 · immutable
Raw Edit
·published 2008-02-05 05:28 UTC
rendered paste body
//Ryan Weber Program 0
# include <iostream>
using namespace std;
                                
int main()
{
        int counter=0;
        char ch;
        int lnct=0;
        int chct=0;
        const int DefaultListSize=100;
        typedef Elem = char;
        class Astack
        {
                private:
                        int size;
                        int top;
                        Elem *listArray;
                public:
                        Astack(int sz =DefaultListSize)
                        {
                                size=sz;
                                top=0;
                                listArray=new Elem[sz];
                        }
                        ~Astack() {delete [] listArray;}
                        void clear() {top=0;}
                        bool push(const Elem& item)
                        {
                                if (top == size) return false;
                                else { listArray[top++] = item; return true;}
                        }
                        bool pop(Elem& it)
                        {
                                if (top==0) return false;
                                else { it= listArray[--top];
                        }
                        bool topValue(Elem& it) const
                        {
                                if (top == 0) return false;
                                else { it = listArray[top-1]; return true;}
                        }
                        int length() const {return top;}
                        bool IsEmpty() const {return (top==0);}
                };

        while((ch=cin.get())!=EOF)
        {
                if (ch!='\n')
                {
                        chct++;
                        cout<< ch << " ";
                        cout<<"The number of characters is: " << chct << endl;
                }
                else
                {
                        lnct++;
                        cout<<endl;
                        cout<<"The number of lines is: " << lnct << endl;
                }
                //cout<<"The number of characters is: " << chct << endl;
                //cout<<"The number of lines is: " << lnct << endl;
                         
        }
        cout<<"Programmer: Ryan Weber \n  Class: CS 258\n\n";
        return 0;
}  //end main