Question: how to transfer these in to readit, calcit, writeit programm in c++: (https://www.chegg.com/homework-help/questions-and-answers/problem-write-program-determines-well-pattern-target-numbers-matches-set-candidate-numbers-q1681043) #include #include #include using namespace std; // returns score for the target

how to transfer these in to "readit, calcit, writeit" programm in c++:

(https://www.chegg.com/homework-help/questions-and-answers/problem-write-program-determines-well-pattern-target-numbers-matches-set-candidate-numbers-q1681043)

#include #include #include using namespace std; // returns score for the target and data value // as described in th problem int getScore(int target, int data) { int score = 0; while(target > 0) { int a = target % 10; int b = data % 10; target /= 10; data /= 10; score += abs(a-b); } return score; } // main funciton int main() { //opens candidates file ifstream indata("candidates.txt"); //opens target file ifstream target("targets.txt"); //creates results file to output ofstream output("results.txt"); int data, targ, location; int minScore, score; cout << "Target\t\tCandidate\tScore" << endl; output << "Target\t\tCandidate\tScore" << endl; //loop through target file data while(!target.eof()) { //gets target value target >> targ; location = 0; minScore = 100; // loops through indata file for(int i=0;i<10;i++) { //gets data indata >> data; //calculates score score = getScore(targ, data); //writes the values to the both console and output file cout << targ << "\t\t" << data << "\t\t" << score << endl; output << targ << "\t\t" << data << "\t\t" << score << endl; // finds minimum score location if(minScore > score) { minScore = score; location = i+1; } } // writes the min score location to both screen and output file cout << "loaction of the closest candidate to the target " <

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!