Question
Reads(by ifstream infile ) the first target pattern and compares it to each of the candidate patterns. As it compares the patterns, it calculates a
Reads(by ifstream infile) 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.
Candidate | Target |
111111 | 242234 |
342234 | 231244 |
222222 | 132232 |
231244 | |
333333 | |
342121 | |
444444 | |
243124 | |
341232 | |
132432 |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started