Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

10,000 EMPLOYEES

Status
Not open for further replies.

chriscarlile911

Technical User
Jun 12, 2003
3
GB
HI,
i'm trying to figure out the best way to create 9999 random employees each with an employee number (0001-9999) attached to them. i think that for the purpose of what i need, it would be easier to create them with all the same name followed by their number. ie. JOHN SMITH0001,JOHN SMITH0002 etc...
any ideas for a new pascal user.
cheers
 
Use the function random:
random(x) generates a random number in the interval [0,1,...x[ (i.e. x not included).

Use the function str to convert a number to a string:
str(125,s); => s = '125'

Use + to concatenate strings:
s:='john'+'125'; => s = 'john125'

Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
THANX Bertv100,
when i said i was a new pascal user, i meant really new. so i dont really understand any of what you just said except for your signature (cool by the way) i'll look in some books to try and figure out what you're telling me.
regards
chriscarlile911
p.s. if, "once you pop, you can't stop", why do pringle come in a resealable tub!?!?!?
 
Some example code:
Code:
FUNCTION generate_name(name : string; number : word) : string;
VAR number_string : string;
begin
  { convert the given number to a string: }
  str(number,number_string);
  { push zeroes in front of it, so all "numbers" have the same length }
  while length(number_string)<4 do
   number_string:='0'+number_string;
  { return as result the concatenation of the given name and the number }
  generate_name:=name+number_string;
end;

Executing
Code:
generate_name('JOHN SMITH',1);
will result in the value
Code:
'JOHN SMITH0001'
.
The following example will print this result on screen:
Code:
VAR s : string;
BEGIN
  s:=generate_name('JOHN SMITH',1);
  writeln(s);
END.

If you don't understand all this code, you should really read some book on Pascal. People in this forum can only help if you already know Pascal's syntax and are at least remotely familiar with its iteration and selection techniques.

Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
Bertv100, can't you get str to produce the right format automatically by specifying it with ':' things, like you can in writeln?? I can't remember....
 
Yes you can, but I took Chris' requirement which was: zeroes in front of number. The ':' formatting uses spaces.

Also, since he's a beginning programmer, an example of a while loop can be more helpful in learning to work in Pascal than a cryptic ':' construct.

Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
true, true!
The ':' thing isn't very well documented in help-files, either.
 
I have taught and designed random files with random record processing, if that is really what you want, for about 40 years and designing & programming a good random file processing system with a good packing factor, synonyms spreading, overflows, dynamic key reuse and appox., 1.2 reads per request, chains, skip techniques & prime divide is not something for the faint of heart. I have taught a one week design & coding overview class to experienced people and sometimes they have trouble understanding the issues.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top