WeixiangYan/CodeTransOcean huggingface dataset:
Task: Gray code


C++: #include <bitset>
#include <iostream>
#include <string>
#include <assert.h>

uint32_t gray_encode(uint32_t b)
{
    return b ^ (b >> 1);
}

uint32_t gray_decode(uint32_t g)
{
    for (uint32_t bit = 1U << 31; bit > 1; bit >>= 1)
    {
        if (g & bit) g ^= bit >> 1;
    }
    return g;
}

std::string to_binary(int value) 
{
    const std::bitset<32> bs(value);
    const std::string str(bs.to_string());
    const size_t pos(str.find('1'));
    return pos == std::string::npos ? "0" : str.substr(pos);
}

int main()
{
    std::cout << "Number\tBinary\tGray\tDecoded\n";
    for (uint32_t n = 0; n < 32; ++n)
    {
        uint32_t g = gray_encode(n);
        assert(gray_decode(g) == n);

        std::cout << n << "\t" << to_binary(n) << "\t" << to_binary(g) << "\t" << g << "\n";
    }
}







VB: Function Encoder(ByVal n)
    Encoder = n Xor (n \ 2)
End Function

Function Decoder(ByVal n)
    Dim g : g = 0
    Do While n > 0
       g = g Xor n
       n = n \ 2
    Loop
    Decoder = g
End Function


Function Dec2bin(ByVal n, ByVal length)
    Dim i, strbin : strbin = ""
    For i = 1 to 5
        strbin = (n Mod 2) & strbin
        n = n \ 2
    Next
    Dec2Bin = strbin
End Function

WScript.StdOut.WriteLine("Binary -> Gray Code -> Binary")
For i = 0 to 31
    encoded = Encoder(i)
    decoded = Decoder(encoded)
    WScript.StdOut.WriteLine(Dec2Bin(i, 5) & " -> " & Dec2Bin(encoded, 5) & " -> " & Dec2Bin(decoded, 5))
Next
Task: Playing cards


C++: #include <deque>
#include <algorithm>
#include <ostream>
#include <iterator>

namespace cards
{
class card
{
public:
    enum pip_type { two, three, four, five, six, seven, eight, nine, ten,
                    jack, queen, king, ace, pip_count };
    enum suite_type { hearts, spades, diamonds, clubs, suite_count };
    enum { unique_count = pip_count * suite_count };

    card(suite_type s, pip_type p): value(s + suite_count * p) {}

    explicit card(unsigned char v = 0): value(v) {}

    pip_type pip() { return pip_type(value / suite_count); }

    suite_type suite() { return suite_type(value % suite_count); }

private:
    unsigned char value;
};

const char* const pip_names[] =
    { "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
      "jack", "queen", "king", "ace" };

std::ostream& operator<<(std::ostream& os, card::pip_type pip)
{
    return os << pip_names[pip];
}

const char* const suite_names[] =
    { "hearts", "spades", "diamonds", "clubs" };

std::ostream& operator<<(std::ostream& os, card::suite_type suite)
{
    return os << suite_names[suite];
}

std::ostream& operator<<(std::ostream& os, card c)
{
    return os << c.pip() << " of " << c.suite();
}

class deck
{
public:
    deck()
    {
        for (int i = 0; i < card::unique_count; ++i) {
            cards.push_back(card(i));
        }
    }

    void shuffle() { std::random_shuffle(cards.begin(), cards.end()); }

    card deal() { card c = cards.front(); cards.pop_front(); return c; }

    typedef std::deque<card>::const_iterator const_iterator;
    const_iterator begin() const { return cards.cbegin(); }
    const_iterator end() const { return cards.cend(); }
private:
    std::deque<card> cards;
};

inline std::ostream& operator<<(std::ostream& os, const deck& d)
{
    std::copy(d.begin(), d.end(), std::ostream_iterator<card>(os, "\n"));
    return os;
}
}







