-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASSSI-5.CPP
75 lines (74 loc) · 1.44 KB
/
ASSSI-5.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <fstream>
using namespace std;
const char* file1 = "Source1.txt";
const char* file2 = "Source2.txt";
const char* file3 = "Target.txt";
int main()
{
ifstream inputfile1, inputfile2;
ofstream outfile;
inputfile1.open(file1);
inputfile2.open(file2);
if (inputfile1 == NULL || inputfile2 == NULL)
{
perror("Could not open the files");
cout << "Press any key to exit" << endl;
getchar();
exit(0);
}
outfile.open(file3);
if (!outfile)
{
perror("Could not open the file");
cout << "Press any key to exit" << endl;
getchar();
exit(0);
}
int arr1[5], arr2[5];
while (inputfile1.read((char*)&arr1, sizeof(arr1)) != NULL)
{
cout << "Data received from Source1.txt" << endl;
}
for (int i = 0; i < 5; i++)
{
cout << arr1[i] << " ";
}
cout << endl;
while (inputfile2.read((char*)&arr2, sizeof(arr2)) != NULL)
{
cout << "Data recieved from Source2.txt" << endl;
}
for (int i = 0; i < 5; i++)
{
cout << arr2[i] << " ";
}
cout << endl;
int arr[10], i = 0, j = 0, k = 0;
fill(arr, arr + 10, 0);
while (i < 5 && j < 5)
{
if (arr1[i] < arr2[j])
{
arr[k++] = arr1[i++];
}
else
{
arr[k++] = arr2[j++];
}
}
while (i < 5)
{
arr[k++] = arr1[i++];
}
while (j != 5)
{
arr[k++] = arr[j++];
}
cout << "The Merged Array that will be stored in Target.txt (in binary form): " << endl;
for (i = 0; i < 10; i++)
cout << arr[i] << " ";
cout << endl;
outfile.write((char*)&arr, sizeof(arr));
return 0;
}