ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions
4 marks · Standard algorithms
An algorithm is required to count the number of upper and lower case characters in a string variable called sentence. Upper case characters have an ASCII code between 65 and 90 and lower case characters are between 97 and 122. The expected output for the sentence ‘To be or not to be?’ would be: Upper case: 1 Lower case: 12 Using a design technique of your choice, design this algorithm.
• initialising and increment both counters • loop for length of string/each letter • two if statements or if/else if to check each single character • correct conditions for lower case and uppercase Set lower to 0 Set upper to 0 For each character in sentence If current character>=’a’ and <=’z’ Set lower to lower +1 Else if current character>=’A’ and <=’Z’ Set upper to upper +1 End if End loop Candidate can also use ASCII codes for upper (65-90) and lowercase (97- 122) Award fourth bullet if candidate has used a correct condition and an Else statement.