VB: class playingcard
	dim suit
	dim pips
end class

class carddeck
	private suitnames
	private pipnames
	private cardno
	private deck(52)
	private nTop
	
	sub class_initialize
		dim suit
		dim pips
		suitnames = split("H,D,C,S",",")
		pipnames = split("A,2,3,4,5,6,7,8,9,10,J,Q,K",",")
		cardno = 0

		for suit = 1 to 4
			for pips = 1 to 13
				set deck(cardno) = new playingcard
				deck(cardno).suit = suitnames(suit-1)
				deck(cardno).pips = pipnames(pips-1)
				cardno = cardno + 1
			next
		next
		nTop = 0
	end sub
	
	public sub showdeck
		dim a
		redim a(51-nTop)
		for i = nTop to 51
			a(i) = deck(i).pips & deck(i).suit  
		next
		wscript.echo join( a, ", ")
	end sub
	
	public sub shuffle
		dim r
		randomize timer
		for i = nTop to 51
			r = int( rnd * ( 52 - nTop ) ) 
			if r <> i then
				objswap deck(i),deck(r)
			end if
		next
	end sub

	public function deal()
		set deal = deck( nTop )
		nTop = nTop + 1
	end function

	public property get cardsRemaining
		cardsRemaining = 52 - nTop
	end property
	
	private sub objswap(   a,   b )
		dim tmp
		set tmp = a
		set a = b
		set b = tmp
	end sub
end class
Task: Arrays


C++: #include <array>
#include <vector>


#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>


template <typename Array>
void demonstrate(Array& array)
{
  
  array[2] = "Three";  
                       
  array.at(1) = "Two"; 
                       
  
  
  std::reverse(begin(array), end(array));
  std::for_each(begin(array), end(array),
    [](typename Array::value_type const& element) 
    {
      std::cout << element << ' ';
    });
  
  std::cout << '\n';
}

int main()
{
  
  auto fixed_size_array = std::array<std::string, 3>{ "One", "Four", "Eight" };
  
  
  
  auto dynamic_array = std::vector<std::string>{ "One", "Four" };
  dynamic_array.push_back("Eight"); 
  
  
  demonstrate(fixed_size_array);
  demonstrate(dynamic_array);
}







VB: Option Base {0|1}
Task: Sierpinski carpet


C++: 


#include <cstdint>
#include <cstdlib>
#include <cstdio>

static constexpr int32_t bct_low_bits = 0x55555555;

static int32_t bct_decrement(int32_t v) {
    --v;            
    return v ^ (v & (v>>1) & bct_low_bits);     
}

int main (int argc, char *argv[])
{
    
    const int32_t n = (1 < argc) ? std::atoi(argv[1]) : 3;
    
    if (n < 0 || 9 < n) {                       
        std::printf("N out of range (use 0..9): %ld\n", long(n));
        return 1;
    }

    const int32_t size_bct = 1<<(n*2);          
    
    int32_t y = size_bct;
    do {                                        
        y = bct_decrement(y);                   
        int32_t x = size_bct;
        do {                                    
            x = bct_decrement(x);               
            
            std::putchar((x & y & bct_low_bits) ? ' ' : '#');
        } while (0 < x);
        std::putchar('\n');
    } while (0 < y);

    return 0;
}







VB: Const Order = 4

Function InCarpet(ByVal x As Integer, ByVal y As Integer)
    Do While x <> 0 And y <> 0
        If x Mod 3 = 1 And y Mod 3 = 1 Then
            InCarpet = " "
            Exit Function
        End If
        x = x \ 3
        y = y \ 3
    Loop
    InCarpet = "#"
End Function
 
Public Sub sierpinski_carpet()
    Dim i As Integer, j As Integer
    For i = 0 To 3 ^ Order - 1
        For j = 0 To 3 ^ Order - 1
            Debug.Print InCarpet(i, j);
        Next j
        Debug.Print
    Next i
