Thread: Vector question

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

    Join Date
    Jul 2003
    Rep Power

    Vector question

    I need some help on a project and my book and teacher are useless. I'm creating a program to simulate an ATM. One of the things I need to do is read in from a file a list of valid PIN numbers along with the checking and savings balances for that PIN number. What I want to do is have the user enter their PIN and then compare that to the ones on the list and if it's vaild to go on with the program but if it's invalid to display an error message. And if it's vaild to be able to use the checking and savings balances associated with that PIN. The problem I'm running into is that my teacher is REALLY pushing us to use vectors but the SOB has spent like no time covering it and it's not in the book, however, array are.

    Does anyone have any suggestions on how I can do this using vectors?

    I would really appreciate ANY help anyone could offer.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Woodland Hills, Los Angeles County, California, USA
    Rep Power
    4301 <-- Probably the definitive technical reference, but doesn't have too many examples.

    BTW, it's probably easier to use a map or hash_map instead of a vector class, especially if you're going to search the structure for existing keys frequently. This is because, map or hash_map support the find() method, which allows you to find a key quickly. With a vector class, you'll need to iterate through the list of items yourself, to find what you're looking for.

    Hope this helps :)
    Last edited by Scorpions4ever; July 28th, 2003 at 07:39 PM.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. *bounce*
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Delft, The Netherlands
    Rep Power
    First off, get a better book. Stroustrup's "The C++ Programming Language" is excellent, but if you're new to programming in general, I'd go with something easier. And then there's always Bruce Eckel's book, which you can download free of charge.

    And last but not least, there's Google. Try searching for C++ STL vector tutorial. It turns up a wealth of information :)
    "A poor programmer is he who blames his tools."
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Flint, MI
    Rep Power
    You might also try to go to your instructor's office hours. Most universities have them. Unless you go to one of those unfortunate private schools that works almost totally on adjunct faculty who need to have day jobs (I tought at one), your professor is probably required to keep office hours.

    Vectors aren't hard though. It's an array without all the hassle. For example:

    #include <vector>
    #include <iostream>
    class Account {
      int account_no;
      char pin[4];
      int savings;
      int checking;
    typedef vector<Account> AccountList;
    ostream& operator<<(ostream&, Account&);
    istream& operator>>(istream&, Account&);
    ostream& operator<<(ostream&, AccountList&);
    istream& operator>>(istream&, AccountList&);
    That's about the header that I would require to implement this project. Most of the harriness will happen in the overloaded stream operators.

    You also need a lookup function to search the list of Accounts for a specific account. Most STL containers implement a find() method, but I haven't used this functionality in long enough that I don't remember the specifics.
    Clay Dowling
    Lazarus Notes
    Articles and commentary on web development

IMN logo majestic logo threadwatch logo seochat tools logo