Borland C++ Builder

Implementation of programming language C++

Borland C++ Builder is an IDE created by Borland Software Corporation. C++ Builder 2007 is incorporated in CodeGear RAD Studio 2007.

Latest version (C++ Builder 2010) key features:

  • supports rapid application development methodology;
  • includes drag-and-drop WYSIWYG graphical user interface builder;
  • supports the draft of C++0x standard;
  • includes Boost and TR1 libraries;
  • incorporates Borland Visual Component Library (VCL) and Component Library for Cross Platform (CLX);
  • has built-in support for major databases and touch and gesture processing.

Examples:

Hello, World!:

Example for versions Borland C++ Builder 6, Microsoft Visual C++ 6, Microsoft Visual C++ 9 (2008), g++ 3.4.5
#include <iostream>

int main(void)
{
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Factorial:

Example for versions Borland C++ Builder 6, Microsoft Visual C++ 6, Microsoft Visual C++ 9 (2008), g++ 3.4.5

This example uses recursive factorial definition.

#include "stdio.h"

__int64 factorial(__int64 n)
{
	return ( n==0 ? 1 : n*factorial(n-1) );
}

int main(int argc, char* argv[])
{
	for (int n=0; n<=16; n++)
		printf( "%d! = %I64d\n", n, factorial(n) );
	return 0;
}

Factorial:

Example for versions Borland C++ Builder 6, g++ 3.4.5

This example uses recursive factorial definition.

#include <iostream>

unsigned long long factorial(unsigned long long n)
{
	if (n == 0) 
		return 1;
	else 
		return n * factorial (n - 1);
}

int main(void)
{
    for (int n = 0; n <= 16; n++) 
        std::cout << n << "! = " << factorial(n) << std::endl;
    return 0;
}

Fibonacci numbers:

Example for versions Borland C++ Builder 6, Microsoft Visual C++ 6, Microsoft Visual C++ 9 (2008), g++ 3.4.5

This example uses recursive definition of Fibonacci numbers.

#include <iostream>

int fibonacci(int n)
{
    return ( n<=2 ? 1 : fibonacci(n-1) + fibonacci(n-2) );
}

int main(void)
{
    for (int n=1; n<=16; n++)
        std::cout << fibonacci(n) << ", ";
    std::cout << "..." << std::endl;
    return 0;
}

Quadratic equation:

Example for versions Borland C++ Builder 6

This example uses a template class complex<>, provided in STL. All calculations are done in complex numbers, because this allows not to worry about the sign of discriminant and representation of the roots.

Operator >> of complex is overloaded so that it can recognize several formats of the number, so the input constants are read not as integers but as complex numbers without imaginary part. This implementation allows to solve quadratic equations not only with integer coefficients but also with floating-point and even complex ones.

Operator << is also overloaded to print the number x as (x.real(),x.imag()), so to print roots without imaginary part as a single double, function print was created.

#include <iostream>
#include <complex>
#include <math>

using namespace std;

void print(int ind, complex<double> x)
{   cout << "x" << ind << " = ";
    if (fabs(x.imag()) < 1E-6)
        cout << x.real() << endl;
    else cout << x << endl;
}

void main()
{   complex<double> A, B, C, D, x1, x2;
    cout << "A = ";
    cin >> A;
    if (abs(A)<1E-3)
    {   cout << "Not a quadratic equation" << endl;
        return;
    }
    cout << "B = ";
    cin >> B;
    cout << "C = ";
    cin >> C;

    A *= 2;
    D = B*B-A*C*2.0;
    if (abs(D)<1E-3)
        cout << "x = " << (-B/A).real();
    else
    {   print(1, (-B+sqrt(D))/A);
        print(2, (-B-sqrt(D))/A);
    }
}