Tuesday, April 25, 2023

Computer Systems (FAST TRACK)

1     Data representation

 

1.1   Number systems

 How and why computers use binary to represent all forms of data?

    Any form of data needs to be converted to binary to be processed by a computer

    Data is processed using logic gates and stored in registers

 What are the denary, binary and hexadecimal number systems?

        Denary is a base 10 system

        Binary is a base 2 system

        Hexadecimal is a base 16 system

 How and why hexadecimal is used as a beneficial method of data representation?

    Areas within computer science that hexadecimal is used should be identified
    Hexadecimal is easier for humans to understand than binary, as it is a shorter representation of
     the binary 

What is overflow and why it occurs in binary addition?

    An overflow error will occur if the value is greater than 255 in an 8-bit register

    A computer or a device has a predefined limit that it can represent or store, for example 16-bit

    An overflow error occurs when a value outside this limit should be returned

What is a logical binary shift on a positive 8-bit binary integer and what effect this has on the positive binary integer?

        Perform logical left shifts

        Perform logical right shifts

        Perform multiple shifts

       Bits shifted from the end of the register are lost and zeros are shifted in at the opposite end of the register

        The positive binary integer is multiplied or divided according to the shift performed

        The most significant bit(s) or least significant bit(s) are lost

How to use two’s complement to represent positive and negative 8-bit binary integers

        Convert a positive binary or denary integer to a two’s complement 8-bit integer and vice versa

        Convert a negative binary or denary integer to a two’s complement 8-bit integer and vice versa


Wednesday, March 13, 2019

Pre Release May/June 2019 with comments




In preparation for the examination candidates should attempt the following practical tasks by writing and testing a program or programs.

An auction company has an interactive auction board at their sale rooms, which allows buyers to place bids at any time during the auction. Before the auction starts, the sellers place their items in the sale room with a unique number attached to each item (item number). The following details about each item need to be set up on the interactive auction board system: item number, number of bids, description and reserve price. The number of bids is initially set to zero.

During the auction, buyers can look at the items in the sale room and then place a bid on the interactive auction board at the sale room. Each buyer is given a unique number for identification (buyer number). All the buyer needs to do is enter their buyer number, the item number and their bid. Their bid must be greater than any existing bids.

At the end of the auction, the company checks all the items and marks those that have bids greater than the reserve as sold. Any items sold will incur a fee of 10% of the final bid to be paid to the auction company.

Write and test a program or programs for the auction company.

      Your program or programs must include appropriate prompts for the entry of data, data must be validated on entry.
     Error messages and other output need to be set out clearly and understandably.
     All variables, constants and other identifiers must have meaningful names.

You will need to complete these three tasks. Each task must be fully tested.

Task 1 Auction set up.

For every item in the auction the item number, description and the reserve price should be recorded. The number of bids is set to zero. There must be at least 10 items in the auction.

Task 2 – Buyer bids.

A buyer should be able to find an item and view the item number, description and the current highest bid. A buyer can then enter their buyer number and bid, which must be higher than any previously recorded bids. Every time a new bid is recorded the number of bids for that item is increased by one. Buyers can bid for an item many times and they can bid for many items.

Task 3 At the end of the auction.

Using the results from TASK 2, identify items that have reached their reserve price, mark them as sold, calculate 10% of the final bid as the auction company fee and add this to the total fee for all sold items. Display this total fee. Display the item number and final bid for all the items with bids that have not reached their reserve price. Display the item number of any items that have received no bids. Display the number of items sold, the number of items that did not meet the reserve price and the number of items with no bids.














Wednesday, March 6, 2019

O Level 2210 Pre Release + Solution May/June 2019

In preparation for the examination candidates should attempt the following practical tasks by writing and testing a program or programs.

An auction company has an interactive auction board at their sale rooms, which allows buyers to place bids at any time during the auction. Before the auction starts, the sellers place their items in the sale room with a unique number attached to each item (item number). The following details about each item need to be set up on the interactive auction board system: item number, number of bids, description and reserve price. The number of bids is initially set to zero.

During the auction, buyers can look at the items in the sale room and then place a bid on the interactive auction board at the sale room. Each buyer is given a unique number for identification (buyer number). All the buyer needs to do is enter their buyer number, the item number and their bid. Their bid must be greater than any existing bids.

At the end of the auction, the company checks all the items and marks those that have bids greater than the reserve as sold. Any items sold will incur a fee of 10% of the final bid to be paid to the auction company.

Write and test a program or programs for the auction company.

Your program or programs must include appropriate prompts for the entry of data, data must
        be validated on entry.
•      Error messages and other output need to be set out clearly and understandably.
•      All variables, constants and other identifiers must have meaningful names.

You will need to complete these three tasks. Each task must be fully tested.

Task 1 – Auction set up.
For every item in the auction the item number, description and the reserve price should be recorded. The number of bids is set to zero. There must be at least 10 items in the auction.

Task 2 – Buyer bids.
A buyer should be able to find an item and view the item number, description and the current highest bid. A buyer can then enter their buyer number and bid, which must be higher than any previously recorded bids. Every time a new bid is recorded the number of bids for that item is increased by one. Buyers can bid for an item many times and they can bid for many items.

Task 3 – At the end of the auction.
Using the results from TASK 2

1. How you Identified items that have reached their reserve price, mark them as sold
  if highestBid(count) > resPrice(count) then
    sold$(count) = "sold"
  end if

2. How you calculated and displayed 10% of the final bid as the auction company fee and 
        added this to the total fee for all sold items. 

    if highestBid(count) > resPrice(count) then
     sold$(count) = "sold"
      itemFee(count) = highestBid(count) * 10/100
     totalFee = totalFee + itemFee(count)
    end if

Display total fee of company. 

if highestBid(count) > resPrice(count) then
      itemFee(count) = highestBid(count) * 10/100
     totalFee = totalFee + itemFee(count)
 end if
        Print " Total Company Fee = ";totalFee

3. How did you find and displayed the item number & final bid for all the items with 
        bids that have not reached their reserve price. 

for count=1 to numOfItems
   if highestBid(count) < resPrice(count) then
    print itemNo(count), highestBid(count),numOfBids(count)
    belowResPrice = belowResPrice + 1
   end if
  next

4. How did you find and displayed the item number of any items that have received no bids. 

for count=1 to numOfItems
   if numOfBids(count)=0 then
    print itemNo(count), numOfBids(count)
   end if
 next

5. How did you Calculated/Display the number of items sold, the number of items that 
        did not meet the reserve price and the number of items with no bids.

for count = 1 to numOfItems
   if highestBid(count) > resPrice(count) then   
      tsold = tsold + 1
   if numOfBids(count) = 0                      then
      noBids = noBids + 1
   if highestBid(count) < resPrice(count) then
      belowResPrice = belowResPrice + 1
   print  "Total number of items sold                         = ";tsold
   print "Num of items that below the reserve price  = ";belowResPrice
   print "Num of items with no bids                           = ";noBids
next

'******************************** THIS IS TASK 1 ***************************'
 do
  input "Enter number of items in auction "; numOfItems
  if numOfItems < 3 then
    print "Auction cannot start with items less then 3 items. Please re-enter"
  end if
 loop until numOfItems >= 3

 dim itemNo(numOfItems)
 dim desc$(numOfItems)
 dim resPrice(numOfItems)
 dim numOfBids(numOfItems)
 dim highestBid(numOfItems)
 dim currentBuyer(numOfItems)

 check = 1
 count = 1

 while count <= numOfItems
  input "Enter item number      ";itemNo(count)

   while check < count
    if itemNo(count) = itemNo(check) then
      print "*** Duplicate ***"
      input "Enter item number      ";itemNo(count)
      check = 1
    else
      check = check + 1
    end if
   wend
   check=1

   input "Enter description     "; desc$(count)

  do
   input "Enter reserve price   "; resPrice(count)
    if resPrice(count) <= 0 then
      print "Invalid reserve price entered."
    end if
  loop until resPrice(count) > 0

   numOfBids(count) = 0
   highestBid(count)= 0
   count = count + 1
 wend

   print "---------------------------------------------------------"
   print " ItemNo      Description    Reserve-Price   Total-Bids   "
   print "---------------------------------------------------------"

  for count=1 to numOfItems
   print  itemNo(count),desc$(count),resPrice(count),numOfBids(count)
  next

