MERGING TWO ARRAYS IN ONE ARRAY.
#include <iostream>
#include <conio.h>
using namespace std;
class Array
{
private:
int *Arr, Size, Num;
public:
Array(int Siz)
{
Arr = new int[Siz];
for (int I = 0; I <Siz; I++)
{
Arr[I] = 0;
}
Num = 0;
Size = Siz;
}
void Input()
{
int No;
cout << "Enter Size Of Array: ";
cin >> No;
Num = No;
cout << "Enter Elements Of Array: " << endl;
for (int I = 0; I <Num; I++)
{
cin >> Arr[I];
}
}
void Merge(Array Obj1, Array Obj2)
{
int I = 0, J = 0;
for (; I <Obj1.Num;)
{
Arr[Num++] = Obj1.Arr[I++];
}
for (; J <Obj2.Num;)
{
Arr[Num++] = Obj2.Arr[J++];
}
}
void Print()
{
cout << "\nElements Of Array is: " << endl;
for (int I = 0; I <Num; I++)
{
cout << Arr[I] << endl;
}
}
~Array()
{
cout << "\n\n\n\n************PROGRAM ENDED***************";
}
};
int main()
{
Array Obj1(10), Obj2(10), Obj3(20);
Obj1.Input();
Obj2.Input();
Obj3.Merge(Obj1, Obj2); ///elements of Obj1 and Obj2 will be Merged in Obj3;
Obj3.Print();
getch();
return 0;
}
0 comments:
Post a Comment