End Sub
Task: Sorting algorithms_Bogosort


C++: #include <algorithm>
#include <iostream>
#include <iterator>
#include <random>

template <typename RandomAccessIterator, typename Predicate>
void bogo_sort(RandomAccessIterator begin, RandomAccessIterator end,
               Predicate p) {
  std::random_device rd;
  std::mt19937 generator(rd());
  while (!std::is_sorted(begin, end, p)) {
    std::shuffle(begin, end, generator);
  }
}

template <typename RandomAccessIterator>
void bogo_sort(RandomAccessIterator begin, RandomAccessIterator end) {
  bogo_sort(
      begin, end,
      std::less<
          typename std::iterator_traits<RandomAccessIterator>::value_type>());
}

int main() {
  int a[] = {100, 2, 56, 200, -52, 3, 99, 33, 177, -199};
  bogo_sort(std::begin(a), std::end(a));
  copy(std::begin(a), std::end(a), std::ostream_iterator<int>(std::cout, " "));
  std::cout << "\n";
}







VB: Private Function Knuth(a As Variant) As Variant
    Dim t As Variant, i As Integer
    If Not IsMissing(a) Then
        For i = UBound(a) To LBound(a) + 1 Step -1
            j = Int((UBound(a) - LBound(a) + 1) * Rnd + LBound(a))
            t = a(i)
            a(i) = a(j)
            a(j) = t
        Next i
    End If
    Knuth = a
End Function

Private Function inOrder(s As Variant)
    i = 2
    Do While i <= UBound(s)
         If s(i) < s(i - 1) Then
            inOrder = False
            Exit Function
        End If
        i = i + 1
    Loop
    inOrder = True
End Function
 
Private Function bogosort(ByVal s As Variant) As Variant
    Do While Not inOrder(s)
        Debug.Print Join(s, ", ")
        s = Knuth(s)
    Loop
    bogosort = s
End Function
 
Public Sub main()
    Debug.Print Join(bogosort(Knuth([{1,2,3,4,5,6}])), ", ")
End Sub
Task: Euler method


C++: #include <iomanip>
#include <iostream>

typedef double F(double,double);


void euler(F f, double y0, double a, double b, double h)
{
    double y = y0;
    for (double t = a; t < b; t += h)
    {
        std::cout << std::fixed << std::setprecision(3) << t << " " << y << "\n";
        y += h * f(t, y);
    }
    std::cout << "done\n";
}


double newtonCoolingLaw(double, double t)
{
    return -0.07 * (t - 20);
}

int main()
{
    euler(newtonCoolingLaw, 100, 0, 100,  2);
    euler(newtonCoolingLaw, 100, 0, 100,  5);
    euler(newtonCoolingLaw, 100, 0, 100, 10);
}







VB: Private Sub ivp_euler(f As String, y As Double, step As Integer, end_t As Integer)
    Dim t As Integer
    Debug.Print " Step "; step; ": ",
    Do While t <= end_t
        If t Mod 10 = 0 Then Debug.Print Format(y, "0.000"),
        y = y + step * Application.Run(f, y)
        t = t + step
    Loop
    Debug.Print
End Sub
 
Sub analytic()
    Debug.Print "    Time: ",
    For t = 0 To 100 Step 10
        Debug.Print " "; t,
    Next t
    Debug.Print
    Debug.Print "Analytic: ",
    For t = 0 To 100 Step 10
        Debug.Print Format(20 + 80 * Exp(-0.07 * t), "0.000"),
    Next t
    Debug.Print
End Sub
 
Private Function cooling(temp As Double) As Double
    cooling = -0.07 * (temp - 20)
End Function

Public Sub euler_method()
    Dim r_cooling As String
    r_cooling = "cooling"
    analytic
    ivp_euler r_cooling, 100, 2, 100
    ivp_euler r_cooling, 100, 5, 100
    ivp_euler r_cooling, 100, 10, 100
