1. Write C++ code for a loop that simultaneously computes both the maximum and minimum element in a given vector.

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
ASSIGNMENT: Working with Vectors
Write a menu-driven program that will allow the user to run any of the following
questions. Please put the functions headers in h file and the functions definitions in a
.cpp file.
1. Write C++ code for a loop that simultaneously computes both the maximum and minimum
element in a given vector.
2. Write a function
double scalar_product(vector<double> a, vector<double> b)
that computes the scalar product of two vectors. The scalar product of two vectors
A[al, a2, a3) and B(bl, b2, b3} is another vector C given by
C{c1, c2, c3} where cl = al * b1, c2 = a2 + b2, c3 = a3 + b3.
3. Write a function that computes the alternating sum of all elements in a vector.
For example, if alternatingSum() is called with a vector containing
149 16 9 7 4 9 11
then it computes
1-4+9-16+9-7+4-9+11=-2
4. Write a procedure reverse that reverses the sequence of elements in a vector. For
example, if reverse is called with a vector containing
1 49 16 9 7 4 9 11
then the vector is changed
11 9 4 7 9 16 941
5. Write a function
vector<int> append(vector<int> a, vector<int> b)
That appends one vector after another. For example, if a is
149 16
and bis
then append returns the vector
9 7 4 9 11
149 16 9 7 4 9 11
6. Write a function
vector<int> merge(vector<int> a, vector<int> b)
that merges two arrays, alternating elements from both arrays. If one array is shorter than
1
Transcribed Image Text:ASSIGNMENT: Working with Vectors Write a menu-driven program that will allow the user to run any of the following questions. Please put the functions headers in h file and the functions definitions in a .cpp file. 1. Write C++ code for a loop that simultaneously computes both the maximum and minimum element in a given vector. 2. Write a function double scalar_product(vector<double> a, vector<double> b) that computes the scalar product of two vectors. The scalar product of two vectors A[al, a2, a3) and B(bl, b2, b3} is another vector C given by C{c1, c2, c3} where cl = al * b1, c2 = a2 + b2, c3 = a3 + b3. 3. Write a function that computes the alternating sum of all elements in a vector. For example, if alternatingSum() is called with a vector containing 149 16 9 7 4 9 11 then it computes 1-4+9-16+9-7+4-9+11=-2 4. Write a procedure reverse that reverses the sequence of elements in a vector. For example, if reverse is called with a vector containing 1 49 16 9 7 4 9 11 then the vector is changed 11 9 4 7 9 16 941 5. Write a function vector<int> append(vector<int> a, vector<int> b) That appends one vector after another. For example, if a is 149 16 and bis then append returns the vector 9 7 4 9 11 149 16 9 7 4 9 11 6. Write a function vector<int> merge(vector<int> a, vector<int> b) that merges two arrays, alternating elements from both arrays. If one array is shorter than 1
the other, then alternate as long as you can and then append the remaining elements
from the longer array. For example, if vector a is
149 16
and bis
then merge returns the array
9749 11
19 479 4 16 9 11
7. Write a function
vector<int> merge(vector<int> a, vector<int> b)
and bis
that merges two arrays, alternating elements from both arrays. If one array is shorter than
the other, then alternate as long as you can and then append the remaining elements
from the longer array. For example, if ais
149 16
4799 11
then merge_sorted returns the vector
then the vector is changed to
14 4 7 9 9 9 11 16
8. Write a function that removes duplicates from a vector. For example, if
remove_duplicates is called with a vector containing
149 16 9 7 4 9 11
149 16 7 11
9. Design a class Student or use one from a previous exercise. A student has a name and a
birthday. Make a vector
vector<Student> friends;
Read a set of names and birthdays in from a file or type them in, thus populating the
friends vector. Then print out all friends whose birthday falls in the current month.
2
Transcribed Image Text:the other, then alternate as long as you can and then append the remaining elements from the longer array. For example, if vector a is 149 16 and bis then merge returns the array 9749 11 19 479 4 16 9 11 7. Write a function vector<int> merge(vector<int> a, vector<int> b) and bis that merges two arrays, alternating elements from both arrays. If one array is shorter than the other, then alternate as long as you can and then append the remaining elements from the longer array. For example, if ais 149 16 4799 11 then merge_sorted returns the vector then the vector is changed to 14 4 7 9 9 9 11 16 8. Write a function that removes duplicates from a vector. For example, if remove_duplicates is called with a vector containing 149 16 9 7 4 9 11 149 16 7 11 9. Design a class Student or use one from a previous exercise. A student has a name and a birthday. Make a vector vector<Student> friends; Read a set of names and birthdays in from a file or type them in, thus populating the friends vector. Then print out all friends whose birthday falls in the current month. 2
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Functions
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.
Similar questions
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