Photo AI

A program is being created to convert the data capacity of a storage device into a different measure - OCR - GCSE Computer Science - Question 5 - 2021 - Paper 1

Question icon

Question 5

A-program-is-being-created-to-convert-the-data-capacity-of-a-storage-device-into-a-different-measure-OCR-GCSE Computer Science-Question 5-2021-Paper 1.png

A program is being created to convert the data capacity of a storage device into a different measure. The function, calculate(), takes the measurement (e.g. gigabyt... show full transcript

Worked Solution & Example Answer:A program is being created to convert the data capacity of a storage device into a different measure - OCR - GCSE Computer Science - Question 5 - 2021 - Paper 1

Step 1

Complete the function calculate

96%

114 rated

Answer

To complete the function calculate, we must ensure that conversions for gigabytes, megabytes, kilobytes, and bytes are accurately represented. Here’s how:

function calculate(measurement, number)
    if measurement == "gigabytes" then
        value = number * 1024 * 1024 * 1024 * 8
    elseif measurement == "megabytes" then
        value = number * 1024 * 1024 * 8
    elseif measurement == "kilobytes" then
        value = number * 1024 * 8
    elseif measurement == "bytes" then
        value = number * 8
    else
        return -1
    endif
    return value
endfunction

Join the GCSE students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;