'************************* THIS IS TASK 2 *************************************'

  input "Press enter to  ********* START AUCTIONS **********";tmp
  cls

  op$="n"
  while op$="n" or op$="N"

   input "Enter item number to search : ";ms

   loc=0

   for count=1 to numOfItems
    if ms=itemNo(count) then
     loc=count
    end if
   next

   if loc=0 then
    print "Not Found......"
   end if

   if loc>0 then
    print "itemNo   description    ReservePrice    HighestBid"
    print itemNo(loc),desc$(loc),resPrice(loc),highestBid(loc)

    input "Enter Buyer Code : "; bc

   do
    input "Enter you Bid    : "; bid
     if bid <= highestBid(loc) then
      print "Bid must be larger than current highest bid "
     end if
   loop until bid > highestBid(loc)

     if (bid>highestBid(loc)) then
      highestBid(loc)=bid
      currentBuyer(loc)=bc
      numOfBids(loc)=numOfBids(loc)+1
     end if

   end if

   input "Want to END auctions [y/n] : ";op$
   cls
   wend

   print "----------------------------------------------------------------------------------------------------------"
   print " itemNo      Description    Reserve-Price   Total-Bids   Highest-Bid   Current-Buyer"
   print "----------------------------------------------------------------------------------------------------------"

  for count=1 to numOfItems
   print  itemNo(count),desc$(count),resPrice(count),numOfBids(count),highestBid(count),currentBuyer(count)
  next

  input "Press enter to continue...........";a

 '******************************** This is Task 3 **********************************

dim sold$(numOfItems)
dim itemFee(numOfItems)
dim SoldItemFee(numOfItems)
totalFee = 0
tsold = 0
noBids = 0
belowResPrice = 0

 for count = 1 to numOfItems

   if highestBid(count) > resPrice(count) then
    sold$(count) = "sold"
    itemFee(count) = highestBid(count) * 10/100
    SoldItemFee(count)=highestBid(count)+itemFee(count)
    totalFee = totalFee + itemFee(count)
    tsold = tsold + 1
   end if


   if numOfBids(count) = 0 then
    noBids = noBids + 1
   end if
 next count

' Displaying items that did not recieved any bids.
  print
  print "Items that had no bids are :"

 for count = 1 to numOfItems
  if highestBid(count) = 0 then
    print itemNo(count)
  end if
 next count

   print "---------------------------------------------------------------------------------------------------------------"
   print " itemNo  Description   Reserve-Price   Total-Bids   Highest-Bid    Current-Buyer  Company Fee  FinalFee  Status   "
   print "---------------------------------------------------------------------------------------------------------------"

   for count=1 to numOfItems
    print  itemNo(count),desc$(count),resPrice(count),numOfBids(count),highestBid(count),currentBuyer(count),itemFee(count),SoldItemFee(count),sold$(count)
   next

   Print "*******************************"
   Print " Total Company Fee = ";totalFee
   Print "*******************************"

  print "Items that have not reached their reserve price (with their final bid) are "
  print "---------------------------------------------------------------------------"
  print " itemNo       Highest-Bid         Total Bids "
  print "---------------------------------------------------------------------------"
  for count=1 to numOfItems
   if highestBid(count) < resPrice(count) then
    print itemNo(count), highestBid(count),numOfBids(count)
    belowResPrice = belowResPrice + 1
   end if
  next

  input "Press enter to continue...........";a

  print "Items that have received no bid "
  print "--------------------------------"
  print " itemNo       Total Bids   "
  print "--------------------------------"
  for count=1 to numOfItems
   if numOfBids(count)=0 then
    print itemNo(count), numOfBids(count)
   end if
  next

 print
 print "Total number of items sold                                        = ";tsold
 print "Number of items that did not meet the reserve price = ";belowResPrice
 print "Number of items with no bids                                    = ";noBids
 print "Total auction company fee                                          = ";totalFee




Monday, February 12, 2018

Pre-release Material May/June 2018


