A program, written using object-oriented programming, stores pictures as objects. The program stores the dimensions of the picture (width and height), the colour of the frame (e.g. black), and a description of the picture (e.g. flowers). The class has the following attributes and methods. Description : STRING // stores a description of the picture Width : INTEGER // stores the width e.g. 30 Height : INTEGER // stores the height e.g. 40 FrameColour : STRING // stores the colour e.g. black Constructor() // takes all four values as parameters and sets them to the private attributes GetDescription() // returns the description of the picture GetHeight() // returns the height GetWidth() // returns the width GetColour() // returns the frame colour SetDescription() // takes the new description as a parameter and writes the value to description
- (a)The constructor takes the picture description, frame colour, height, and width as parameters and sets these to the private attributes. Write the program code to declare the class Picture and its constructor. Do not write any other methods. Use your language appropriate constructor. All attributes should be private. If you are writing in Python programming language, include attribute declarations using comments. Save your program as question 2. Copy and paste the program code into part 2(a) in the evidence document.[5]
- (b)The four get methods return the associated attribute, for example, GetDescription() returns the description of the picture. Write the four get methods. Save your program. Copy and paste the program code into part 2(b) in the evidence document.[3]
- (c)The method SetDescription() takes a new description as a parameter, and writes this value to the appropriate attribute. Write the method SetDescription(). Save your program. Copy and paste the program code into part 2(c) in the evidence document.[2]
- (d)Write program code to declare an array of type Picture with 100 elements. Save your program. Copy and paste the program code into part 2(d) in the evidence document.[1]
- (e)The text file Pictures.txt stores the data for the pictures in the order: description, width, height, colour. For example, for the first picture in the text file: Flowers is the description 45 is the width 50 is the height black is the frame colour. The data read into the program from the text file is stored in an array of type Picture. The main program and the function will need to access the array data. The function ReadData(): • opens the file Pictures.txt • reads the data from the file • creates a new object of type Picture for each picture • writes each object to the array • raises an exception if the file cannot be found • counts and returns the number of pictures in the array. Write program code for the function ReadData(). Save your program. Copy and paste the program code into part 2(e) in the evidence document.[8]
- (f)The main program calls the function ReadData(). Write the main program. Save your program. Copy and paste the program code into part 2(f) in the evidence document.[2]
- (g)The main program needs to ask the user to input their requirements for a picture. The user will enter the colour of the frame, the maximum width, and the maximum height of the picture. The program will then search the array of pictures, and output the picture description, the width, and the height of any picture that meets the user's requirements. The program should allow the user to input the colour in any case (e.g. Silver, silver, or SILVER), and still output the correct results. Edit the main program to perform the described actions. Save your program. Copy and paste the program code into part 2(g) in the evidence document.[7]
- (h)Test your program by inputting the following search criteria: : BLACK, 100, 100 silver, 25, 25 Take screenshots to show the output for both search criteria. Copy and paste the screenshots into part 2(h) in the evidence document.[2]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2021). The mark or mark type is shown in brackets.
- [1] class declared (with appropriate close) with identifier Picture
- [1] correct attribute declarations with Data types (Description, Frame colour = string, Width, Height = integer.)
- [1] ...as private
- [1] correct constructor (with appropriate close) with four parameters...
- [1] ...parameters assigned to attributes
- [1] 1 Get method taking no parameter...
- [1] ...returning correct attribute
- [1] remaining 3 correct methods
- [1] Set method (procedure) taking parameter (no return)
- [1] ...assigning parameter to correct attribute
- [1] 1 mark for declaring array of type Picture with 100 elements
- [1] Function/procedure declared with correct name (and close, passing array by reference or global array declared)
- [1] opening Pictures.txt for Read
- [1] looping until EOF / or equivalent
- [1] ...reading each set of 4 lines from the file within loop
- [1] creating object of type Picture ...with Description, Width, Height, Frame colour from File as parameters
- [1] ..adding to next array element/appending
- [1] closing the File (in an appropriate place)
- [1] counts and returns number of pictures in array
- [1] Exception with opening the file inside... ...appropriate catch and output
- [1] calling function ReadData()
- [1] ...store/use the Number of elements returned/by reference based on answer to part 2e
- [1] taking as input all three values (colour, width, height)
- [1] converting colour to lowercase // uppercase
- [1] looping through array ...using returned value from part 2(f) as max index
- [1] .within loop, checking if Array[index].FrameColour matches input
- [1] .and checking if Array[index].FrameWidth <= input Width
- [1] ...and checking if Array[index].FrameHeight <= input Height
- [1] ...all using Get methods
- [1] outputting the Picture Description, Width and Height for all/any matching Pictures
- [1] 1 mark for screenshot showing output for BLACK, 100, 100
- [1] 1 mark for showing no outputs for silver, 25, 25
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →