1 Problem description Write a program that merges the number

1. Problem description: Write a program that merges the numbers in two files and writes all the numbers into a third file. Each input file contains a list of unsorted integer numbers. There are total 50 numbers in two input files. The output file should contain all numbers in ascending order. (Hint: You could use either selection sort, bubble sort, or insertion sort.)

The two input files are input1_1.txt and input1_2.txt, the output file should look similar to output.txt.

They are all available online at:

http://www.cs.iusb.edu/~yul/C201/source/hw1/input1_1.txt

http://www.cs.iusb.edu/~yul/C201/source/hw1/input1_2.txt

http://www.cs.iusb.edu/~yul/C201/source/hw1/output.txt

The executable of the program is at: http://www.cs.iusb.edu/~yul/C201/source/hw1/s1.ex

Below is my Problem 1 source code and i need help Completing it please someone help! This is due today and I have no idea how to do it! :(

2. (Rework of Homework 1, Question 1) Problem description: Write a program that
merges the numbers in two files and writes all the numbers into a third file. Each input
file contains a list of unsorted integer numbers. We do not know how many numbers are
contained in these two files. You must (1) count the number of integers in these two
files and (2) create a dynamic array to store and sort the integers.

The two input files are input1_1.txt and input1_2.txt, the output file should look similar to
output.txt. They are all available online at:
http://www.cs.iusb.edu/~yul/C201/source/hw1/input1_1.txt
http://www.cs.iusb.edu/~yul/C201/source/hw1/input1_2.txt

#include <iostream>
#include <fstream>
using namespace std;

void main()
{
   ifstream fin;
   ifstream fin2;
   ofstream fout;

   fin.open(\"input1_1.txt\");
   fin2.open(\"input1_2.txt\");
   fout.open(\"output.txt\");

   int Name1[50];

   int i;


   for (i = 0; i <= 29;i++)
   {
       fin >> Name1[i];
   }

   for (i; i <= 49;i++)
   {
       fin2 >> Name1[i];
   }
   for (int i = (50 - 1); i >= 0; i--)
   {
       for (int j = 1; j <= i; j++)
       {
           if (Name1[j - 1] > Name1[j])
           {
               int temp = Name1[j - 1];
               Name1[j - 1] = Name1[j];
               Name1[j] = temp;
           }
       }
   }

   for (i = 0;i <= 49;i++)
   {
       fout << Name1[i] << \" \";
   }

   fin.close();
   fin2.close();
   fout.close();

   cin.ignore(2);
}

Solution

Here is the code for you:

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin;
ifstream fin2;
ofstream fout;
fin.open(\"input1_1.txt\");
fin2.open(\"input1_2.txt\");
fout.open(\"output.txt\");
//We do not know how many numbers are contained in these two files.
//You must (1) count the number of integers in these two files and
//(2) create a dynamic array to store and sort the integers.
   int file1Count = 0, file2Count = 0;
   int temp;
   //Count the number of integers in first file.
   while(!fin.eof())
   {
   fin>>temp;
   file1Count++;
   }
     
   //Count the number of integers in the second file.
   while(!fin2.eof())
   {
   fin2>>temp;
   file2Count++;
   }
     
   int Name1[file1Count + file2Count];
fin.close();
fin2.close();
fin.open(\"input1_1.txt\");
fin2.open(\"input1_2.txt\");
  
int i;
  
for (i = 0; i < file1Count; i++)
{
fin >> Name1[i];
}
for (; i < file1Count+file2Count; i++)
{
fin2 >> Name1[i];
}
for (int i = (file1Count+file2Count - 1); i >= 0; i--)
{
for (int j = 1; j <= i; j++)
{
if (Name1[j - 1] > Name1[j])
{
int temp = Name1[j - 1];
Name1[j - 1] = Name1[j];
Name1[j] = temp;
}
}
}
for (i = 0;i <= file1Count+file2Count;i++)
{
fout << Name1[i] << \" \";
}
fin.close();
fin2.close();
fout.close();
//cin.ignore(2);
}

1. Problem description: Write a program that merges the numbers in two files and writes all the numbers into a third file. Each input file contains a list of un
1. Problem description: Write a program that merges the numbers in two files and writes all the numbers into a third file. Each input file contains a list of un
1. Problem description: Write a program that merges the numbers in two files and writes all the numbers into a third file. Each input file contains a list of un

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site