Question: How to write a readit, calcit, writeit program in C++ that: 1. Reads the first target pattern and compares it to each of the candidate

How to write a "readit, calcit, writeit" program in C++ that:

1. Reads the first target pattern and compares it to each of the candidate patterns. As it compares the patterns, it calculates a score that measures their "closeness." For example, if the target pattern is 242234 and the candidate pattern is 342121, the candidate pattern ;would be given a score of 6: score = abs(2 − 3) + abs(4 − 4) + abs(2 − 2) + abs(2 − 1) + abs(3 − 2) + abs(4 − 1) = 6 . Note that the score is the sum of the absolute values of the differences between each pair of digits in the pattern, and is not just the difference between the numbers!

2. Compares each of the three target patterns to all ten of the candidate patterns, and determines which candidate best fits the target.

3. Prints a three-column table to the screen with column headings Target , Candidate , and Score . At the end of the table, the program prints the location of the candidate that was closest to the target.

4. The program continues to compare target patterns until all the targets are tested.

Candidate
Target
111111
242234
342234
231244
222222
132232
231244

333333

342121

444444

243124

341232

132432

Step by Step Solution

3.49 Rating (146 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The question is incomplete The reason is that while the requi... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!