A fatal exception

Discussion in 'C++' started by Developwebsites, Oct 22, 2003.

  1. A fatal exception 0E has occurred at 0028:C027B6DC in VXD VWIN32(04)+00001088.
    The current application will be terminated.

    Same program below run in DOS does not crash.


    #include<iostream>
    #include<iomanip>

    int numb_cities=0;
    const int MAX = 120;

    class Cities {
    private:
    char cityname[MAX][MAX];//an array of 120 cities.
    int temp[MAX];

    public:
    Cities();
    void output();
    };

    Cities:: Cities()
    {
    char y_n;
    do{
    cout<<"\n\n";
    cout<<"Please enter name of city: ";
    cin>>cityname[numb_cities];
    cout<<"\nPlease enter temp: ";
    cin>>temp[numb_cities];
    numb_cities++;
    cout<<"\nAnother city?(Y/N)";
    cin>>y_n;
    }while(y_n =='y' || y_n =='Y');
    cout<<"\n\n";
    }

    void Cities::eek:utput()
    {
    cout<<"\n"<<"name of city"
    <<" temperature"
    <<"\n";
    for(int t=0;t<numb_cities;t++)
    {
    cout<<setw(5)<<cityname[t]<<setw(15)<<temp[t]<<"\n";
    }
    }//close output

    int main()
    {
    Cities info;
    info.output();
    return 0;
    }

    --------------------------------------------------
    *** E-mail is shut off ***
    --------------------------------------------------
    Developwebsites, Oct 22, 2003
    #1
    1. Advertising

  2. Developwebsites

    Ron Natalie Guest

    "Developwebsites" <> wrote in message news:...
    >
    > int numb_cities=0;


    Why is this a global variable if you are going to use it to
    count the number of cityname's input into a single object.
    If you ever have more than one City object, this is not going
    to work.

    > char cityname[MAX][MAX];//an array of 120 cities.


    What do you have against strings?

    But all that being said, I don't know why it crashes....
    Did you try a debugger.
    Ron Natalie, Oct 22, 2003
    #2
    1. Advertising

  3. Developwebsites

    Alan Morgan Guest

    In article <>,
    Developwebsites <> wrote:
    >A fatal exception 0E has occurred at 0028:C027B6DC in VXD VWIN32(04)+00001088.
    >The current application will be terminated.


    What input did you use? Did the program crash immediately or did it crash when
    you entered in the city name or was it when you entered in the temperature or
    was it when you entered in Y or N?

    I can think of a couple of reasons why the program might crash, but you haven't
    given enough information to determine which one it is.

    Have you tried using a debugger? Have you tried putting trace statements in the
    code to figure out what is going wrong? Do you know which line is causing the
    problem?

    Alan
    --
    Defendit numerus
    Alan Morgan, Oct 22, 2003
    #3
  4. >What input did you use? Did the program crash immediately or did it crash
    >when


    the program compiled but crashed right when I tried to run it; did not have a
    chance to enter input.
    --------------------------------------------------
    *** E-mail is shut off ***
    --------------------------------------------------
    Developwebsites, Oct 23, 2003
    #4
  5. Developwebsites

    Jerry Coffin Guest

    In article <>,
    says...
    > A fatal exception 0E has occurred at 0028:C027B6DC in VXD VWIN32(04)+00001088.
    > The current application will be terminated.


    Sounds like you're using Windows 95 or its ilk -- the crash is more
    likely due to the OS than your program.

    > #include<iostream>
    > #include<iomanip>


    Well, it's nice to see that at least you've fixed _something_ since you
    posted the same thing 12 days ago.

    >
    > int numb_cities=0;
    > const int MAX = 120;
    >
    > class Cities {
    > private:
    > char cityname[MAX][MAX];//an array of 120 cities.
    > int temp[MAX];


    In the previous thread I recommended using a vector of strings. I'll
    repeat that recommendation now. I'll also recommend that you upgrade
    your OS -- it sounds like the problems you're seeing at the moment are
    due more to a screwup in your OS than in your own code.

    --
    Later,
    Jerry.

    The universe is a figment of its own imagination.
    Jerry Coffin, Oct 23, 2003
    #5
  6. Developwebsites wrote:

    > A fatal exception 0E has occurred at 0028:C027B6DC in VXD VWIN32(04)+00001088.
    > The current application will be terminated.
    >
    > Same program below run in DOS does not crash.
    >
    >
    > #include<iostream>
    > #include<iomanip>
    >
    > int numb_cities=0;
    > const int MAX = 120;
    >
    > class Cities {
    > private:
    > char cityname[MAX][MAX];//an array of 120 cities.


    As others have said:
    std::vector<string> citynames;

    > int temp[MAX];


    Any temporary variables should be declared and used
    within a method or function.


    > public:
    > Cities();
    > void output();
    > };


    A style suggestion: Place public declarations first
    because these are the items that the users of your
    class will want to know. They won't want to scroll
    through a list of private and protected stuff just
    to get to the public area.

    >
    > Cities:: Cities()
    > {
    > char y_n;
    > do{
    > cout<<"\n\n";
    > cout<<"Please enter name of city: ";
    > cin>>cityname[numb_cities];
    > cout<<"\nPlease enter temp: ";


    What is temp? A number, string, letter?

    > cin>>temp[numb_cities];
    > numb_cities++;
    > cout<<"\nAnother city?(Y/N)";
    > cin>>y_n;
    > }while(y_n =='y' || y_n =='Y');


    See also std::toupper or std::tolower
    while (std::toupper(y_n) == 'Y')


    > cout<<"\n\n";


    I highly suggest you do not perform I/O in the constructor
    of an object. Some objects _may_ be constructed before
    the I/O stream. A better thing to do is to have an
    input method and place that in your main() function.

    > }
    >
    > void Cities::eek:utput()
    > {
    > cout<<"\n"<<"name of city"
    > <<" temperature"
    > <<"\n";
    > for(int t=0;t<numb_cities;t++)
    > {
    > cout<<setw(5)<<cityname[t]<<setw(15)<<temp[t]<<"\n";
    > }
    > }//close output
    >
    > int main()
    > {
    > Cities info;
    > info.output();
    > return 0;
    > }
    >
    > --------------------------------------------------
    > *** E-mail is shut off ***
    > --------------------------------------------------


    Why do we care if your E-mail is shut off?
    You post here. We respond here.

    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.raos.demon.uk/acllc-c /faq.html
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
    Thomas Matthews, Oct 23, 2003
    #6
  7. Developwebsites

    Jerry Coffin Guest

    In article <ZgTlb.14080$>,
    says...

    [ ... ]

    > A style suggestion: Place public declarations first
    > because these are the items that the users of your
    > class will want to know. They won't want to scroll
    > through a list of private and protected stuff just
    > to get to the public area.


    While I realize this idea is widely parroted, I (for one) am willing to
    go on record as saying that it's a _bad_ idea. First of all, the public
    interface should be _documented_, not gleaned from the declaration, so
    the idea is only relevant if everything involved is a complete and utter
    mess from beginning to end.

    Second, anything has to be declared before use, therefore if you have
    screwed up so badly that somebody is scrolling through code to find the
    declaration, they're probably scrolling UP to find it -- so they'll find
    it first if it's at the end of the declaration.

    Third, if your declaration is sufficiently large and complex that any of
    this makes any difference in finding the public parts of the class, then
    moving declarations around is basically applying a small band-aid in a
    situation where major surgery is what's really needed.

    Finally, this style leads to bugs.

    class X {
    public:
    // public stuff

    // private stuff
    };

    and you've forgotten to put the "private:" before the private parts of
    the class, so now everything is public. The compiler can't catch a
    problem, because it doesn't see anything wrong. A user doesn't know
    that you intended some particular part to be private, so he breaks the
    encapsulation you intended to have.

    Now, you can say that this could only happen if you're declaring a class
    that's FAR too large -- and I'd agree. But I'd also point out that only
    in such a case would your "solution" become useful anyway.

    In fact, I'd say the point at which the class should be refactored is
    LOWER than the point at which position of declarations would have a hope
    of doing anything useful. IOW, your idea is useful only as a way of
    preventing really bad code from getting fixed.

    --
    Later,
    Jerry.

    The universe is a figment of its own imagination.
    Jerry Coffin, Oct 23, 2003
    #7
  8. Developwebsites

    Mike Wahler Guest

    "Jerry Coffin" <> wrote in message
    news:...
    > In article <ZgTlb.14080$>,
    > says...
    >
    > [ ... ]
    >
    > > A style suggestion: Place public declarations first
    > > because these are the items that the users of your
    > > class will want to know. They won't want to scroll
    > > through a list of private and protected stuff just
    > > to get to the public area.

    >
    > While I realize this idea is widely parroted, I (for one) am willing to
    > go on record as saying that it's a _bad_ idea. First of all, the public
    > interface should be _documented_, not gleaned from the declaration, so
    > the idea is only relevant if everything involved is a complete and utter
    > mess from beginning to end.
    >
    > Second, anything has to be declared before use, therefore if you have
    > screwed up so badly that somebody is scrolling through code to find the
    > declaration, they're probably scrolling UP to find it -- so they'll find
    > it first if it's at the end of the declaration.
    >
    > Third, if your declaration is sufficiently large and complex that any of
    > this makes any difference in finding the public parts of the class, then
    > moving declarations around is basically applying a small band-aid in a
    > situation where major surgery is what's really needed.
    >
    > Finally, this style leads to bugs.
    >
    > class X {
    > public:
    > // public stuff
    >
    > // private stuff
    > };
    >
    > and you've forgotten to put the "private:" before the private parts of
    > the class, so now everything is public. The compiler can't catch a
    > problem, because it doesn't see anything wrong. A user doesn't know
    > that you intended some particular part to be private, so he breaks the
    > encapsulation you intended to have.
    >
    > Now, you can say that this could only happen if you're declaring a class
    > that's FAR too large -- and I'd agree. But I'd also point out that only
    > in such a case would your "solution" become useful anyway.
    >
    > In fact, I'd say the point at which the class should be refactored is
    > LOWER than the point at which position of declarations would have a hope
    > of doing anything useful. IOW, your idea is useful only as a way of
    > preventing really bad code from getting fixed.


    I'll throw in my two cents here:

    I define my classes like so:

    class C
    {
    /* types (class, enum, typedef, forward decls, etc.) */

    /* data members */

    /* functions */

    public:
    /* types */

    /* data members (I try to avoid public ones, however */

    /* ctors, dtor, assignment op */

    /* other functions */
    };

    My rationale is that when I write:
    class C {

    it *means* "what follows is private, until I specify
    otherwise.

    Of course this is only a style/opinion issue.
    IMO a more important aspect is consistency
    (within the class definitions, as well as among
    them).

    -Mike
    Mike Wahler, Oct 23, 2003
    #8
  9. Developwebsites

    lilburne Guest

    Mike Wahler wrote:

    >
    > Of course this is only a style/opinion issue.
    > IMO a more important aspect is consistency
    > (within the class definitions, as well as among
    > them).
    >


    You can also script the style up so that all someone needs
    to do is enter a command like:

    make_class -header myNewClassName

    which produces a default class header with various bits
    filled in like default ctor and dtor, assignment and copy
    ctor (in private section of course), class validity object,
    etc. Encourages conformity to a standard layout.
    lilburne, Oct 23, 2003
    #9
  10. Developwebsites

    Mike Wahler Guest

    "lilburne" <> wrote in message
    news:bn9j94$uoins$-berlin.de...
    > Mike Wahler wrote:
    >
    > >
    > > Of course this is only a style/opinion issue.
    > > IMO a more important aspect is consistency
    > > (within the class definitions, as well as among
    > > them).
    > >

    >
    > You can also script the style up so that all someone needs
    > to do is enter a command like:
    >
    > make_class -header myNewClassName
    >
    > which produces a default class header with various bits
    > filled in like default ctor and dtor, assignment and copy
    > ctor (in private section of course), class validity object,
    > etc. Encourages conformity to a standard layout.


    Encourages laziness. No thanks. :)

    And I don't want 'dummy' member functions written
    (e.g. ctors) when I don't need to define them at all.
    Nor do I want to have to delete them after the fact.

    I like to actually 'pay attention' to what I'm doing
    when creating a class definition. :)

    $.02
    -Mike
    Mike Wahler, Oct 23, 2003
    #10
  11. Developwebsites

    lilburne Guest

    Mike Wahler wrote:

    > "lilburne" <> wrote in message
    > news:bn9j94$uoins$-berlin.de...
    >
    >>Mike Wahler wrote:
    >>
    >>
    >>>Of course this is only a style/opinion issue.
    >>>IMO a more important aspect is consistency
    >>>(within the class definitions, as well as among
    >>> them).
    >>>

    >>
    >>You can also script the style up so that all someone needs
    >>to do is enter a command like:
    >>
    >> make_class -header myNewClassName
    >>
    >>which produces a default class header with various bits
    >>filled in like default ctor and dtor, assignment and copy
    >>ctor (in private section of course), class validity object,
    >>etc. Encourages conformity to a standard layout.

    >
    >
    > Encourages laziness. No thanks. :)
    >
    > And I don't want 'dummy' member functions written
    > (e.g. ctors) when I don't need to define them at all.
    > Nor do I want to have to delete them after the fact.


    > I like to actually 'pay attention' to what I'm doing
    > when creating a class definition. :)
    >


    Well no one forces anyone to use the scripts, they can type
    the each character themselves if they want.

    But the resulting layout *will* conform to the house rules,
    there *will* be a justification provided for why compiler
    generated default functions have been allowed, or why there
    are copy ctors and assignment operators, and there *will* be
    a justification for why the class validity checker is
    missing, otherwise the code will rejected when submitted for
    integration.
    lilburne, Oct 24, 2003
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Polo Lee
    Replies:
    0
    Views:
    2,722
    Polo Lee
    Jul 7, 2003
  2. senthil
    Replies:
    5
    Views:
    1,377
    senthil
    Jan 24, 2004
  3. Jarek
    Replies:
    1
    Views:
    1,745
    =?ISO-8859-1?Q?Stefan_N=E4we?=
    Sep 7, 2005
  4. vinnuavc
    Replies:
    0
    Views:
    1,812
    vinnuavc
    Jul 25, 2008
  5. Steve
    Replies:
    3
    Views:
    685
    Steve
    Aug 4, 2009
Loading...

Share This Page