Help with arrays

Help with sorting...

Page 1 of 1

2 Replies - 935 Views - Last Post: 25 April 2008 - 03:35 PM Rate Topic: -----

#1 jsizzle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 25-April 08

Help with arrays

Post icon  Posted 25 April 2008 - 12:27 PM

Hello, I am having some trouble figuring out some code for a current homework project. I am supposed to write some pseudocode that produces a report that lists the total sales and total commissions earned by all
salespeople for time frames based on the hour of the day (0005, 0612, 1318,
and 1923) looking somewhat like this:

HOUR O F THE DAY 99
EMPLOYEE TOTAL TOTAL
NAME SALES COMMISSIONS
XXXXXXXX 999999 999999
XXXXXXXX 999999 999999

TOTAL 999999 999999
HOUR O F THE DAY 99
EMPLOYEE TOTAL TOTAL
NAME SALES COMMISSIONS
XXXXXXXX 999999 999999
XXXXXXXX 999999 999999

TOTAL 999999 999999
The file which lists a record of all sales made by employees and the time they were made is unsorted. I could go ahead and use some sort of sorting method to sort them out by time of sales but we haven't technically gotten that far in the course as of yet. So my problem lies in getting them sorted so the employee totals go into the correct hour break for the day. I am absolutely lost on this. My pseudocode is as follows.
start
   perform readData()
	while not eof
	   perform mainLoop()
	endwhile
   perform closeUp()
stop

readData()
   DECLARE VARIABLES
   char mainHeading1 = "HOUR OF THE DAY "
   char mainHeading2 = "EMPLOYEE	 TOTAL	  TOTAL"
   char mainHeading3 = "NAME		 SALES	  COMMISSIONS"
   num empIDNum[0] = 103
   num empIDNum[1] = 104
   num empIDNum[2] = 201
   num empIDNum[3] = 319
   num empIDNum[4] = 367
   num empIDNum[5] = 375
   num empIDNum[6] = 400
   char empName[0] = "Edwards"
   char empName[1] = "Rogers"
   char empName[2] = "Krybek"
   char empName[3] = "Delaney"
   char empName[4] = "LaFleur"
   char empName[5] = "Smith"
   char empName[6] = "Black"
   num empTotalSales [6] all = 0
   num commissionRate[0] = .04
   num commissionRate[1] = .05
   num commissionRate[2] = .06
   num commissionRate[3] = .07
   num commissionRange[0] = 0
   num commissionRange[1] = 51000
   num commissionRange[2] = 126000
   num commissionRange[3] = 201000
   num saleTime[0] = 0000
   num saleTime[1] = 0600
   num saleTime[2] = 1300
   num saleTime[3] = 1900
   num salesPerson
   num month
   num day
   num year
   num time
   num salesAmount
   num x
   num a
   num b
   num rate
   num commission = 0
   num prevTime
   num prevEmp
   open files
   read saleRecord
return

mainLoop()
   if time is not equal prevTime
	perform hourBreak()
   else
	if salesPerson is not equal prevEmp
	   perform empBreak()
	endif
   endif
   read salesRecord
return

hourBreak()
//this should total up all the sales for per employee for that time period but i don't know how to sort it without losing
//information.
   b = 0
   while b < 3
	if time > saleTime[b]
	   print mainHeading1, saleTime[b]
	   print mainHeading2
		   print mainHeading3
	else
	   b = b + 1
	endif
   endwhile
   perform empBreak()
   prevTime = time
return

empBreak()
   //print prevEmp, total???
   if prevEmp = salesPerson
	perform getSales()
	
   prevEmp = SalesPerson
return

getSales()
   x =0
   while salesPerson not equal empIDNum[x]
	x = x + 1
   endwhile
   empTotalSales[x] = empTotalSales[x] + salesAmount
return

determineCommission()
   a = 3
   while a >= 3
	if empTotal[x] >= commissionRange[a]
	   rate = commissionRate[a]
	   a = -1
	else
	   a = a - 1
	endif
   endwhile
   commission = empTotal[x] * rate
   print empName[x], empTotal[x], commission
return

closeUp()
   closefiles
return	


any insight that anyone could give me on this would be very much appreciated. If i am not clear enough on what i need help with, please let me know. Many thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Help with arrays

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: Help with arrays

Posted 25 April 2008 - 12:39 PM

If you want to sort them you will need to store all the records from file in memory
Then why don't you just:

read all records in records[]

from[] = 00, 06, 13, 19
to[] = 05, 12, 28, 23

loop 4 times through your array records[]

for(i = 0; i < 4; i++)

if record[] matches from[i] and to[i]
print it
else
continue
Was This Post Helpful? 0
  • +
  • -

#3 jsizzle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 25-April 08

Re: Help with arrays

Posted 25 April 2008 - 03:35 PM

AWESOME!!!! That's the piece i was overlooking. After reading that, everything has clicked into place. Thank you very much for your insight!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1