End Sub
Task: Sequence of non-squares


C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <boost/bind.hpp>
#include <iterator>

double nextNumber( double number ) {
   return number + floor( 0.5 + sqrt( number ) ) ;
}

int main( ) {
   std::vector<double> non_squares ;
   typedef std::vector<double>::iterator SVI ;
   non_squares.reserve( 1000000 ) ;   
   
   for ( double i = 1.0 ; i < 100001.0 ; i += 1 )
      non_squares.push_back( nextNumber( i ) ) ;  
   
   std::copy( non_squares.begin( ) , non_squares.begin( ) + 22 ,
	 std::ostream_iterator<double>(std::cout, " " ) ) ;     
   std::cout << '\n' ;
   
   SVI found = std::find_if ( non_squares.begin( ) , non_squares.end( ) ,
	 boost::bind( &floor, boost::bind( &sqrt, _1 ) ) == boost::bind( &sqrt, _1 ) ) ;
   if ( found != non_squares.end( ) ) {
      std::cout << "Found a square number in the sequence!\n" ;
      std::cout << "It is " << *found << " !\n" ;
   }
   else {
      std::cout << "Up to 1000000, found no square number in the sequence!\n" ;
   }
   return 0 ;
}







VB: Sub Main()
Dim i&, c&, j#, s$
Const N& = 1000000
   s = "values for n in the range 1 to 22 : "
   For i = 1 To 22
      s = s & ns(i) & ", "
   Next
   For i = 1 To N
      j = Sqr(ns(i))
      If j = CInt(j) Then c = c + 1
   Next
   
   Debug.Print s
   Debug.Print c & " squares less than " & N
End Sub

Private Function ns(l As Long) As Long
   ns = l + Int(1 / 2 + Sqr(l))
End Function
Task: Substring


C++: #include <iostream>
#include <string>

int main()
{
  std::string s = "0123456789";

  int const n = 3;
  int const m = 4;
  char const c = '2';
  std::string const sub = "456";

  std::cout << s.substr(n, m)<< "\n";
  std::cout << s.substr(n) << "\n";
  std::cout << s.substr(0, s.size()-1) << "\n";
  std::cout << s.substr(s.find(c), m) << "\n";
  std::cout << s.substr(s.find(sub), m) << "\n";
}







VB: Public Sub substring()





 
    sentence = "the last thing the man said was the"
    n = 10: m = 5
       
    
    Debug.Print Mid(sentence, n, 5)
    
    Debug.Print Right(sentence, Len(sentence) - n + 1)
    
    Debug.Print Left(sentence, Len(sentence) - 1)
    
    k = InStr(1, sentence, "m")
    Debug.Print Mid(sentence, k, 5)
    
    k = InStr(1, sentence, "aid")
    Debug.Print Mid(sentence, k, 5)
End Sub
Task: JortSort


C++: #include <algorithm>
#include <string>
#include <iostream>
#include <iterator> 

class jortSort {
public:
    template<class T>
    bool jort_sort( T* o, size_t s ) {
        T* n = copy_array( o, s );
        sort_array( n, s );
        bool r = false;

        if( n ) {
            r = check( o, n, s );
            delete [] n;
        }
        return r;
    }

private:
    template<class T>
    T* copy_array( T* o, size_t s ) {
        T* z = new T[s];
        memcpy( z, o, s * sizeof( T ) );
        
        return z;
    }
    template<class T>
    void sort_array( T* n, size_t s ) {
        std::sort( n, n + s );
    }
    template<class T>
    bool check( T* n, T* o, size_t s ) {
        for( size_t x = 0; x < s; x++ )
            if( n[x] != o[x] ) return false;
        return true;
    }
};

jortSort js;

