Write a program in C++ Using inheritance, extend the template class _ Concatenat
ID: 647331 • Letter: W
Question
Write a program in C++ Using inheritance, extend the template class
_ Concatenate two indexed lists.
_ Sort an indexed list using the selection sort algorithm
_ Find the index of a target item using the binary search algorithm.
Write a driver program that will create two indexed lists of integers, concatenate the two
lists, sort the resulting list and then display it. In addition, the driver will search for a target in the resulting list.
A sample run follows.
List 1 of type "int"
Enter number of list items: 4
Enter next item: 1
Enter next item: 7
Enter next item: 5
Enter next item: 3
List 2 of type "int"
Enter number of list items: 3
Enter next item: 6
Enter next item: 2
Enter next item: 4
List 3: List 1 concatenated to List 2
1 7 5 3 6 2 4
List 3 sorted in ascending order
1 2 3 4 5 6 7
Enter the number to search in List 3: 12
12 is not in List 3
Explanation / Answer
#include <iostream>
class input()
public:
{
int n, arr1[], arr2[];
cout<<("enter number of elements in list 1");
cin>> n;
for (int i = 0; i < n; i ++)
{
cout<< ("Enter item");
cin>>arr[i];
}
cout<<("enter elements in list 2");
cin >> m;
for (int i = 0; i < m; i ++)
{
cout<< ("Enter item");
cin>>arr[i];
}
}
class concat_list : public input
public:
{
int j = 0;
for (int i = n; i < n + m; i ++)
{
arr[i] = arr2[j];
j = j + 1;
}
}
class sort: public concat_list
public:
{
int i, j, k;
for (i = 0; i < n + m; i++)
for (j = 0; j < n + m; j ++)
{
if arr[j] < arr[i]
{
k = arr[i];
arr[i] = arr[j];
arr[j] = k;
}
}
void main()
{
input in;
sort s;
concat_list l;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.