Jump to content

how to generate a code like this

- - - - -

  • Please log in to reply
3 replies to this topic

#1
atoivan

atoivan

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
i am writing a database program and i want to generate item codes so that all the item will be identified by this code.

the items are in categories examples (soft-drinks,wines beers ....etc )

i want to crate a function the will generate this codes for me. example a category (Array) is wines all the item codes in Wine in the Array Wine should begin with the word 'W' if it is Beers all the items codes in the Array Beer must begin with' B'.

thank u

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
I'm not sure what your question is. What part are you stuck on? What do you have so far?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
I presume you are going to be using char Arrays then you are looking at generating random strings per category. Then a possible way to achieve that is either: 1. Keep track of the strings you generate per category(possibly another array). 2. Generate the strings per category in such a way a repeat never occurs. For example the Beer category could have strings like B1, B2, B3 etc, increasing incrementally by some amount. 3. Manually create each string code somewhere in a file then read them in(you will have to make sure you don't repeat the codes. Don't do this if the arrays are 'large'). I'm sure there are other ways, but it depends on your specifications.
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#4
notes

notes

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
I think you might want to read : Hash table - Wikipedia, the free encyclopedia Separate Chining is what I have on my mind.
Remebre about KISS & DRY




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users