My numeric analyzer

This is a discussion on My numeric analyzer within the C++ Programming forums, part of the General Programming Boards category; Make new return NULL on error instead of throwing an exception? Oh, yes. Why not? I defined MAX_PATH 260 at ...

  1. #16
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    Make new return NULL on error instead of throwing an exception?
    Oh, yes. Why not?

    I defined MAX_PATH 260 at the beginning of the code as it is in <windef.h>.
    Thanks for searchings dwks. I am reading them.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  2. #17
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    I defined MAX_PATH 260 at the beginning of the code as it is in <windef.h>.
    That's probably a bad idea, in case the value ever changes (not that it will!). I'd go (if you still want to use it):
    Code:
    #ifndef MAX_PATH
        #define MAX_PATH 260
    #endif
    After you include windef.h, of course.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #18
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    So we should always use C++ casting.

    [EDIT]
    Code:
    #ifndef MAX_PATH
        #define MAX_PATH 260
    #endif
    Including windef.h means losing portability. So what can be done?
    Last edited by siavoshkc; 07-14-2007 at 06:34 PM.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  4. #19
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Couple of notes:
    Code:
    //It doesn't use vector maybe for simplfication (?)
    I can't see how managing the memory allocations yourself could be easier than letting the library do it. With a vector, for example, you wouldn't need to count the items in the file before loading them.

    Code:
       ifstream *fileOfNumbers;
    Why do you feel it is necessary to make this a member of the class? It is only used in one function.

    Code:
    int Numbers::Ave()
    {
    	return(Sum()/numCount);
    }
    This might still crash if the file was empty.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #20
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    So we should always use C++ casting.
    In C++, yes. In C, of course, there's only one option.

    This might crash as well.
    Code:
    int Numbers::Mid()
    {
    	sort(nums, nums + numCount);
    	return (nums[numCount/2]);
    }
    Any code that assumes at least one number exists might crash.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #21
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    Any code that assumes at least one number exists might crash.
    I will correct this problem using isOK.

    Why do you feel it is necessary to make this a member of the class? It is only used in one function.
    For limiting its access.

    I can't see how managing the memory allocations yourself could be easier than letting the library do it.
    I do this to practice memory allocation.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  7. #22
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Including windef.h means losing portability. So what can be done?
    Aren't things such as "stdafx.h" and _tmain Microsoft compiler specific anyway?


    Quote:
    Any code that assumes at least one number exists might crash.
    I will correct this problem using isOK.
    If the constructor fails, you'll have a completely unusable object - without a means to try loading another file. So you might just as well let the exception leave the constructor: user gets a valid object or nothing.
    But I'm not that fond of using exceptions...

    Quote:
    Why do you feel it is necessary to make this a member of the class? It is only used in one function.
    For limiting its access.
    How? If it is used locally in one function, its access would be even more limited? Your class is a wrapper around a numeric array, the ifstream is just a tool to get that array loaded from file.

    Quote:
    I can't see how managing the memory allocations yourself could be easier than letting the library do it.
    I do this to practice memory allocation.
    That's a valid reason. But may-be update the comment then
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  8. #23
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,236
    So you might just as well let the exception leave the constructor: user gets a valid object or nothing.
    I don't know why I thought I can't throw exceptions from constructor (or it is a bad idea)!!! So it is possible, isn't it?

    How? If it is used locally in one function, its access would be even more limited? Your class is a wrapper around a numeric array, the ifstream is just a tool to get that array loaded from file.
    Aha, now I understant you. I thought you say it should be global. You are right if the class design remains the same.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My numeric analyzer (2)
    By siavoshkc in forum C++ Programming
    Replies: 11
    Last Post: 07-27-2007, 04:32 PM
  2. Send a numeric
    By nick048 in forum Networking/Device Communication
    Replies: 2
    Last Post: 04-09-2007, 06:42 PM
  3. Simple vector class problem, please help
    By fidodidohk in forum C++ Programming
    Replies: 9
    Last Post: 03-30-2007, 10:13 AM
  4. only accept numeric data
    By willc0de4food in forum Windows Programming
    Replies: 6
    Last Post: 08-19-2005, 04:38 AM
  5. OpenScript2.0 Spectrum Analyzer
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 03-23-2004, 10:01 PM

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