Write a function, named series_of_letters, that takes a reference to a vector of chars and returns nothing. The function should modify the vector to contain a series of letters increasing from the smallest letter (by ASCII value) in the vector. Note, the vector should not change in size, and the initial contents of the vector (excepting the smallest letter) do not matter.

Respuesta :

Answer:

Follows are the code to this question:

#include <iostream>//defining header file

#include <vector>//defining header file

#include <algorithm>//defining header file

#include <iterator>//defining header file

using namespace std;//use namespace

void series_of_letters(vector<char> &d)//defining a method series_of_letters that accept a vector array  

{

char f = *min_element(d.begin(), d.end()); //defining a character array  that holds parameter address

   int k = 0;//defining integer vaiable  

   std::transform(d.begin(), d.end(), d.begin(), [&f, &k](char c) -> char//use namespace that uses transform method  

   {

       return (char)(f + k++);//return transform values

   });  

}

int main() //defining main method

{

   vector<char> x{ 'h', 'a', 'd' };//defining vector array x that holds character value

   series_of_letters(x);//calling series_of_letters method

   std::copy(x.begin(),x.end(),//use namespace to copy and print values

           std::ostream_iterator<char>(std::cout, " "));//print values

}

Output:

a b c

Explanation:

In the above code, a method "series_of_letters" is defined that accepts a vector array in its parameter, it uses a variable "d" that is a reference type, inside the method a char variable "f" is defined that uses the "min_element" method for holds ita value and use the transform method to convert its value.

Inside the main method, a vector array "x" is defined that holds character value, which is passed into the "series_of_letters" to call the method and it also uses the namespace to print its values.

ACCESS MORE
EDU ACCESS
Universidad de Mexico