Fumbling Around with C++: Searchable Inventory

Picture this: you’re wiring a new set of fog lights into your mad Lancer Evo and you need 8 inches of yellow 16 gauge wire. But, disaster! You only have 6 inches, so now you have to drop what you’re doing and go buy more or use a different color (thus ruining your color coordination and, by extension, your resale value). Petty, non-issue “problems” like this could be a thing of the past if only you had spent weeks of your life creating a terminal-style program that manages all your parts inventory and maintenance schedules, right? Of course. Let’s build it.

This is a return to form for me, as computer science was my original major in college before I switched out. Pretty much it’s all part of my sick hobby where I do computer stuff just to spite my physics degree. So, what the hell is this all about? I want to create an inventory management system for my garage. The purpose is twofold: First, it will let me know what I have and how much there is before I start a project. Second, it’s a great way to stretch my coding legs and re-learn all of the things that I forgot from years past.

The first step to any well organized project is pseudocode, which is why I usually neglect to do it. One of the great things about having an audience is that you feel compelled to do things correctly, so here we are. As the Latin-speaking audience has already determined (Romani ite domum!), pseudocode is not actually any sort of finished product. It’s fake, and only serves as a guide. This step is important for helping you figure out where your functions will go and how everything will work. The structure and syntax should be similar to your chosen language (mine is C++), but it does not have to be as verbose or exact as the finished product.

This will be a continuing series as my program evolves and I’ll release an open-source version that you can try for yourself when it’s all done. At the end of each update, I’ll include my goals for the next section, the challenges associated with those goals, new code that I wrote, and a change log. The (mostly) completed psuedocode is included for the first edition.

Version 0: Fun with Fake Code

  1. Goals

    1. Re-familiarize myself with C++ syntax and format

    2. Experiment with and re-learn two-dimensional arrays for storing data

    3. Get a working bare-bones framework running reliably

  2. Challenges:

    1. I need to remember how to do a lot with arrays

    2. There is a big possibility that I’ll have to use classes and objects in this project, which is where C++ and other object-oriented languages draw most of their strength, but it’s something I struggled with in school

 \\This program keeps track of parts inventory and maintenece schedules

  function ShowInventory(void)
      Print all lines of Inventory.txt with line number prefixes
      2D Array is the way to go!
      return 0
  end
  }
  function AddItem(void)
      Options: add to exising or add new
      Case AddTo
          Call Search(SearchTerm)
          search file for matching line numbers and print them
          user selects option by giving line number 
          print prompt "item number: "
          print prompt var *UNIT* "to add: "
          Quantity=Quantity+X
          Print confirmation "QUAN UNIT of NAME added"
      Case AddNew
          Print prompt "Name: "
          Print prompt "Quantity: "
          Print prompt "Unit: "
          Print confirmation "QUAN UNIT of NAME added"
          Add Item to proper place or call sort function
      return 0
  end
  }
  function UseItem(void)
      Call Search(SearchTerm)
      List matching items for user to choose
      print prompt var *UNIT* "to use: "
      Quantity=Quantity-X
      Print confirmation "QUAN UNIT of NAME used"
      return 0
  end
  }
  function Search(SearchTerm)
      Scan Inventory.txt for matching items
  return matching line numbers
  end
  }
  function main(void)
    list menu options
    handle exceptions
    return 0
end
}
Previous
Previous

Steal That Look: Norway in the Cold War

Next
Next

Cast Iron II: The one where John McClane drives a motorcycle into a helicopter