wpe3B5.jpg (4091 bytes) Question #3(a-c)/ Answer


Question 3A

A computer component supplier keeps stock data on products in the form of a table as illustrated below:-

Stock code Category Description Quantity in stock
M002 Motherboard ABit BX 45
InV006teger Video card Voodoo AGP 27
C003 Modem Rockwell PCI 11

A supplier keeps records on a maximum of 300 products.

  1. Write down a C++ declaration for a record type ItemType, to hold the four pieces of data for a product. Declare a variable StockList to hold a table of 300 such records.
  2. Write a fragment of C++ code which will initialise the first record in Stocklist with the data on the ABit motherboard given in the illustration above.
  3. Write a fragment of C++ code whose purpose is to search the table StockList for out-of-stock items (items whose 'Quantity in stock' entry is zero). For any such items found, the stock code and description should be written out. You may assume that the entire table of 300 records has been initialised. [7]

Question 3B

A bookshop keeps information about its stock in the form of a table of records. For each book, the following information is kept:-

  • the ISBN (a string)
  • the title (a string)
  • the author, or first author if there is more than one, (a string)
  • the cost (a float)
  • the number in stock (an integer)

The stock never exceeds 5000 different titles

  1. Write down a C++ declaration for a record type BookType, to hold the four pieces of data for a product. Declare a variable BookStock to hold a table of 5000 such records.
  2. Write a fragment of C++ code which will initialise the twentieth record in BookStock with the data for the following book.
        ISBN 0-13-115007-3, "Communications and Concurrency" by Robin Milner, price £23.95, 1 in stock.
  3. Write a fragment of C++ code whose purpose is to search the table BookStockList for an item whose ISBN matches the value stored in a (string) variable called WantedISBN. If found  a suitable message should be written out. You may assume that the entire table of 5000 records has been initialised. [7]

Question 3C

An OU research project on drop-out rates keeps information on some courses in the form of a table. An example of the contents of the table is given below. (The numbers are entirely fictional.):-

Course code Number at start Number at examination
M203 873 ABit BX
M206 5043 Voodoo AGP
MT262 1357 Rockwell PCI

The project keeps records on 25 courses.

  1. Write down a C++ declaration for a record type CourseType, to hold the four pieces of data for a product. Declare a variable ProjectData to hold a table of 25 such records.
  2. Write a fragment of C++ code which will initialise the third record in ProjectData with the data on the MT262  given in the illustration above.
  3. Write a fragment of C++ code whose purpose is to search the table ProjectData for courses where fewer than 75% of the students who actually reach the examination. For any such courses found, the course and percentage should be written out,t, if there are none, a suitable message should be given. You may assume that the entire table of 25 records has been initialised. [7]
first previous key.gif (977 bytes) next last