Computer Science Write a program that processes a data sequence according to the following specifications: The sequence has three kinds of positive numbers: red, black and white. Each red number is preceded by the letter r, each black number is preceded by the letter b and each white number is preceded by the letter w. The number 0 indicates the end of data. If a number is preceded by any character other than r, b or w, the number is ignored. For instance, if the input to the program is: r 23 b 15 b 11 w 17 c 13 r 19 b 0, then we have two red numbers, 23 and 19, two black numbers 15 and 11, and one white number, 17. The number 13 is ignored. (The terminating 0 is also a black number but it is not processed.) The program produces the following output: The sum of red numbers is 42 The sum of black numbers is 26 The sum of white numbers is 17 Assume that input is from the keyboard and is in the prescribed format. (a). In 2-3 sentences, describe your strategy for solving this problem. (b). List 4 or 5 test inputs and expected outputs. Why did u choose these tests? (c). List the sequence of operations that will be performed in order to process the data according to your strategy. (d). What kind of a loop (pretest or post-test) seems most appropriate for this repetition and why? (e). Within each iteration, how will you process a token? What kind of C++ statement will you use for this and why? (f).Write the C++ code (write the code for main() only) for performing the entire computation.
Computer Science
Write a
The sequence has three kinds of positive numbers: red, black and white. Each red number is preceded by the letter r, each black number is preceded by the letter b and each white number is preceded by the letter w. The number 0 indicates the end of data. If a number is preceded by any character other than r, b or w, the number is ignored.
For instance, if the input to the program is: r 23 b 15 b 11 w 17 c 13 r 19 b 0, then we have two red numbers, 23 and 19, two black numbers 15 and 11, and one white number, 17. The number 13 is ignored. (The terminating 0 is also a black number but it is not processed.) The program produces the following output:
The sum of red numbers is 42
The sum of black numbers is 26
The sum of white numbers is 17
Assume that input is from the keyboard and is in the prescribed format.
(a). In 2-3 sentences, describe your strategy for solving this problem.
(b). List 4 or 5 test inputs and expected outputs. Why did u choose these tests?
(c). List the sequence of operations that will be performed in order to process the data according to your strategy.
(d). What kind of a loop (pretest or post-test) seems most appropriate for this repetition and why?
(e). Within each iteration, how will you process a token? What kind of C++ statement will you use for this and why?
(f).Write the C++ code (write the code for main() only) for performing the entire computation.
Step by step
Solved in 5 steps with 7 images