a)Write a C++ recursive function that takes an array of words and returns an array that contains all the words capitalized. b)Write a linear search C++ program that searches for a number in a two dimensional array.
a)Write a C++ recursive function that takes an array of words and returns an array that contains all the words capitalized.
b)Write a linear search C++ program that searches for a number in a two dimensional array.
Answer a:
#include<bits/stdc++.h>
using namespace std;
// c++ function taht take words array and convert it into Capitalize word
vector<string> fun(vector<string> arr)
{
//length of array
int n = arr.size();
//iterate over array
for(int i=0;i<n;i++)
{
//function to convert each word into uppercase
transform(arr[i].begin(), arr[i].end(), arr[i].begin(), ::toupper);
}
//return new array
return arr;
}
int main(){
//array of words
vector<string> arr{"absd","adsg","sdgs","sgsgf"};
//function call
vector<string> new_arr = fun(arr);
//print each word
for(int i=0;i<arr.size();i++)
{
cout<<arr[i]<<" = ";
cout<<new_arr[i]<<endl;
}
return 0;
}
OUTPUT SCREENSHOT:
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images