Starting from:

$25

COMP2710 Project 3- streams and file I/O  Solved


Goals: 

•      To learn streams and file I/O 

•      To learn how to use tools for stream I/O

•      To use arrays to group data elements

•      To design and implement functions (Note: this topic was covered in Homework 2)

•      To perform unit testing

•      To design a simple algorithm

 

 

Write a program that merges the numbers in two files and writes all the numbers into a third file. Your program takes input from two different files and writes its output to a third file. Each input file contains a list of numbers of type int in sorted order from the smallest to the largest. After the program is run, the output file will contain all the numbers in the two input files in one longer list in sorted order from smallest to largest. If there are same numbers in these two arrays, just output this number twice.

You must provide the following user interface. The user input is depicted as Bold, but you do not need to display user input in bold. Please replace “Li” with your name. Your program must first run a list of unit test cases and print unit testing results. Next, your program loads two input files and merges the numbers in the two files.

*** Unit Test Cases  ***

Unit Test Case 1: Function Name – show function name here.

       Case 1.1: explain test case 1.1 here (e.g., input arguments).         Case 1.1 passed.

       Case 1.2: explain test case 1.2 here (e.g., input arguments).         Case 1.2 passed.

         ...

 Press any key to continue...

 

 Unit Test Case 2: Function Name – show function name here.

 

     Case 2.1: explain test case 2.1 here (e.g., input arguments).           Case 2.1 passed.

         Case 2.2: explain test case 2.2 here (e.g., input arguments). 

       Case 2.2 passed....      Press any key to continue...

  

Add more test cases below

Press any key to continue...
1

 

 

*** Welcome to Li’s sorting program ***

 Enter the first input file name: input1.txt The list of 4 numbers in file input1.txt is:  3

 7

9

 12 

Enter the second input file name: input2.txt  The list of 6 numbers in file input2.txt is:

4

6

 8

 11

 16

 23

 

 The sorted list of 10 numbers is: 3 4 6 7 8 9 11 12 16 23

 Enter the output file name: output3.txt

 *** Please check the new file - output3.txt ***

*** Goodbye. ***

 
 

Your program must follow the above user interface, which includes unit testing results. 

 

Design Issues:

Please do NOT intend to implement this project using a single main() function.

You need at least three functions to implement this project. The suggested functions are:

 

1.  array_size <- readfile(inputArray[], instream)

2.  outputArray_size <- sort(inputArray1[], inputArray1_size, inputArray2[], inputArray2_size, outputArray[])

3.  void <- writefile(outputArray[], outputArray_size)

 

Unit Testing:

Unit testing is a way of determining if an individual function or class works. You need to isolate a single function or class and test only that function or class. For each function in this homework, you need to check normal cases and boundary cases. 

 

            Examples for tested values:

•      string – empty string, medium length, very long

•      Array – empty array, first element, last element

•      Int – zero, mid-value, high-value

 

2

You must implement a unit test driver for each function implemented in your program. You may need to use assert() to develop your unit test drivers if tested results are predictable.

 

Integration Testing:

Integration testing (a.k.a., Integration and Testing) is the phase in software testing in which individual software modules are combined and tested as a group. You may use the attached two input files to test the correctness of your program as an entire system.

 

More products