Basically the program must read the input files and combine

Basically the program must read the input files and combine them into one file. This must be done utilizing arrays and it must follow the user interface in the pictures above using C++

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 3) 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. 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 \"Aubie\" 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 l: 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.

Solution

C++ code:

#include <bits/stdc++.h>
using namespace std;

vector< int > merge()
{
   cout << \"Welcome to Aubie\'s sorting program!\" << endl;
   string f1,f2;
   cout << \"Enter file1 name!\ \";
   cin >> f1;
   cout << \"Enter file2 name!\ \";
   cin >> f2;

   std::vector<int> v1;

   string line;
   ifstream myfile (f1.c_str());
   if (myfile.is_open())
   {
   while ( getline (myfile,line) )
   {
   string buf; // Have a buffer string
   stringstream ss(line); // Insert the string into a stream
   vector<string> tokens; // Create vector to hold our words
   while (ss >> buf)
   tokens.push_back(buf);
   for(int i = 0; i<tokens.size(); i++)
   {
       v1.push_back(atoi(tokens[i].c_str()));
   }
   }
   myfile.close();
   }
   else
   {
   cout << \"Unable to open file1\" << endl;
   exit(1);
   }
   cout << \"The list of \" << v1.size() << \" numbers in file \" << f1 << \" is:\ \";
   for(int i = 0; i<v1.size();i++)
   {
       cout << v1[i] << endl;
   }           
   // tokens.clear();
   std::vector<int> v2;
   ifstream myfile2 (f2.c_str());
   if (myfile2.is_open())
   {
   while ( getline (myfile2,line) )
   {
   string buf; // Have a buffer string
   stringstream ss(line); // Insert the string into a stream
   vector<string> tokens; // Create vector to hold our words
   while (ss >> buf)
   tokens.push_back(buf);
   for(int i = 0; i<tokens.size(); i++)
   {
       v2.push_back(atoi(tokens[i].c_str()));
   }
   }
   myfile2.close();
   }
   else
   {
   cout << \"Unable to open file2\" << endl;
   exit(1);
   }          
   cout << \"The list of \" << v2.size() << \" numbers in file \" << f2 << \" is:\ \";
   for(int i = 0; i<v2.size();i++)
   {
       cout << v2[i] << endl;
   }           
   v1.insert(v1.end(), v2.begin(), v2.end());
   return v1;
}

std::vector<int> mysort( std::vector<int> v)
{
   sort(v.begin(), v.end());
   cout << \"The sorted list of \" << v.size() << \" numbers is: \";
   for(int i = 0; i<v.size();i++)
   {
       cout << v[i] << endl;
   }
   string outfile;
   cout << \"Enter the name of output file!\ \";
   cin >>    outfile;
   ofstream myfile;
myfile.open(outfile.c_str());
   for(int i = 0; i<v.size();i++)
   {
       myfile << v[i] << \" \";
   }
   myfile.close();                        
   return v;
}

int main()
{
   std::vector<int> vf;
   vf = merge();
   vf = mysort(vf);
   cout << \"\ \ \";

   cout << \"*** Unit test Cases ***\ \";
   cout << \"Unit test case 1: Function Name- merge()\ \";
   cout << \"Case1.1 No input arguments\ \";
   cout << \"Case1.1 passed\ \ \";
   cout << \"Unit test case 2: Function Name- merge()\ \";
   cout << \"Case2.1 takes input a vector\ \";
   cout << \"Case2.1 passed\ \";
   return 0;
}

Sample Output:

Welcome to Aubie\'s sorting program!
Enter file1 name!
file1.txt
Enter file2 name!
file2.txt
The list of 6 numbers in file file1.txt is:
4
5
5
7
10
90
The list of 6 numbers in file file2.txt is:
1
4
5
7
8
12
The sorted list of 12 numbers is: 1
4
4
5
5
5
7
7
8
10
12
90
Enter the name of output file!
sortout.txt

*** Unit test Cases ***
Unit test case 1: Function Name- merge()
Case1.1 No input arguments
Case1.1 passed

Unit test case 2: Function Name- merge()
Case2.1 takes input a vector
Case2.1 passed

Basically the program must read the input files and combine them into one file. This must be done utilizing arrays and it must follow the user interface in the
Basically the program must read the input files and combine them into one file. This must be done utilizing arrays and it must follow the user interface in the
Basically the program must read the input files and combine them into one file. This must be done utilizing arrays and it must follow the user interface in the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site