need some pointers on program

This is a discussion on need some pointers on program within the C++ Programming forums, part of the General Programming Boards category; hey all, i wrote this program for an assignment in class. It does everything it is supposed to , i ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    134

    need some pointers on program

    hey all,

    i wrote this program for an assignment in class. It does everything it is supposed to , i just needed some tips on how i can improve the code and make it better....thanks in advance

    oh yeah

    it is an address book, and uses stl map and list to manage the data.
    Attached Files Attached Files

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,669
    Additions in red:
    >> eAddressBook& operator = (const eAddressBook&);
    >> eAddressBook(const eAddressBook& );
    >> inline bool operator == (const name &k, const name &a);
    >> inline bool operator < (const name &k, const name &a);

    -- main() should return a value, your's doesn't

    >> cout<<"MENU OF CHOICES\na)Add entry\nb)Delete Address\nc)....
    Are you trying to make it as un-readable as possible?
    Code:
        cout << "MENU OF CHOICES"    << endl
             << "  a)Add entry"      << endl
             << "  b)Delete Address" << endl
             << "  c)Delete Name"    << endl
             << "  d)Find Address"   << endl
             << "  e)Print Names Starting with Letter"     << endl
             << "  f)Print All Names and E-mail Addresses" << endl
             << "  g)Quit" << endl;
    Don't try to compress your code into fewer number of lines, there's no point and it just make it harder for others to understand when they read it.

    gg

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    134
    about the return 0 thing, i saw somewhere prelude said that you dont need it.

    this is what he said, i got it from the post

    >return 0;
    Not required. Standard C++ allows you to omit the return statement from main and a value of 0 will be implicitly returned.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,669
    Well, my compiler spits out a warning and I can't have that (even if it is wrong).

    gg

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    134
    must be depending on the compiler, because i used g++ and msvc 7.0 with no issues. But ill add and other suggestions you made to be on the safe side.

  6. #6
    Registered User
    Join Date
    Sep 2003
    Posts
    135
    The standard doesn't require a return statement from main() and will treat it as return 0 if you don't provide one. Older compilers may not accept this.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    > The standard doesn't require a return statement from main()
    The only reason I can figure out for this is a sop to the void main'ers, so all they have to do is change void to int to make their code a little bit more compliant (like that is going to be their only mistake).

    The standards commitees go out of their way removing all the old implicit behaviours of C and C++, just to introduce a new one - namely, it is implicit that main returns 0 if you don't say so otherwise.

    No other function has this behaviour. Stick to saying what you mean rather than trying to save a few keystrokes here and there.
    Braces and parentheses are optional in many circumstances as well, but leave enough of them out for long enough, and you'll get bitten.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Sep 2003
    Posts
    135
    Originally posted by Salem
    > The standard doesn't require a return statement from main()
    The only reason I can figure out for this is a sop to the void main'ers, so all they have to do is change void to int to make their code a little bit more compliant (like that is going to be their only mistake).

    The standards commitees go out of their way removing all the old implicit behaviours of C and C++, just to introduce a new one - namely, it is implicit that main returns 0 if you don't say so otherwise.

    No other function has this behaviour. Stick to saying what you mean rather than trying to save a few keystrokes here and there.
    Braces and parentheses are optional in many circumstances as well, but leave enough of them out for long enough, and you'll get bitten.
    Not identical behaviour to main, no. But there is still an implicit return (with no value) for all other functions where no return statement is provided. So for all functions there is an implicit return statement if none is provided.

    Of course, for value returning functions that would be undefined behaviour.

    Just out of curiousity, do you place a return; statement at the end of void functions in your own code, or do you rely on the impicit return statement? For most people I suspect the latter.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 08:48 AM
  2. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 04:23 PM
  3. Replies: 2
    Last Post: 03-13-2003, 08:40 AM
  4. Help In Visualising Pointers ( C Program )
    By Evilelmo in forum C Programming
    Replies: 5
    Last Post: 01-25-2003, 12:48 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21