#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Elkhart, Indiana
    Posts
    3
    Rep Power
    0

    Inputting File on into a STACK [HELP NEEDED]


    How's everyone doing? I've been working the program below for some time and cannot figure what the problem is.

    I have to take a data file (that I have named rsize.dat) and input the values on to a stack.

    These are the values that represent the indent from the left side, the width, and height.

    1 2 3
    3 4 5
    5 6 7
    8 9 10
    10 9 8
    8 7 6

    After putting these values on to the stack the input file must be closed. So when these files are inputed on to the stack the last line has to should be popped with 3 numbers at a time first until it gets to the last line (1, 2, 3). The output should produce a rectangle.

    this is the error that I receive:
    ------------------------------------------
    Compiling...
    program3.cpp
    C:\program3\program3.cpp(63) : fatal error C1001: INTERNAL COMPILER ERROR
    (compiler file 'msc1.cpp', line 1786)
    Please choose the Technical Support command on the Visual C++
    Help menu, or open the Technical Support help file for more information
    Error executing cl.exe.

    program3.obj - 1 error(s), 0 warning(s)
    ---------------------------------------------

    I'm not quite sure what the error is, it might be the software itself, but if anyone can take a look at my code and tell me how I can input a file onto a STACK and then after closing the inputfile, how I can POP the data values into a function, it would be very helpful.

    ---------------------------------------------------------------------
    CODE
    --------------------------------------------------------------------

    #include <iostream.h>
    #include <fstream.h>
    #include <stdlib.h>


    void top(int &indent, int &height, int &width);
    void bottom (int &indent, int &height, int &width);
    void sides (int &indent, int &height, int &width);
    void ind (int &indent, int &height, int &width);

    const int MAXSTACK = 18;
    const int TRUE = 1;
    const int FALSE = 0;

    //-------------------------------//
    //------------Stack-------------//
    //------------------------------//

    class RectangleStack
    {
    private:
    int top;
    int num[MAXSTACK];

    public:
    RectangleStack();
    void push(int);
    int pop();
    int isempty();
    int isfull();
    };

    //---------------------------------------------//
    //----Define or Implement public functions-----//
    //---------------------------------------------//

    RectangleStack::RectangleStack()
    {
    top = -1;
    }

    void RectangleStack::push(int data)
    {
    top++;
    num[top] = data;
    }

    int RectangleStack::pop()
    {
    int topdata;
    topdata = num[top];
    top--;
    return (topdata);
    }

    int RectangleStack::isempty
    {
    if (top == -1)
    return TRUE;
    else
    return FALSE;
    }

    int RectangleStack::isfull()
    {
    if (top==MAXSTACK-1)
    return TRUE;
    else
    return FALSE;
    }



    void main()
    {

    RectangleStack rectangle;
    int indent, height, width, ch;
    ifstream infile;



    infile.open("rsize.dat", ios::in);


    if (infile.fail())
    {
    cout<<" The file was not sucessfully opened"<<endl;
    exit (1);
    }


    while ((ch = infile.peek()) != EOF)


    {
    infile>>indent>>height>>width;

    if (rectangle.isfull())
    //stack is full
    {
    cout<<"The stack is full"<<endl;
    break;
    }
    else
    rectangle.push(indent, height, width);

    }

    infile.close();


    /*ind (indent, height, width);
    top (indent, height, width);
    sides (indent, height, width);
    bottom (indent, height, width);
    cout<<"\n";
    cout<<"\n";
    cout<<"\n";*/


    }

    cout<<endl;

    }

    void ind(int &indent, int &height, int &width)
    {
    int indentone;
    indentone = indent;

    while (indentone > 0)
    {
    cout<<" ";
    indentone--;
    }

    return;
    }



    void top(int &indent, int &height, int &width)
    {
    int widthone;

    widthone = width; while ( widthone != 0)
    {
    cout<<"*";
    widthone--;
    }

    cout<<endl;

    return;
    }


    void sides (int &indent, int &height, int &width)
    {

    int heightminustwo; heightminustwo = height - 2;

    while (heightminustwo > 0)

    {
    ind (indent, height, width);

    int spaces;
    spaces = width - 2;

    cout<<"*";


    while (spaces > 0)
    {
    cout<<"*";

    spaces --;
    }


    cout<<"*"<<endl;

    heightminustwo--;


    }



    }

    void bottom (int &indent, int &height, int &width)
    {
    ind (indent, height, width);

    int widthtwo;
    widthtwo = width;


    while ( widthtwo != 0)
    {
    cout<<"*";

    widthtwo--;

    }
    return;
    }
  2. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    in your main function you are calling the Rectangle::Push(int x) method with 3 parameters instead of only one. perhaps instead of implementing an integer stack, you could have an integer pointer stack. then each pointer on the stack would point to a record in the file.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Elkhart, Indiana
    Posts
    3
    Rep Power
    0
    thanks for the help infamous41md. But that wasn't the problem at all. If you look at my empty function

    ::"int RectangleStack::isempty "::

    it's missing a (). Appreciate you trying to help anyways.

    NO ONE NEEDS TO POST ANYTHING. I figured out how to do all this on my own from one of my books
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Elkhart, Indiana
    Posts
    3
    Rep Power
    0
    DO NOT POST ANYTHING
    DO NOT POST ANYTHING
    DO NOT POST ANYTHING
    DO NOT POST ANYTHING
    DO NOT POST ANYTHING
    DO NOT POST ANYTHING
    DO NOT POST ANYTHING

IMN logo majestic logo threadwatch logo seochat tools logo