Photo AI

A string variable called month has been assigned the value ‘April’ and another string variable called year has been assigned the value ‘2019’ as shown below - Scottish Highers Computing Science - Question 2 - 2019

Question icon

Question 2

A-string-variable-called-month-has-been-assigned-the-value-‘April’-and-another-string-variable-called-year-has-been-assigned-the-value-‘2019’-as-shown-below-Scottish Highers Computing Science-Question 2-2019.png

A string variable called month has been assigned the value ‘April’ and another string variable called year has been assigned the value ‘2019’ as shown below. Line 1... show full transcript

Worked Solution & Example Answer:A string variable called month has been assigned the value ‘April’ and another string variable called year has been assigned the value ‘2019’ as shown below - Scottish Highers Computing Science - Question 2 - 2019

Step 1

DECLARE shortDate INITIALLY month[0:3] + year[2:4]

96%

114 rated

Answer

To assign the value 'Apr19' to the variable shortDate, we use substring operations. The expression month[0:3] extracts the first three characters of the string 'April', which yields 'Apr'.

Next, year[2:4] extracts the last two characters of the year string '2019', giving us '19'.

Concatenating these two substrings together gives us:

shortDate = month[0:3] + year[2:4]

Therefore, after execution, shortDate will hold the value 'Apr19'.

Step 2

Alternative Method: Using SUBSTRING Functions

99%

104 rated

Answer

An alternative approach can use the substring or similar functions depending on the programming language. For example:

shortDate = substring(month, 0, 3) + substring(year, 2, 2)

This achieves the same result, and shortDate will also contain 'Apr19'.

Join the Scottish Highers students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;