Thread: Just another noob question

  1. #1
    Registered User verbity's Avatar
    Join Date
    Nov 2006
    Posts
    101

    Lightbulb Just another noob question

    Can someone please explain, if you would be so kind, what automatic range checking is?? In reference to a integer array. I have an assignment that says: "user will be able to declare integer arrays of any size with automatic range checking of indices. The upper and lower indices can be any integer, positive or negative, rather than the fixed limits of 0 to size -1."

    ps: I JUST WAS LOOKING FOR AN QUICK EXPLAINATION...NOT SOMEONE TO DO MY CODE JUST IN CAUSE SOMEBODY GOT IT TWISTED.
    Last edited by verbity; 03-23-2007 at 06:23 PM.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Automatic range checking means that accessing element 494 in a N<495 array bears no consequence because your logic is managed for you. vector<> has a runtime exception called out_of_range, which is thrown.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> vector<> has a runtime exception called out_of_range, which is thrown.
    ... when you use at() (not when you use operator[]).

  4. #4
    Registered User verbity's Avatar
    Join Date
    Nov 2006
    Posts
    101
    alrighty...thank you. I didn't understand anything you guys said LOL.

    So if you possibly could elaborate on that for a guy who is really not smart. Here's my constructor for array with two parameters one for lower bounds and one for upper.

    Code:
    IntArray::IntArray(int x, int y)
    {
    	const int size = y - x + 1;
    	array = new char[size];
    	low = x;
    	high = y;
    }

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The range checking part is for when the user of your array tries to access an element and gives you an index. If your array indices go from 0 - 99 and the code tries to access the element at index 150, then you need to check for that and give an error.

  6. #6
    Registered User verbity's Avatar
    Join Date
    Nov 2006
    Posts
    101
    Ok cool. What was all that other stuff you guys where talking about? I'm wondering if I'm in the wrong school cause I"ve never once heard about a vector...

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    >> What was all that other stuff you guys where talking about?
    A vector is a templated object in C++'s standard template library that makes managing arrays a little more straight forward and thus less error prone. It wasn't meant to be a jab at your school but I thought you were asking a question about vectors. I'm sorry about confusing you. If you don't know what the standard template library is, well, I can only suggest that you pick up a book on it sometime (there are book recommendations in another topic on this forum) and not to worry about what I said until you know what vectors are supposed to do.

  8. #8
    Registered User verbity's Avatar
    Join Date
    Nov 2006
    Posts
    101
    It's cool. I'm didn't take it as a jab at my school...I was just thinking I need to be in a different school...if I didn't know what you guys were talking about. I'm going to UCSD next semester I'm sure I'll learn it there...and I'll pick up a book. I've got Stroustrup's book right here but we really don't use it...and he's about the most confusing writer I've ever read so I don't really bother by myself.

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> I've got Stroustrup's book right here but we really don't use it.
    If you're just learning C++, it isn't exactly the best book to read through.

    >> I'm wondering if I'm in the wrong school cause I"ve never once heard about a vector.
    Many, many schools, books, tutorials and instructors don't teach vector. Part of the reason for this is that a large part of the C++ community developed certain coding habits before vector became part of the language. Because C++ still supports the old way of doing things, there is less incentive for people to use the new features (that have been around for almost 10 years).

    So don't change schools just because your current one doesn't teach vector, you might not find one that does. Just continue learning programming concepts and remember that C++ actually has better options for many of the tasks you are learning right now. If you are really motivated you can try learning on your own with a book like Accelerated C++ or You Can Do It! which use a much more modern C++ style than many other books out there.

  10. #10
    Registered User verbity's Avatar
    Join Date
    Nov 2006
    Posts
    101

    Red face

    Oh it was in the master plan for me anyway....My buddy's been doing this for years and even he gets upset at what my school's teaching me sometimes so..who know's. As for UCSD I'm just taking a few classes there for solitification of what I hopefully already know. So at least when I hit the work force I at least know all the syntax....I'm also going to Harvard via their extension school through online so we'll see if the school makes any differences LOL.....thanks for the help though......

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick noob question
    By thanatos1 in forum C# Programming
    Replies: 2
    Last Post: 06-17-2009, 08:28 PM
  2. another noob question
    By clb2003 in forum C Programming
    Replies: 4
    Last Post: 02-12-2009, 01:28 PM
  3. Noob printf question
    By lolguy in forum C Programming
    Replies: 3
    Last Post: 12-14-2008, 08:08 PM
  4. Very noob question :(.
    By GamerProduction in forum Tech Board
    Replies: 4
    Last Post: 04-14-2007, 05:40 AM
  5. Noob question ( little dos program )
    By Demon1s in forum C++ Programming
    Replies: 13
    Last Post: 04-04-2003, 09:28 PM