The main objective of this assignment is to demonstrate your understanding file input and output, and to implement an algorithm to merge two unsorted data files into one sorted data file.

  • Demonstrate how to merge two sorted lists into one sorted output file.
  • Demonstrate how to implement the given algorithm to solve the merge problem.
  • Do not modify the input data files.
  • Do not define additional arrays in your program solution.
  • The two existing arrays, already sorted, must be merged externally into the required output file.
  • Use the algorithm that follows as the basis of your solution.
  • After the merged output file is closed, reset the counters and write a loop to print both lists side-by-side to the standard output screen; it should similar to the first two columns on the first page of these instructions. Hint: you will need a decision about how to use setw() to finish up.

Considerations:

  • The algorithm uses different counters for each of the arrays. You need to maintain those two counters, one for each list as indicated in the solution algorithm.
  • The list counters need to be compared to the lengths of their corresponding lists in order to determine when the end of list A or the end of list B has been reached. Notice also that one of the lists will end before the other in the first part, so when that loop ends, a follow up IF-ELSE with nested loops is used to determine which array still needs to be added to the output file..

Use the start-up source code file MergeSort.cpp provided to complete this assignment. Start by creating a new empty project and the copy the source code (.cpp) file and data .txt files into the project folder. Then right-click the Source node in Solution Explorer to Add Existing item into your projects solution. Be sure you can compile, load and run the program to make sure that much works, which should print some messages to the screen and create an output file that initially will be empty you will be merging two sorted lists into one sorted output file. Complete the TODO comments where indicated in the source code file.

Given input files A and B read into two arrays and then sorted separately, the program will use those two lists and the algorithm that follows to write the merged output file AB (Note: TestScoresMergeAB file should contain just one

TestScoresA

88
87
88
66
55
56
75
75
78
80
80
90
99
87
44
34
0
100 TestScoresB

80
91
55
67
75
90
80
100
35
98
0
66
99
87
75
34
15
90
88
100
44
83 TestScoresMergeAB

0
0
15
34
34
35
44
44
55
55
56
66
66
67
75
75
75
75
78
80
.
. TestScoresMergeAB

.
.
80
80
80
83
87
87
87
88
88
88
90
90
90
91
98
99
99
100
100
100

This will not be an interactive program, but console output should include at least the following messages about program activity:

Opening files....
Reading files....
Merging files....
Finishing up....
End program.

Use the algorithm shown here to implement your solution.

Merge list-A and list-B into output file-AB
until (end-of-list-A) or (end-of-list-B)
if next-A <= next-B then
write next-A to file-AB
increment list-A counter
else
write next-B to file-AB
increment list-B counter
if (end-of-list-A) then
until (end-of-list-B)
write next-B to file-AB
increment list-B counter
else
until (end-of-list-A)
write next-A to file-AB
increment list-A counter
close output file-AB
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.