In preparation for the examination candidates should attempt the following practical tasks by writing and testing a program or programs.

A farmer records the milk production of a herd of cows. Every cow has a unique 3-digit identity code. Each cow can be milked twice a day, seven days a week. The volume of milk from each cow is recorded in litres correct to one decimal place (yield) every time the cow is milked. The size of the herd is fixed. At the end of the week the total and the average yield for each cow for that week is calculated.

The farmer identifies the cow that has produced the most milk that week. The farmer also identifies any cows that have produced less than 12 litres of milk on four or more days that week.

A program is required to record the yield for each cow every time it is milked, calculate the total weekly volume of milk for the herd and the average yield per cow in a week. The program must also identify the cow with the best yield that week and identify any cows with a yield of less than 12 litres of milk for four or more days that week.

Write and test a program or programs for the farmer.

•         Your program or programs must include appropriate prompts for the entry of data.
•         Error messages and other output need to be set out clearly and understandably.
•         All variables, constants and other identifiers must have meaningful names.

You will need to complete these three tasks. Each task must be fully tested.



TASK  - Record the yield.
Write a program for TASK  to record the milk yields for a week. The program records and stores the identity code number and the yield every time a cow is milked.


TASK 2 - Calculate the statistics.
 Using your recorded data from TASK 1, calculate and display the total weekly volume of milk for the herd to the nearest whole litre. Calculate and display the average yield per cow in a week to the nearest whole litre.

  
TASK 3 -  Identify the most productive cow and cows that are producing a low volume of milk.
Extend TASK 2 to identify and display the identity code number and weekly yield of the cow that has produced the most milk. Also identify and display the identity code numbers of any cows with a yield of less than 12 litres of milk for four days or more in the week.




Practice Questions

1          When you performed the tasks, you used variables. Write suitable declarations for two of these. State what you used each one for.

Variable 1:    CowHerd
Datatype:       Integer
Use:    To input no. of cows in the herd
Variable 2:    MostYield
Datatype:       Integer
Use:    To store the weekly yield of the cow that has produced the most milk

2          When you performed the tasks, you may have used arrays. Write suitable declarations for any two of these. State what you used each one for.

Declaration of Array1:        Dim IdentityCode(CowHerd) As Integer
Use:    To store the Identity Code of each cow in the herd Declaration of Array2:         Dim TotalCowYield(7) As Integer Use:    To store the total milk yield of each cow per week

3          Write an algorithm to complete Task 1, using either pseudocode, programming statements or a flowchart.

Dim CowHerd As Integer
Input "Enter No. of Cows in the Herd", CowHerd

Dim IdentityCode(CowHerd) As Integer
Dim Yield1(7), Yield2(7) As Single

For c = 1 To CowHerd
Do
 Input "Enter Three Digit Cow Code:", IdentityCode (c)
  If IdentityCode (c) < 100 Or IdentityCode (c) > 999 Then
   Print("Invalid Code! Re-Enter")
  End If
Loop Until IdentityCode (c) >= 100 And IdentityCode (c) <= 999

For d = 1 To 7
 Input "Enter Milk Yield for Session 1:", Yield1(d)
  Yield1(d) = Math.Round(Yield1(d), 1)
 Input "Enter Milk Yield for Session 2:", Yield2(d)
  Yield2(d) = Math.Round(Yield2(d), 1)
Next
Next

4          Write an algorithm to complete Task 2, using either pseudocode, programming statements or a flowchart.

Dim CowHerd As Integer
Dim TotalWeeklyVolume As Single
TotalWeeklyVolume = 0
Input "Enter No. of Cows in the Herd", CowHerd
Dim IdentityCode (CowHerd) As Integer
Dim Yield1(7), Yield2(7) As Single
Dim TotalCowYield(CowHerd), Average(CowHerd), Yield(7) As Single


               For c = 1 To CowHerd
Total(c) = 0
Do
Input "Enter Three Digit Cow Code:", IdentityCode (c)
If IdentityCode (c) < 100 Or IdentityCode (c) > 999 Then
Print "Invalid Code! Re-Enter")
End If
Loop Until IdentityCode (c) >= 100 And IdentityCode (c) <= 999

