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 Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Topic Video
Question

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.

Expert Solution
steps

Step by step

Solved in 5 steps with 7 images

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY