Spot the Error (1 Viewer)

Ghost1788

Member
Joined
Jan 30, 2005
Messages
276
Location
Sydney
Gender
Male
HSC
2005
This is a question from the 2004 HSC paper though i a little confused so to clarify can someone do this question and post ur answer

HSC 2004 SDD said:
An amateur theatre company wants to computerise the allocation and sale of seatsat its performances. The theatre company would like to have a system that identifiesand prints out a list of all unsold seats when a customer makes a purchase enquiry.
The theatre used by the company can seat 80 people. The theatre has eight rows,
each with 10 seats, as shown in the diagram below.

The following algorithm has been designed to print a list of all unsold seats.

1 BEGIN print_all_unsold_seats
2 seat = 1
3 row = 1
4 available = false
5 WHILE row <= 8
6 WHILE seat <= 10
7 IF array(row, seat) = “unsold” THEN
8 available = true
9 ENDIF
10 increment seat
11 ENDWHILE
12 increment row
13 ENDWHILE
14 IF available = true THEN
15 print array(row, seat)
16 ENDIF
17 END print_all_unsold_seats

(i) A deskcheck is conducted on the algorithm. It is found that it does not
operate as expected. Identify where two logic errors occur and, for each
error, write the corrected line(s) of code.

(ii) After meeting with members of the theatre company it is decided that
the algorithm needs to be able to print out a list of adjoining seats for
any customer who enquires about purchasing two or more seats in the
same row.
Develop an algorithm, using either pseudocode or a flowchart, which
would meet this specification.
I have my answers but I am confused i can spot more than 2 errors with that algorithm..is it just me...???
 
Joined
Feb 7, 2005
Messages
665
Location
Sydney
Gender
Male
HSC
2005
I can only find one.

Do you realise the fact when Seat 10 of Row 1 is reached, there is nothing to return the value of Seat to 1.

It will just go Row 2, Seat 10,
Row 3, Seat 10
Row 4, Seat 10

etc...



Thats what i figured..

what did u get?
 

MarsBarz

Member
Joined
Aug 1, 2005
Messages
282
Location
Nsw
Gender
Male
HSC
2005
i.
First error:
The algorithm does not reset the value of the seat variable to '1' after the 10th seat has been checked. Hence the value of the seat variable becomes and stays '11'.
Now because the value of the variable seat '11' is greater than '10' the "while seat <= 10" loop will never be executed again. Hence only the first 10 seats of row 1 will be checked for availability and the algorithm fails (logic error).

To fix this error we could simply place the following statement between lines 11 and 12:
seat = 1


Second error:
If a particular seat is labelled "unsold", available becomes true. But the position of this available seat is not recorded.
At the end we have:
IF available = true THEN
print array(row, seat)
ENDIF
Assuming that at least one seat was "available", this control structure will print out the very last values of row and seat which would be 9 and 1 respectively (assuming we have fixed the first error, see above).
Now this is obviously a logic error as array(9,1) does not even exist. Hence the algorithm is flawed.

To fix this we would have to take the following steps:
1. Eliminate the lines 14, 15 and 16.
2. Replace line 8 with [print row "," seat]



The final (fixed) algorithm would be:

Code:
BEGIN print_all_unsold_seats
	seat = 1
	row = 1
	available = false
	WHILE row <= 8
		WHILE seat <= 10
			IF array(row, seat) = “unsold” THEN
				print row "," seat
			ENDIF
			increment seat
		ENDWHILE
		seat = 1
		increment row
	ENDWHILE
END print_all_unsold_seats

A pretty queer question in my opinion.
Edited with the mistake fixed.
 
Last edited:

Ghost1788

Member
Joined
Jan 30, 2005
Messages
276
Location
Sydney
Gender
Male
HSC
2005
yea i got that too but print array(row, seat) prints the value of that seat...ie. whether it is sold or unsold..

and the theatre company needs to 'print out a list of all unsold seats' which to me infers their position..

so wouldn't you have to
print "Seat: " & seat & " Row: " & row & ""

^^in Visual Basic code as i have no idea how to write that in pseudocode
Ghost1788 answer said:
1 BEGIN print_all_unsold_seats
2 seat = 1
3 row = 1
4 available = false
5 WHILE row <= 8
6 WHILE seat <= 10
7 IF array(row, seat) = “unsold” THEN
8 available = true
9 ENDIF
10 IF available = true THEN
11 print "Seat: " & seat & " Row: " & row & ""
12 ENDIF
13 increment seat
14 ENDWHILE
15 increment row
16 seat = 1
17 ENDWHILE
18 END print_all_unsold_seats
 
Last edited:

MarsBarz

Member
Joined
Aug 1, 2005
Messages
282
Location
Nsw
Gender
Male
HSC
2005
1. My fixed algorithm will only print-out the coordinates of the seats which have not been sold (notice the control structure).
2. Yes perhaps you could embellish the print-out of the actuall program in real life but this is pseudocode and I don't think that it is necessary to worry much about the formating of the actual print-out. I think that my answer would be sufficient.
 

Ghost1788

Member
Joined
Jan 30, 2005
Messages
276
Location
Sydney
Gender
Male
HSC
2005
formatting has nothing to do with it...i put the formatting to ensure that the actual position of the seat is printed out not whether it is sold or unsold

print array(row, seat)

would print whether the seat was sold or unsold..in this case unsold
 

MarsBarz

Member
Joined
Aug 1, 2005
Messages
282
Location
Nsw
Gender
Male
HSC
2005
Oh, you are correct and I have realised my mistake. Sorry about that.

I'll edit my original solution then. Lol! What a lame mistake ey!
 
Last edited:

mattchan

Member
Joined
Jul 23, 2004
Messages
166
Gender
Male
HSC
2005
Line 8. It doesnt really record which seat is made available. It only indicates that the boolean available is now true

And the Seat counter doesnt return to 1 when the next row needs to be checked. (Like what DigitalFortress said)
 
Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
the 2004 paper had relatively easy pseudocode compared to previous years
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top