Object Oriented Languages (OCR A Level Computer Science): Exam Questions

45 mins12 questions
13 marks

An object oriented system is implemented to organise further information about each worker’s attendance. Classes, objects, methods and attributes are used in this system.

State the meaning of each of the following terms:

  • Object

  • Method

  • Attribute

Did this page help you?

22 marks

Barney is writing a program to store data in a linked list. He is writing the initial program for a maximum of 10 data items.

Each node in the linked list has a data value and a pointer (to the next item).

A null pointer is stored with the value –1

Barney wants the nodes to be stored as objects using object-oriented programming. He designs the following class.

class: node

attributes: private
data : Real
private pointer : Integer

methods:

new (newData, newPointer)

getData()

getPointer()

setData(newData)

setPointer(newPointer)

The constructor assigns the parameters to the attributes to create an object

The class node, uses get methods and set methods.

Describe one difference between get methods and set methods.

Did this page help you?

33 marks

A supermarket uses an object-oriented approach to organise items that it offers for sale. Part of the class definition for the ItemForSale class is shown below.

class ItemForSale 
      public itemName 
      public price 
      public discount 
     
      … 

endclass

The discount attribute represents a percentage discount on the price. The discount can be between 0 and 50 (inclusive). All new items for sale initially have a discount value of 0.

Write the constructor method for the ItemForSale class.

Did this page help you?

43 marks

A supermarket uses an object-oriented approach to organise items that it offers for sale. Part of the class definition for the ItemForSale class is shown below.

class ItemForSale 
      public itemName 
      public price 
      public discount 
     
      … 

endclass

Write a line of code to create an object of type ItemForSale called mushypeas that has a name of “mushy peas” and a price of £0.89

Did this page help you?

51 mark

State the purpose of a constructor.

Did this page help you?

12 marks

Describe what is meant by inheritance with reference to these classes.

Did this page help you?

23 marks

A supermarket uses an object-oriented approach to organise items that it offers for sale. Part of the class definition for the ItemForSale class is shown below.

class ItemForSale
public itemName
public price
public discount

endclass

Write the calculatePrice() method, which applies the percentage discount to the price and returns the new value.

Did this page help you?

33 marks

The supermarket has previously had issues with discounts being set as values above 50.

Explain how encapsulation could be applied to the ItemForSale class to stop this problem from occurring.

You are not expected to write any code in your answer to this question.

Did this page help you?

44 marks

Some items in the supermarket are only available through home delivery. These items are the same as ItemsForSale with the following exceptions:

  • the supermarket also stores the location of the stock

  • the percentage discount allowed is up to 75 rather than the standard 50.

Explain how inheritance can be used to implement the above requirements.

Did this page help you?

54 marks

Barney wants the nodes to be stored as objects using object-oriented programming. He designs the following class.

class: node

attributes:
private data : Real
private pointer : Integer

methods:
new (newData, newPointer)
getData()
getPointer()
setData(newData)
setPointer(newPointer)

The constructor assigns the parameters to the attributes to create an object.

Write an algorithm, using pseudocode or program code, to create the class node, its attributes and constructor.

You do not need to write the get and set methods.

Did this page help you?

15 marks

A business uses an array with the identifier wNames to store workers’ names. A variable with the identifier top is used to store the index of the last element to be added to the array, which is also the element which will next be removed.

wNames

0

1

2

3

4

5

6

Kirstie

Martyn

Louise

Alex

Anna

top

4

An object oriented system is implemented to organise further information about each worker’s attendance. Classes, objects, methods and attributes are used in this system.

Each worker has a name and an attendance figure which can be between 0 and 100.

Write a definition for a fully encapsulated customer class, providing both get and set methods for all attributes. You do not have to write code for the constructor method.

Did this page help you?

212 marks

Barney would like his linked list to be part of a base program that is saved in a library. This means that it can be reused and changed by other programs.

Discuss the benefits of using different object-oriented techniques that Barney could use to achieve this.

Did this page help you?