Programming

scottyy

Active member
Regular
Joined
Dec 16, 2011
Messages
767
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
If i am counting the all the members in various departments how would i write this in pascal form and also what kind of loop should i use?
 

Alkad

Active member
Regular
Joined
Jun 17, 2010
Messages
1,940
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
Awards
What format do "departments" and "member lists" come in? It all depends on what you already have, but you're probably going to have two nested "while" loops - one for listing departments, another for listing members.
 

scottyy

Active member
Regular
Joined
Dec 16, 2011
Messages
767
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
What format do "departments" and "member lists" come in? It all depends on what you already have, but you're probably going to have two nested "while" loops - one for listing departments, another for listing members.
human resource department

information technology deparment

sales & distribution department

sorry not member employee
 

Alkad

Active member
Regular
Joined
Jun 17, 2010
Messages
1,940
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
Awards
human resource department

information technology deparment

sales & distribution department

sorry not member employee
That's not exactly what I asked.

Are the names stored directly in files? Will you add new departments once the code is complete? Do you have any other data, such as the number of employees? Is the data already present?

I advise you to use "while" loops. But if you don't have a design, there's not much valuable info that I can give you.
 

Mugiwara

Active member
Legendary
Joined
Apr 25, 2008
Messages
11,625
Kin
24💸
Kumi
0💴
Trait Points
0⚔️
Awards
for loops could work.
I used for loops to create fibonacci sequence where the user inputs how many numbers they want, and then the program outputs it.

while loops should work as well.
 

Alkad

Active member
Regular
Joined
Jun 17, 2010
Messages
1,940
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
Awards
The problem with FOR loops is that they make employees harder to add. He'd need to keep a counter and update it. If he wants to "count all the members", he wouldn't have a counter.

WHILE loops are more robust. If he's using the format I was thinking of, he could keep reading lines until the document was finished. If he wanted to add new employees, he'd only need to append lines.

Removing employees is a bit trickier, but should work with a combination of REWRITE (on a temporary), RESET (on the current file) and finally replace the old file (remove) with the new one (rename). This is one of the better approaches for serious programs, if he's doing it for an actual business. Since the modification is atomic, if the program crashes before the rename, it would know the next time it runs, maintaining file consistency. He could go a little further, but it all depends on the requirements.

Ending all files with an "----END-FILE----" marker will enable you to check whether the file was written properly. Then a few changes are in order.


I've never used anything other than text files to store data with Pascal. Maybe there are libraries for databases which are more efficient.

If you are having many employees, consider indexing them.
like "department-management--employees-A.txt"

.txt is optional of course.

only if your version of Pascal supports longer filenames. the one I used was 16-bit and had some pretty shitty restrictions.
 
Last edited:
Top