Write the following function in C The function must not use

Write the following function in C++:

The function must not use any function templates from the algorithms portion of the Standard C++ library.

int divide(string a[], int n, string divider);

Rearrange the elements of the array so that all the elements whose value is < divider come before all the other elements, and all the elements whose value is > divider come after all the other elements. Return the position of the first element that, after the rearrangement, is not <divider, or n if there are none. Here\'s an example:

The function must write take at least two parameters: an array of strings, and the number of items the function will consider in the array, starting from the beginning.

Notwithstanding each function\'s behavior described below, all functions that return an int must return 1 if they are passed any bad arguments (e.g. a negative array size, or a position that would require looking at the contents of an element past the last element we\'re interested in). Unless otherwise noted, passing 0 to the function as the array size is not itself an error; it merely indicates the function should examine no elements of the array.

Solution

Hello Friend I tried to find solution of your mentioned problem .. In this user enter the string from keyboard and also enter the dividend from keyboard . after performing the required operation programe print the desied output.

please Check it and If you have any problem please asked ..

Thank you..

#include <iostream>
#include <string>
#include <sstream>
int len=0;
static int less=0;
int divide(std::string input,int len,std::string div)
{
   int j=0;
   static int k=0;
   for(int i=0;i<len;i++)
   {
       if(input[i]<div[j])
           {
               less++;
               for(;input[i]!=\' \';)
               {
                   i++;
               }  
           }
          
           else
           {
           for(;input[i]!=\' \';)
               {
                   i++;
               }  
           }
}
   return less;
}
int main()
{
   std::string input = \"\";
std::string divider = \"\";
   std::cout<<\"Please enter Array of String: \"<<std::endl;
getline(std::cin, input);
// std::cout << \"You entered: \" << input << std::endl;
for(int i=0; input[i]!=\'\\0\'; ++i)
{
   len++;
}
//std::cout << \"Length of string: \" << len<<std::endl;
//std::cout << \"Length Is: \" << len << std::endl;
    std::cout<<\"Please enter Divider: \";
getline(std::cin, divider);
//std::cout << \"You entered: \" << divider << std::endl;
int r = divide(input,len,divider);
std::cout<<\"total number of Word less Than Divider\"<<r<<std::endl;
   return 0;
}

Write the following function in C++: The function must not use any function templates from the algorithms portion of the Standard C++ library. int divide(string
Write the following function in C++: The function must not use any function templates from the algorithms portion of the Standard C++ library. int divide(string

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site