template<class T>
void displayTest( T* o, size_t s ) {
    std::copy( o, o + s, std::ostream_iterator<T>( std::cout, " " ) );
    std::cout << ": -> The array is " << ( js.jort_sort( o, s ) ? "sorted!" : "not sorted!" ) << "\n\n";
}

int main( int argc, char* argv[] ) {
    const size_t s = 5;
    std::string oStr[] = { "5", "A", "D", "R", "S" };
    displayTest( oStr, s );
    std::swap( oStr[0], oStr[1] );
    displayTest( oStr, s );

    int oInt[] = { 1, 2, 3, 4, 5 };
    displayTest( oInt, s );
    std::swap( oInt[0], oInt[1] );
    displayTest( oInt, s );

    return 0;
}







VB: Function JortSort(s)
	JortSort = True
	arrPreSort = Split(s,",")
	Set arrSorted = CreateObject("System.Collections.ArrayList")
	
	For i = 0 To UBound(arrPreSort)
		arrSorted.Add(arrPreSort(i))
	Next
	arrSorted.Sort()
	
	For j = 0 To UBound(arrPreSort)
		If arrPreSort(j) <> arrSorted(j) Then
			JortSort = False
			Exit For
		End If
	Next
End Function

WScript.StdOut.Write JortSort("1,2,3,4,5")
WScript.StdOut.WriteLine
WScript.StdOut.Write JortSort("1,2,3,5,4")
WScript.StdOut.WriteLine
WScript.StdOut.Write JortSort("a,b,c")
WScript.StdOut.WriteLine
WScript.StdOut.Write JortSort("a,c,b")
Task: Leap year


C++: #include <iostream>

bool is_leap_year(int year) {
  return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}

int main() {
  for (auto year : {1900, 1994, 1996, 1997, 2000}) {
    std::cout << year << (is_leap_year(year) ? " is" : " is not") << " a leap year.\n";
  }
}







VB: Public Function Leap_year(year As Integer) As Boolean
    Leap_year = (Month(DateSerial(year, 2, 29)) = 2)
End Function
Task: Combinations and permutations


C++: #include <boost/multiprecision/gmp.hpp>
#include <iostream>

using namespace boost::multiprecision;

mpz_int p(uint n, uint p) {
    mpz_int r = 1;
    mpz_int k = n - p;
    while (n > k)
        r *= n--;
    return r;
}

mpz_int c(uint n, uint k) {
    mpz_int r = p(n, k);
    while (k)
        r /= k--;
    return r;
}

int main() {
    for (uint i = 1u; i < 12u; i++)
        std::cout << "P(12," << i << ") = " << p(12u, i) << std::endl;
    for (uint i = 10u; i < 60u; i += 10u)
        std::cout << "C(60," << i << ") = " << c(60u, i) << std::endl;

    return 0;
}







VB: 
dim i,j
Wscript.StdOut.WriteLine  "-- Long Integer - Permutations - from 1 to 12"
for i=1 to 12
	for j=1 to i
		Wscript.StdOut.Write "P(" & i & "," & j & ")=" & perm(i,j) & "  "
	next 
	Wscript.StdOut.WriteLine ""
next 
Wscript.StdOut.WriteLine  "-- Float integer - Combinations from 10 to 60"
for i=10 to 60 step 10
	for j=1 to i step i\5
		Wscript.StdOut.Write  "C(" & i & "," & j & ")=" & comb(i,j) & "  "
	next 
	Wscript.StdOut.WriteLine ""
next 
Wscript.StdOut.WriteLine  "-- Float integer - Permutations from 5000 to 15000"
for i=5000 to 15000 step 5000
	for j=10 to 70 step 20
		Wscript.StdOut.Write  "C(" & i & "," & j & ")=" & perm(i,j) & "  "
	next 
	Wscript.StdOut.WriteLine ""
next 
Wscript.StdOut.WriteLine  "-- Float integer - Combinations from 200 to 1000"
for i=200 to 1000 step 200
	for j=20 to 100 step 20
		Wscript.StdOut.Write "P(" & i & "," & j & ")=" & comb(i,j) & "  "
	next 
	Wscript.StdOut.WriteLine ""