For d = 1 To 7
Input "Enter Milk Yield for Session 1:", Yield1(d)
Input "Enter Milk Yield for Session 2:", Yield2(d)
TotalCowYield (c) = TotalCowYield(c) + Yield1(d) + Yield2(d) TotaLWeeklyVolume = TotaLWeeklyVolume + TotalCowYield(c)
Next
Average(c) = TotalCowYield(c) / 14
Print "Total Milk Yield for Cow per week i: ", Math.Round(TotalCowYield(c))
Print "Average Milk Yield for Cow per week is: ", Math.Round(Average(c))
          Next

Print "Total weekly volume per week is: " , Math.Round(TotalWeeklyVolume)


5      Write an algorithm to complete Task 3, using either pseudocode, programming statements or a flowchart. You should assume that Task 1 & Task 2 has been already completed.

Dim MostID, Count As Integer
Dim MostYield As Single
Dim Yield(7) As Single
MostYield = 0
Count = 0
For c = 1 To CowHerd
For d = 1 To 7
Yield(d) = Yield1(d) + Yield2(d) If Yield(d) < 12 Then
Count = Count + 1
End If
Next

If Count >= 4 Then
Print "Cow with less than 12 litres of milk for four or more days ", IdentityCode(c)
End If

If MostYield <= TotalCowYield(c) Then
 MostID = IdentityCode(c)
 MostYield = TotalCowYield(c)
 Print("Cow that produced most milk in the week ", MostID , " the yield is ", MostYield
End If
Next

6      Explain how you performed validation of identity code input in Task 1. You can include pseudocode or programming statements as part of your explanations.

Identity code in Task 1 is validated using Do - Loop Until. The Identity code will be re- input if it is not in the range that is from 100 to 999. To print the error message IF-Then- Else-End If is used. Error message will be displayed if number is less than 100 or greater than 999. Following program code describes the working of validation:

Do
Input "Enter Three Digit Cow Code:", IdentityCode(c)
If IdentityCode (c) < 100 Or IdentityCode (c) > 999 Then
Console.WriteLine("Invalid Code! Re-Enter")
End If
Loop Until IdentityCode (c) >= 100 And IdentityCode (c) <= 999

7          Explain how your program calculates the total yield of the herd. You can include pseudocode or programming statements as part of your explanation.

Two arrays named as Yield1 and Yield2 are used to store the milk yield twice a day. Another array named as TotalCowYield will keep the sum of milk yield produced per day. Initialize the TotalCowYield array with zero.
TotalCowYield(c) = TotalCowYield(c) + Yield1(d) + Yield2(d) is used to sum milk yield per day. Then this TotalCowYield value is summed up to the TotalWeeklyVolume using the statement i.e.
TotalWeeklyVolume = TotalWeeklyVolume + TotalCowYield(c).

8          Explain  how  your  program  calculate  average  yield  to  the  nearest  whole number. You can include pseudocode, programming statements as part of your explanation.

Total yield produced by each cow in whole week is summed up in an array named as TotalCowYield(c). Divide each index of TotalCowYield(c) array with the number 14 to calculate the average yield per cow i.e. Average(c) = Math.Round(TotalCowYield(c) / 14) To display the  average yield to the nearest whole number Math.Round function is used i.e.

Print "Average Yield for Cow per week is: ", Math.Round(Average(c))

9          Comment on the efficiency of your design for Task 2.
Arrays are used to store the milk yield for each cow and two loops are used to take milk yield of each cow. External loop is used for each cow and internal loop is used for milk yield of seven days.

10        Comment on the efficiency of your design for Task 3.
The cow that has produced the most milk and less than 12 liters of milk for four days or more in the week are saved in a variable instead of an array. This will save the memory consumption and results will be displayed on the spot.

11    Give a set of “Identity Code data that could be used to check your rules in Task 1. Explain why you chose this data set.

Set 1         200
Reason     To test normal data
Set 2         1283
Reason     To test extreme data
Set 3         One
Reason     To test abnormal data

Computer Systems (FAST TRACK)

1     Data representation   1.1    Number systems   How and why computers use binary to represent all forms of data? •     Any form ...