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 (10th Edition)
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)
- c++ questionarrow_forwardProduce the following program.arrow_forwardComputer Science IN MATLAB Write a function CalFunc.m that can receive multiple math function as input arguments in the form of function handles. This function has one output argument which is the number of input arguments. This function creates a 1x100 vector with values between 0 and 10 as the x values, plots all function handles in a single plot with a proper legend. If the function is called without any input argument, the function will ask the user to enter an anonymous function for plotting. Your program should work as below:arrow_forward
- Write a function that returns the sum of all the elements in a specified column in a matrix using the following header:def sumColumn(m, columnIndex): Write a test program that reads a 3x4 matrix and displays the sum of each column.arrow_forwardUsing R software, create a function that returns the square root of a vector x. However, it uses a tryCatch statement so that if x has negative numbers, then it returns x as it is and issues a warning that x contains negative numbers. Otherwise, it returns the square root of xarrow_forwardThe whole question is included in the picture with the output please help...arrow_forward
- Function: randOps Input: (1xN double) A Vector of numbers (N>=2 and even) Output: (double) A number Function Description: Given a 1XN vector where N>=2 and even, perform the following random operations in the following order and return the resulting number 1. Extract all even indexed values into a vector and multiply them by 3 2. Extract all odd indexed values into a vector and divide by 5 3. Subtract the results of Step 2 from the results of Step 1. 4. Calculate the product of all the values contained in the vector result of Step 3. 5. Calculate the value needed to get the number from Step 4 to the next highest integer. 6. Round your result from Step 5 to 5 decimal places Hint(s): ▪ prod(), ceil() and round() may be Examples: ans1 = randOps ([2 5 4 1 3 4 2 1]) >>ans1 = 0.9632 ans2 = randOps ([3 6 2 5]) >> ans2 = 0.9600 ans3 = randOps ([30 40 10 20 50 80]) >> ans3 = 0arrow_forwardClass Average GPA Create a program that dynamically creates a vector whose size depends on the user's preference. Pass the vector to a CalculateAverage function that is responsible for computing the average GPA of the given vector of GPAs. CalculateAverage Implement a function called CalculateAverage in calculate_avg.cc that calculates the average of a double vector and returns that average. CalculateAverage() will have one parameter, a std::vector<double>& referring to the vector. When the vector size is greater than 0, the function should calculate the average GPA from the given vector of grades. However, when the size of the vector is 0, then the function should return 0. main The main function has mostly been built for you. It is your task to: Construct a double vector based on the inputted class size. Store each student's GPAs into the vector. Pass the vector as input to CalculateAverage to compute the average GPA of the class. Display the students' average GPA. Read…arrow_forwardC++arrow_forward
- Q/ write Matlab code that asks the user to enter several (elements (N) in Vector (V) -: uses (input )then ask the user to enter the values of elements of the vector: use (inputting) Note I. Write the code in the matlab 2. Complete the execution and take pictures of the execution 3. Туре (or copy and paste the code in the window for the problem one herearrow_forwardVector Arithmetics M A function named arithGym requires an input variable h, and returns three outputs: (1) column vector u, column vector z. and scalar variable count. The input variable h is a column vector of random numbers with values between 100 and 100. The length of h is also randomly chosen between 30 and 60 elements. Perform the following operations. 1. Calculate u with the same length as h that has evenly spaced values ranging from the minimum value in h to the maximum value in h. 2. Each element of column vector z is equal to the square of the corresponding element in h divided by 2 times the corresponding element in u 3. Compute the scalar variable count that counts the number of instances an element in z has a value less than the value of the corresponding element in h. Make sure to assign the results to the output variables as indicated Solve this problem using only vectorized code with no loops or if statements. Note the variable h is defined as a function input. Do not…arrow_forwardin c++ Write a function named “getLowest” that accepts a vector of pointers to Student objects. It will go through the list and return pointers to the Student or GradStudent with the lowest student ID and GPA. Please note that the vector contains pointers to either Student or GradStudent objects. Please show that you have tested with a vector of pointers of mixed Student and GradStudent objects (in the same vector) For example, if these students and grad students are in the list Student(2000, "John Smith", 4.0) GradStudent(3000,"Nancy Brown", 3.5, 2021) ; Student(1000, "Bob Johnson", 3.0) ; GradStudent(4000, "Tim Jackson", 2.0, 2020)) ; It will return pointers to these two objects: Lowest ID: ID(1000) NAME(Bob Johnson) GPA(3.00) Lowest GPA: ID(4000) NAME(Tim Jackson) GPA(2.00) GRADUATION-YEAR(2020)arrow_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