Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// Need help with the following c++ code, just need help with filing the code, need code where * appears // Instructions : Void Combine

// Need help with the following c++ code, just need help with filing the code, need code where * appears

// Instructions : Void Combine will take 3 vectors as arguments: A, B and R.

// Combine should work for any size vectors as long as the size of A and B are the same.

// It will combine the elements of A and B into R to produce the sorted list R.

// You should know how to find the size of a vector.

// Display comparison every time an element-element comparison is done.

Your main()

  1. Will declare three vectors L1, L2 and L3.
  2. Will ask the user to type integers in increasing order into L1.
  3. Then ask the user to type more integers in increasing order into L2.
  4. Then it will call void Combine to combine L1 and L2 to produce L3 which is passed back by reference.
  5. Display what is in L3.

Required Test Cases: (Must test in this order)Text2.txt

  1. Combine 1 2 3 with 4 5 6
  2. Combine 1 3 5 with 2 4 6
  3. Combine 4 5 6 with 1 2 3
  4. Combine 1 2 5 6 with 3 4 7 8

// Code

using namespace std;

#include

#include

//--------------------------------------------

//CS311 HW2P2 Combine

//Name: **

//Compiler: g++

//--------------------------------------------

// combine two sorted lists A and B into R

// displays comparison every time it is done

void combine( vector<int> A, vector<int> B, vector<int> &R )

{

**

cout << "comparison" << endl;

** // be careful -- R comes in as an empty vector

}

int main()

{

vector<int> L1;

vector<int> L2;

vector<int> L3;

int N; // how many elements in each of L1 and L2

int e; // for each element

cout << "How many elements in each list?" << endl;

cin >> N;

cout << "List1" << endl;

for (int i = 1; i <=N; i++)

{ cout << "element :"; cin >> e; L1.push_back(e);}

cout << "List2" << endl;

for (int i = 1; i <=N; i++)

{ cout << "element :"; cin >> e; L2.push_back(e);}

// call combine here to combine L1 and L2 into L3

**

cout << "The result is: ";

for (int i = 0; i < N*2; i++)

{ cout << L3[i]; } cout << endl;

}// end of main

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

What is meant by the phrase the first half of the age of oil?

Answered: 1 week ago

Question

What do you think the ePay Cardholder account is used for?

Answered: 1 week ago

Question

Which date of this dataset had the highest total purchase amount?

Answered: 1 week ago