Your assignment is to track the corporate careers of some up-and-coming executiv
ID: 3560778 • Letter: Y
Question
Your assignment is to track the corporate careers of some up-and-coming executives who are
busily changing jobs, and, of course, getting paid.
In this version of the corporate world, people wither belong to a company or are unemployed.
The list of people the program must deal with is not fixed: initially there are none, and new
people may be introduced by the JOIN command. (see below).
An employee's salary is $10000. Unemployment people draw $700 in unemployment
compensation.
Input
1. From file "company.txt": The company names are listed one per line. There are
at most 20 companies. Company names are at most 10 characters and do not
contain embedded blanks.
2. From the keyboard: Commands, as listed below. <Person> and <Company> names
are at most 10 characters and do not contain embedded blanks.
JOIN <person> <company>
<person> joins the specified <company>. This may be the first reference
to this person, or he or she may be unemployed. The person does not
currently belong to another company. Remember that when a person joins
a company.
CHANGE <person> <company>
<person> quits his or her job and joins the specified new <company>. You
may assume that the person is currently employed. This command does not
tell you the person's current employer; you have to search the data
structure to find the person.
QUIT <person>
<person> quits his or her job and becomes unemployed. You may assume
that the person is currently employed.
PAYDAY
Each person is paid his or her salary ($5000). (You must keep track of
the amount each person has earned from the start of the program).
EMPLOYEES <company>
The current list of employees should be printed for the specified
<company>. The employees must be printed in order of their name.
UNEMPLOYED
The list of unemployed people should be printed.
DUMP
Print the employees in each company, as specified under the EMPLOYEES
Assignment: Job Tracking System
command above, then print the unemployed people. Label the output
appropriately.
END
Stop accepting commands.
Ouput
After all the commands have been processed, write a list of employees to a file "employee.txt".
The list consists of all the people who have been mentioned in any command and the total
amount of money they have been accumulated.
The following are some sample data"
file Company.txt
Borland
Microsoft
IBM
Intel
Compaq
NEC
Oracle
Commands from keyboard:
JOIN David IBM
JOIN Peter Intel
PAYDAY
CHANGE Peter Microsoft
Explanation / Answer
Of course, there are many ways to tackle this problem. For example, you could first store everything in an multi-dimensional array, and then after inputting all of the data, determine the output. Or you could just read the data and immediately determine the output for that two-letter label on the fly, without ever storing the data. I chose this method for my program, written in PowerBASIC:
GLOBAL x, index, counter AS LONG
GLOBAL amount, total, minimum, maximum AS SINGLE
GLOBAL employee_data, a, b, c AS STRING
OPEN "c:data.txt" FOR INPUT AS #1 : OPEN "c:out.txt" FOR OUTPUT AS #2
DO UNTIL EOF(1)
minimum = 999999: maximum = 0: total = 0
LINE INPUT #1, employee_data$
index = 4 : counter = 4
FOR x = 1 TO 10
DO
INCR counter
LOOP UNTIL MID$(employee_data$, counter, 1) = " " OR counter >= LEN(employee_data$)
amount = VAL(MID$(employee_data$, index, counter - 1))
index = counter + 1
IF amount < minimum THEN minimum = amount
IF amount > maximum THEN maximum = amount
total = total + amount
NEXT
a$ = FORMAT$(minimum, "########.00")
b$ = FORMAT$(maximum, "########.00")
c$ = FORMAT$(total/10, "########.00")
PRINT #2, MID$(employee_data$, 1, 2); " line minimum = "; a$; ", maximum = "; b$; ", average = "; c$
LOOP
CLOSE #1 : CLOSE #2
Output:
TG line mimimum = 250000.00, maximum = 269000.00, average = 256192.68
VV line mimimum = 3667.69, maximum = 3667.69, average = 3667.6
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.