next 

function perm(x,y)
	dim i,z
	z=1
	for i=x-y+1 to x
		z=z*i
	next 
	perm=z
end function 
	
function fact(x)
	dim i,z
	z=1
	for i=2 to x
		z=z*i
	next 
	fact=z
end function 

function comb(byval x,byval y)
	if y>x then 
		comb=0
	elseif x=y then 
		comb=1
	else
		if x-y<y then y=x-y
		comb=perm(x,y)/fact(y)
	end if
end function
Task: Sort numbers lexicographically


C++: #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

void lexicographical_sort(std::vector<int>& numbers) {
    std::vector<std::string> strings(numbers.size());
    std::transform(numbers.begin(), numbers.end(), strings.begin(),
                   [](int i) { return std::to_string(i); });
    std::sort(strings.begin(), strings.end());
    std::transform(strings.begin(), strings.end(), numbers.begin(),
                   [](const std::string& s) { return std::stoi(s); });
}

std::vector<int> lexicographically_sorted_vector(int n) {
    std::vector<int> numbers(n >= 1 ? n : 2 - n);
    std::iota(numbers.begin(), numbers.end(), std::min(1, n));
    lexicographical_sort(numbers);
    return numbers;
}

template <typename T>
void print_vector(std::ostream& out, const std::vector<T>& v) {
    out << '[';
    if (!v.empty()) {
        auto i = v.begin();
        out << *i++;
        for (; i != v.end(); ++i)
            out << ',' << *i;
    }
    out << "]\n";
}

int main(int argc, char** argv) {
    for (int i : { 0, 5, 13, 21, -22 }) {
        std::cout << i << ": ";
        print_vector(std::cout, lexicographically_sorted_vector(i));
    }
    return 0;
}







VB: Public Function sortlexicographically(N As Integer)
    Dim arrList As Object
    Set arrList = CreateObject("System.Collections.ArrayList")
    For i = 1 To N
        arrList.Add CStr(i)
    Next i
    arrList.Sort
    Dim item As Variant
    For Each item In arrList
        Debug.Print item & ", ";
    Next
End Function

Public Sub main()
    Call sortlexicographically(13)
End Sub
Task: Sorting algorithms_Shell sort


C++: #include <time.h>
#include <iostream>


using namespace std;


const int MAX = 126;
class shell
{
public:
    shell() 
    { _gap[0] = 1750; _gap[1] = 701; _gap[2] = 301; _gap[3] = 132; _gap[4] = 57; _gap[5] = 23; _gap[6] = 10; _gap[7] = 4; _gap[8] = 1; }

    void sort( int* a, int count )
    {
	_cnt = count;
	for( int x = 0; x < 9; x++ )
	    if( count > _gap[x] )
	    { _idx = x; break; }

	sortIt( a );
    }

private:	
    void sortIt( int* arr )
    {
	bool sorted = false;
	while( true )
	{
	    sorted = true;
	    int st = 0;
	    for( int x = _gap[_idx]; x < _cnt; x += _gap[_idx] )
	    {
		if( arr[st] > arr[x] )
		{ swap( arr[st], arr[x] ); sorted = false; }
		st = x;
	    }
	    if( ++_idx >= 8 ) _idx = 8;
	    if( sorted && _idx == 8 ) break;
	}
    }

    void swap( int& a, int& b ) { int t = a; a = b; b = t; }

    int _gap[9], _idx, _cnt;
};

