The following design is for a program which counts the number of occurrences of the digits '0'-'9' in a line of text entered from the keyboard. The data table is as follows:-
1 Total ¬ 0 2 NextNumber ¬ 0 3.1 loop while NextNumber ³ 0 3.2 write out "Enter a non-negative integer,or a negative one to quit: " 3.3 read in NextNumber 3.4 if NextNumber ³ 0 then 3.5 Total = Total + NextNumber 3.6 ifend 3.7 loopend 3.8 write out "Total = ", Total Write C++ code to implement this design. Your code should include declarations. You may assume that the MT262io library of functions is available for use. [6] Question 1B The following design is for a program which accepts a number of non-negative integers entered from the keyboard and writes out their sum. Entering a negative integer signals that data input is finished. The data table is as follows :-
Note: that the design that follows uses features of the ASCII code 1 Count ¬ 0 2 write out "Enter a line of text: " 3 read in Line 4 loop for Index ¬ 1 to Length(Line) 4.2 if Line[Index] ³ '0' and Line[Index] £ '9' then 4.3 Count ¬ Count + 1 4.4 ifend 4.5 loopend 5 write out "Number of digits = ", Count Write C++ code to implement this design. Your code should include declarations. You may assume that the MT262io library of functions is available for use. [6] Question 1C The following design is for a program which accepts a non-empty line of text entered from the keyboard and writes out the the number of vowels and the number of non-vowels in the text. The data table is as follows:-
1.1 Vowels ¬ 0 1.2 NonVowels ¬ 0 1.3 write out "Enter a non-empty line of text: " 1.4 read in Line 2.1 loop for Index ¬ 1 to Length(Line) 2.2 select case depending on value of Line[Index] 2.3 'a': Vowels ¬ Vowels + 1 2.4 'A': Vowels ¬ Vowels + 1 2.5 'e': Vowels ¬ Vowels + 1 2.6 'E': Vowels ¬ Vowels + 1 2.7 'i': Vowels ¬ Vowels + 1 2.8 'I': Vowels ¬ Vowels + 1 2.9 'o': Vowels ¬ Vowels + 1 2.10 'O': Vowels ¬ Vowels + 1 2.11 'u': Vowels ¬ Vowels + 1 2.12 'U': Vowels ¬ Vowels + 1 2.13 default: NonVowels ¬ NonVowels + 1 2.14 selectend 2.15 loopend 3.1 write out "Number of vowels = ", Vowels 3.2 write out "Number of non-vowels = ", NonVowels Write C++ code to implement this design. Your code should include declarations. You may assume that the MT262io library of functions is available for use. [6] |