[Year 12 Its] Algorithm alternative for VITTA sample exam 2

Kevork Krozian Kroset at novell1.fhc.vic.edu.au
Tue Oct 11 12:47:34 EST 2005


Hi Folks,

  Here is an alternative algorithm for this exam after the difficulties with the one given. 
Happy to hear corrections or any other comments. Please feel free to take it or leave it.
There are 2 errors.

Question 5

Study the algorithm below and answer the following questions:


          Procedure MatchID (String Visitor_id) // checking that visitor.id is in database 

                 Boolean YeahMatch
                 Transponder_record  transmit

        Begin

            // visitor hands over the printed ID he was given at previous visit
             If Visitor_id <> "" then   	

            //  Search from end of file because recent visitors are appended
             Open(visitor_file) for read
             YeahMatch = False
             Read(transmit, visitor_file)

               While (NOT EOF(visitor_file)  and Not YeahMatch)							
		  If Visitor_id = transmit.visitorid
			YeahMatch = true
		  End if
               End while
              Close(visitor_file)

              If YeahMatch then
               MessageBox ("check Photo ID to match this: ", transmit.visitorid, Answer yes,no)
               Endif
          If Answer = "no" then

           //visitor had no photo ID for his details

           MessageBox ("No Match, so obtain all details", Answer OK) 

          // Read in all details --  Create new ID 
           Transmit.visitorid <- CreateID(New_ID)

           // TransponderID = TR001, is considered front office
             Transmit.transponderID <- TR001
              Open(visitor_file) for write
              Write(visitor_file, transmit)
              Print(Visitor_id)
             // Give printed new visitor ID to visitor to proceed with visit
	
          Else
	Display Message (" Visitor verified, proceed with visit")
         End if

      End


Two errors:

1.	While searching in the While Loop , the next record is not read to progress further to the next record. 
The While loop will be an infinite loop because a new record is not read to advance towards end of File (EOF). 

So , the correction is :

   While (NOT EOF(visitor_file)  and Not YeahMatch)							
                    Read(transmit, visitor_file)
 		If Visitor.id = transmit.visitorid
			YeahMatch = true
		  End if
	 

2.	When a new visitor is entered into the file, the file is not closed

// Front Office Transmission is from Transponder TR001
Transmit.transponderID <- TR001
Open(visitor_file) for write
Write(visitor_file, transmit)
Close(visitor_file)


 Best Wishes


Kevork Krozian
IT Manager , Forest Hill College
k.krozian at fhc.vic.edu.au
http://www.fhc.vic.edu.au
Mobile: 0419 356 034




More information about the is mailing list