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++ MPL
Additional Engineering Textbook Solutions
Database Concepts (7th Edition)
Problem Solving with C++ (9th Edition)
Artificial Intelligence: A Modern Approach
Concepts of Programming Languages (11th Edition)
Starting Out With Visual Basic (7th Edition)
Starting Out with Java: Early Objects (6th 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_forwardC++ 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_forward
- You 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_forwardIn 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
- 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
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning