Concept explainers
Solution to
Given the following header:
vector<string> split(string target, string delimiter); |
implement the function split so that it returns a vector of the strings in target that are separated by the string delimiter. For example:
split("10,20,30", ",") |
should return a vector with the strings "10", "20", and "30". Similarly,
split("do re mi fa so la ti do", " ") |
should return a vector with the strings "do", "re", "mi", "fa", "so", "la", "ti",
and "do".
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Database Concepts (8th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (8th Edition)
- This in C++.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_forward3. Use two vectors and make them into one. Use the following vectors:Vector#1 {1, 1, 5, -3, 0}Vector#2 {9,7,2}Return a vector containing 1, 1, 5, -3, 0, 9, 7, 2 (in that order)arrow_forward
- In c++ please Write the RemoveEvens() function, which receives a vector of integers as a parameter and returns a new vector of integers containing only the odd numbers from the original vector. The main program outputs values of the returned vector. Hint: If the original vector has even numbers, then the new vector will be smaller in length than the original vector and should have no blank element. Ex: If the vector passed to the RemoveEvens() function is [1, 2, 3, 4, 5, 6, 7, 8, 9], then the function returns and the program output is: [1, 3, 5, 7, 9] Ex: If the vector passed to the RemoveEvens() function is [1, 9, 3], hen the function returns and the program output is: [1, 9, 3] #include <iostream>#include <vector>using namespace std; vector<int> RemoveEvens(vector<int> nums) { /* Type your code here */} int main() { vector<int> input(9); input.at(0) = 1; input.at(1) = 2; input.at(2) = 3; input.at(3) = 4; input.at(4) = 5;…arrow_forwardcan you write in C++arrow_forwarduse c++ to Write a function template palindrome that takes a vector parameter and returns true or false according to whether the vector does or does not read the same forward as backward (e.g., a vector containing 1, 2, 3, 2, 1 is a palindrome, but a vector containing 1, 2, 3, 4 is not)arrow_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_forwardCreate a function set(v, i, j) that makes vector v contain the integers i through j. The original contents of v is deleted. The vector is left empty ifj < i. The argument v is a vector of integers.arrow_forward
- Produce the following program. Series 6.1 and 6.2arrow_forwardWrite a C ++ program that deletes positive integers from the vector and then writes the vector elements. in to do this; Write a function that takes an integer vector as a parameter and returns that vector after deleting its positive elements, and call the FunctionDelete positives (vector v) umw m B) Write a function that takes a vector as a parameter and prints the vector elements. Name this function printVektor (vector v). mw m m C) Write an appropriate amine method for the program. Define a vector containing negative and positive integers. Use the above function to show how to delete positive elements. Hint: the index positions of the elements are shifted after an item is mw m w w m v m w w mw m w deleted.arrow_forwardt. 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_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