Lab8: Vector merge CS-102 2020 Fall Semester E6.20 (Big C++ Chapter 6 – Arrays & Vector Exercise E6.20) Write a function vector merge_sorted(vector a, vector b) that merges two sorted vectors, producing a new sorted vector. Keep an index into each vector, indicating how much of it has been processed already. Each time, append the smallest unprocessed element from either vector, then advance the index. For example, if a is 0 1 49 16 25 36 and b is 4 5 8 13 20 then merge_sorted returns the vector 0 1 4 4 5 89 13 16 20 25 36

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The programming language is C++.

help me write a program.

Lab8: Vector merge
CS-102
2020 Fall Semester
E6.20 (Big C++ Chapter 6 - Arrays & Vector Exercise E6.20)
Write a function
vector<int> merge_sorted(vector<init> a, vector<int> b)
that merges two sorted vectors, producing a new sorted vector. Keep an index into each vector,
indicating how much of it has been processed already. Each time, append the smallest
unprocessed element from either vector, then advance the index.
For example, if a is
0 1 49 16 25 36
and b is
4 5 8 13 20
then merge_sorted returns the vector
0 1 4 4 5 8 9 13 16 20 25 36
Test cases:
o Assign int value 0 1 4 9 16 25 36 to vector <int> a (7) using a for loop where the
value is the product of the index. For example:
For ( index = 0; index < a.size (); index ++)
a[index] = index * index;
cout << a[index] << “ “;
}
O Assign int value 4 5 8 13 20 to vector <int> b (4) using a for loop where the value
is the the current for loop index * index + 4 (see example above). For example, if
index is 0:0 * 0 + 4 = 4; if index is 1 then 1 * 1+ 4 = 5; if index is 2 then 2 * 2 + 4 = 8
o After you call the function:
vector < int > c = merge_sorted (a, b);
vector c would have the following value:
0 14 4 5 8 9 13 16 20 25 36
Transcribed Image Text:Lab8: Vector merge CS-102 2020 Fall Semester E6.20 (Big C++ Chapter 6 - Arrays & Vector Exercise E6.20) Write a function vector<int> merge_sorted(vector<init> a, vector<int> b) that merges two sorted vectors, producing a new sorted vector. Keep an index into each vector, indicating how much of it has been processed already. Each time, append the smallest unprocessed element from either vector, then advance the index. For example, if a is 0 1 49 16 25 36 and b is 4 5 8 13 20 then merge_sorted returns the vector 0 1 4 4 5 8 9 13 16 20 25 36 Test cases: o Assign int value 0 1 4 9 16 25 36 to vector <int> a (7) using a for loop where the value is the product of the index. For example: For ( index = 0; index < a.size (); index ++) a[index] = index * index; cout << a[index] << “ “; } O Assign int value 4 5 8 13 20 to vector <int> b (4) using a for loop where the value is the the current for loop index * index + 4 (see example above). For example, if index is 0:0 * 0 + 4 = 4; if index is 1 then 1 * 1+ 4 = 5; if index is 2 then 2 * 2 + 4 = 8 o After you call the function: vector < int > c = merge_sorted (a, b); vector c would have the following value: 0 14 4 5 8 9 13 16 20 25 36
Your program output should be similar to below.
Vector a:
e 1 4 9 16 25 36
Vector b:
4 5 8 13 20
Result of interleaved merge of sorted a and b is
e 1 4 4 5 8 9 13 16 20 25 36
Lab Submission: See the lab submission requirements published in canvas.
To submit your assignment in canvas, you must submit TWO files (one pdf
and one zip) as follows:
1. Attach pdt file which contains source codes you have written and program output
screenshot so I can easily read in one file. You can use a word editor to place all the required
programs and screenshots, and then use 'Print' to 'Microsoft Print to PDF' to save to a pdf file
Print
Copies
Print
Printer
Microsoft Print to PDF
Ready
The pdf file MUST have the following sections (1. Program Description, 2. Program Source
Code and 3. Program Output).
1. Program Description
• brief description of the purpose of the program and
an explanation of what your software does and what problem it solves
2. Program Source Code
Transcribed Image Text:Your program output should be similar to below. Vector a: e 1 4 9 16 25 36 Vector b: 4 5 8 13 20 Result of interleaved merge of sorted a and b is e 1 4 4 5 8 9 13 16 20 25 36 Lab Submission: See the lab submission requirements published in canvas. To submit your assignment in canvas, you must submit TWO files (one pdf and one zip) as follows: 1. Attach pdt file which contains source codes you have written and program output screenshot so I can easily read in one file. You can use a word editor to place all the required programs and screenshots, and then use 'Print' to 'Microsoft Print to PDF' to save to a pdf file Print Copies Print Printer Microsoft Print to PDF Ready The pdf file MUST have the following sections (1. Program Description, 2. Program Source Code and 3. Program Output). 1. Program Description • brief description of the purpose of the program and an explanation of what your software does and what problem it solves 2. Program Source Code
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Introduction to computer system
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education