int main( int argc, char* argv[] )
{
    srand( static_cast<unsigned int>( time( NULL ) ) ); int arr[MAX];
    for( int x = 0; x < MAX; x++ )
	arr[x] = rand() % MAX - rand() % MAX;

    cout << " Before: \n=========\n";
    for( int x = 0; x < 7; x++ )
    {
	for( int a = 0; a < 18; a++ )
	{ cout << arr[x * 18 + a] << " "; }
	cout << endl;
    }
    cout << endl; shell s; s.sort( arr, MAX );
	
    cout << " After: \n========\n";
    for( int x = 0; x < 7; x++ )
    {
	for( int a = 0; a < 18; a++ )
	{ cout << arr[x * 18 + a] << " "; }
	cout << endl;
    }
    cout << endl << endl; return system( "pause" );
}








VB: Sub arrShellSort(ByVal arrData As Variant)
  Dim lngHold, lngGap As Long
  Dim lngCount, lngMin, lngMax As Long
  Dim varItem As Variant
  
  lngMin = LBound(arrData)
  lngMax = UBound(arrData)
  lngGap = lngMin
  Do While (lngGap < lngMax)
    lngGap = 3 * lngGap + 1
  Loop
  Do While (lngGap > 1)
    lngGap = lngGap \ 3
    For lngCount = lngGap + lngMin To lngMax
      varItem = arrData(lngCount)
      lngHold = lngCount
      Do While ((arrData(lngHold - lngGap) > varItem))
        arrData(lngHold) = arrData(lngHold - lngGap)
        lngHold = lngHold - lngGap
        If (lngHold < lngMin + lngGap) Then Exit Do
      Loop
      arrData(lngHold) = varItem
    Next
  Loop
  arrShellSort = arrData
End Sub
Task: Increment a numerical string


C++: 
#include <cstdlib>
#include <string>
#include <sstream>


std::string s = "12345";

int i;
std::istringstream(s) >> i;
i++;



std::ostringstream oss;
if (oss << i) s = oss.str();







VB:     Dim s As String = "123"

    s = CStr(CInt("123") + 1)
    
    s = (CInt("123") + 1).ToString
Task: Strip a set of characters from a string


C++: #include <algorithm>
#include <iostream>
#include <string>

std::string stripchars(std::string str, const std::string &chars)
{
    str.erase(
        std::remove_if(str.begin(), str.end(), [&](char c){
            return chars.find(c) != std::string::npos;
        }),
        str.end()
    );
    return str;
}

int main()
{
    std::cout << stripchars("She was a soul stripper. She took my heart!", "aei") << '\n';
    return 0;
}







VB: Function StripChars(stString As String, stStripChars As String, Optional bSpace As Boolean)
Dim i As Integer, stReplace As String
    If bSpace = True Then
        stReplace = " "
    Else
        stReplace = ""
    End If
    For i = 1 To Len(stStripChars)
        stString = Replace(stString, Mid(stStripChars, i, 1), stReplace)
    Next i
    StripChars = stString
End Function
Task: Averages_Arithmetic mean


C++: #include <vector>

double mean(const std::vector<double>& numbers)
{
     if (numbers.size() == 0)
          return 0;

     double sum = 0;
     for (std::vector<double>::iterator i = numbers.begin(); i != numbers.end(); i++)
          sum += *i;
     return sum / numbers.size();
}







VB: Private Function mean(v() As Double, ByVal leng As Integer) As Variant
    Dim sum As Double, i As Integer
    sum = 0: i = 0
    For i = 0 To leng - 1
        sum = sum + vv
    Next i
    If leng = 0 Then
        mean = CVErr(xlErrDiv0)
    Else
        mean = sum / leng
    End If
End Function
Public Sub main()
    Dim v(4) As Double
    Dim i As Integer, leng As Integer
    v(0) = 1#
    v(1) = 2#
    v(2) = 2.178
    v(3) = 3#
    v(4) = 3.142
    For leng = 5 To 0 Step -1
        Debug.Print "mean[";
        For i = 0 To leng - 1
            Debug.Print IIf(i, "; " & v(i), "" & v(i));
        Next i
        Debug.Print "] = "; mean(v, leng)
    Next leng
End Sub