Concept explainers
Write a function named firstLast2 that takes as input a vector of integers. The function should return true if the vector starts or ends with the digit 2. Otherwise it should return false. Test your function with vectors of different length and with the digit 2 at the beginning of the vector, end of the vector, middle of the vector, and missing from the vector.
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Mechanics of Materials (10th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Modern Database Management
Java: An Introduction to Problem Solving and Programming (8th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
- Please do write a function that takes a vector of integers, an integer n representing the number of elements in that vector, and an integer b. Implement the sequential search algorithm to look for the integer b in the vector. The sequential search works as follows: you must look at all the elements of the vector until you find the b, from the first to the last. The function must return an integer representing how many elements the function tested until it found b. If it does not find the function, it must return 0. The name of the function must be called "busca_seq".arrow_forwardWrite a function that takes a vector of integers, an integer n representing the number of elements in that vector, and an integer b. Implement the sequential search algorithm to look for the integer b in the vector. The sequential search works as follows: you must look at all the elements of the vector until you find the b, from the first to the last. The function must return an integer representing how many elements the function tested until it found b. If it does not find the function, it must return 0. The name of the function must be called "busca_seq". int busca_seq(int vetor[], int n, int b) { //your code }arrow_forwardWrite a function that takes a vector of integers, an integer n representing the number of elements in that vector, and an integer b. Implement the sequential search algorithm to look for the integer b in the vector. The sequential search works as follows: you must look at all the elements of the vector until you find the b, from the first to the last. The function must return an integer representing how many elements the function tested until it found b. If it does not find the function, it must return 0. The name of the function must be called "busca_seq". Program in C.arrow_forward
- Im having trouble with this Lab for my computer science class. 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)arrow_forwardCreate a function append(v, a, n) that adds to the end of vector v a copy of all the elements of array a. For example, if v contains 1,2, 3, and a contains 4, 5, 6, then v will end up containing 1, 2, 3, 4, 5,6. The argument n is the size of the array. The argument v is a vector ofintegers and a is an array of integers. Write a test driver.arrow_forwardCode in C. Solve the code below. Write a function that takes a vector of integers, an integer n representing the number of elements in that vector, and an integer b. Implement the sequential search algorithm to look for the integer b in the vector. The sequential search works as follows: you must look at all the elements of the vector until you find the b, from the first to the last. The function must return an integer representing how many elements the function tested until it found b. If it does not find the function, it must return 0. The name of the function must be called "busca_seq". int busca_seq(int vetor[], int n, int b) { //your code } My Code #include<stdio.h> int busca_seq(int vetor[], int n, int b) { int i; for(i = 0; i < n; i++){ if(vetor[i] == b) return (i+1); } { int vet[5],n = 5,b,x; vet[0] = 1; vet[1] = 2; vet[2] = 3; vet[3] = 4; vet[4] = 5; scanf("%d",&b); x = busca_seq(vet,n,b); printf("%d",x); return 0; } }arrow_forward
- import numpy as np import torch import matplotlib.pyplot as plt Quiz Preparation Question 1. Write a function that generates a random tensor of n x n (n is the input). The output is the mean of the tensor. = 2, 4, 8, 16, ... 1024 and generate a vector 2. Write a code (for loop) that call that calls the function above with n = M(n). Plot the vector as a function of the log of n. 3. Given an n x m array write a code that replaces every element that is larger than 0.5 with 0.5. 4. The second derivative of a function can be approximated by the finite difference 1 ƒ"(x₂) = 73 (ƒ(£;+1) — 2ƒ(x;) + f(x;-1)) Given a vector f with values f = [f(xo),..., f(n) write a code that computes the approximation to f"(x) 5. The power method is a method to compute the largest eigenvalue of a matrix. Your google search is using this method every time you perform a google search. The method consists of the iteration Vj+1 = Av; || Avi|| where v; is a vector with chosen as a random vector, and A is the matrix…arrow_forwardWrite a function called manualMedian that accepts an vector of numeric values and returns the median of that vector. The function cannot use the built-in median function. If the vector is empty, the function should return the error string "Empty vectors have no median value." Function e C Reset I MATLAB Documentation 1 function [outputArg1, outputArg2] = untitled4(inputArg1, inputArg2) 2 %UNTITLED4 Summary of this function goes here 3 % Detailed explanation goes here 4 outputArg1 = inputArg1; 5 outputArg2 = inputArg2; 6 end Code to call your function e C Reset 1 testVec1=[27 16 26 31 24 26 12 34 18 26 34 11 17 23 18 4 30 18 2 40 2 testVec2=[25.6367 12.1810 33.0248 35.3475 37.8149 15.6318 32.0528 6.2845 25.0066 27.9594 3.4348 21.2472 35 3 testVec3=[17 -8 12 8 -14 8 -14 18 16 1 20 -14 11 14 12 -12 -2 -19 -6 4 testVec4=[1.3015 17.0282 15.9633 1.7933 16.0450 -17.9269 12.3441 -6.6038 -10.8527 12.8961 -6.0706 -13.3812 -18. 5 testVec5=[]; MATLAB Editor to write code to run your solution. To…arrow_forwardThi is matlabarrow_forward
- Define a function named GetWordFrequency that takes a vector of strings and a search word as parameters. Function GetWordFrequency() then returns the number of occurrences of the search word in the vector parameter (case insensitive). Then, write a main program that reads a list of words into a vector, calls function GetWordFrequency() repeatedly, and outputs the words in the vector with their frequencies. The input begins with an integer indicating the number of words that follow. Ex: If the input is: 5 hey Hi Mark hi mark the output is: hey 1 Hi 2 Mark 2 hi 2 mark 2 Hint: Use tolower() to set the first letter of each word to lowercase before comparing. The program must define and use the following function:int GetWordFrequency(vector<string> wordsList, string currWord)arrow_forwardDefine a function named GetWordFrequency that takes a vector of strings and a search word as parameters. Function GetWordFrequency() then returns the number of occurrences of the search word in the vector parameter (case insensitive). Then, write a main program that reads a list of words into a vector, calls function GetWordFrequency() repeatedly, and outputs the words in the vector with their frequencies. The input begins with an integer indicating the number of words that follow. Ex: If the input is: 5 hey Hi Mark hi mark the output is: hey 1 Hi 2 Mark 2 hi 2 mark 2 Hint: Use tolower() to set the first letter of each word to lowercase before comparing. The program must define and use the following function:int GetWordFrequency(vector<string> wordsList, string currWord) write code in c++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
- 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