Rotate Left
The two sets of output below show the results of successive circular rotations of a vector. One set of data is for a vector of integers, and the second is for a vector of strings.
1 3 5 7
3 5 7 1
5 7 1 3
7 1 3 5
a b c d e
b c d e a
c d e a b
d e a b c
e a b c d
Write two template functions that can be used to rotate and output a vector of a generic type:
void rotateLeft(vector <T>& v)
void output(vector <T> v)
The first function performs a single circular left rotation on a vector, and the second prints out the vector passed to it as parameter. Write a suitable driver
Trending nowThis is a popular solution!
Chapter 16 Solutions
Starting Out with C++: Early Objects (9th Edition)
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Starting Out with Python (4th Edition)
Database Concepts (8th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Electric Circuits. (11th Edition)
- t. Given a string as a parameter to the function, return a square grid filled with all the characters of the string from left to right. Fill empty spaces in the grid with '_'. Sample Input: stringtogrid Output: {{s, t, r, i}, {n, g, t, o}, {g, r, i, d}, {_, _, _, _}} Complete the function: vector<vector<int> formGrid(string s){}arrow_forwardProduce the following program. Series 8arrow_forwardWrite a function that adds the contents of two vectors using the following header: template<typename T>void addvector(vector<T> &v1, vector<T> &v2) Write a test program that reads in 6 int values in two vector, adds both and displays the result.arrow_forward
- C++ Sort a vector Define a function named SortVector that takes a vector of integers as a parameter. Function SortVector() modifies the vector parameter by sorting the elements in descending order (highest to lowest). Then write a main program that reads a list of integers from input, stores the integers in a vector, calls SortVector(), and outputs the sorted vector. The first input integer indicates how many numbers are in the list. Ex: If the input is: 5 10 4 39 12 2 the output is: 39,12,10,4,2, For coding simplicity, follow every output value by a comma, including the last one. Your program must define and call the following function:void SortVector(vector<int>& myVec) #include <iostream>#include <vector>using namespace std; /* Define your function here */ int main() { /* Type your code here */ return 0;} Enter program input - 5 10 4 39 12 2arrow_forwardYou may insert an element into an arbitrary position inside a vector using an iterator. Write a function, insert(vector, value) which inserts value into its sorted position inside the vector. The function returns the vector after it is modified. #include <vector>using namespace std; vector<int>& insert(vector<int>& v, int value){ ................ return v; }arrow_forward1. Write a function that returns a vector. The function will accept names (full names: Given, Middle, & Family name for each) for the vector string to be returned as many as the user will enter. The enter key will just be the data required to end the input process. 2. Write a function that returns a vector with given names. The function will extract the given name from all the elements of the vector specified as parameter. The extracted given names will be assigned to another vector that is to be returned. 3. Write a function with vector as it's parameter. The function will display all elements of the vector specified. 4. Write a program for using all the functions created from number 1 to 3 above.arrow_forward
- In PYTHON Write a function that prints all elements of a vector from the first element up to the first occurrence of the element having value equal to a provide number Use while loop(s) Function Name:print_up_to_value Parameters:a_vector,a_value Return:none Example: Input: my_vector = [5,6,7,8,9,5,6,7,8,9] Invokefunction:print_up_to_value(my_vector,7) Output:[5,6,7]arrow_forward- Write a function that takes a vector and returns the maximum element. - Same as above, but without using the "max" function.arrow_forwardin c++ pleasearrow_forward
- In PYTHON Write a function that prints multiple times a vector from its first element up to the next occurrence of an element having value equal to a provide number Each print stops at the i-th occurrence of the provided number Use while loop(s) Function Name:vec_multi_print_to_number Parameters:a_vector,a_value Return:none Example: Input:my_vector=[5,6,7,8,9,5,6,7,8,9] Invokefunction:print_up_to_value(my_vector,7) Output:[5,6,7,8,9,5,6,7]arrow_forwardWrite a function that removes the duplicate elements from a vector using the following header: template<typename T>void removeDuplicate(vector<T>& v) Write a test program that prompts the user to enter 10 integers to a vector and displays the distinct integers.arrow_forwardC++ languagearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education