Gerry Lintonice wrote:
I wonder if C++ is any better than a common BASIC, for example GW
BASIC.
What can you do with C++ that BASIC can't do?
C++ seems so incredibly complicated, even more complicated than
Assembler.Why bother with C++?
Well depends on what you want to do...
Generic and type independent programming for instance:
This is a simple _complete_ program in c++. It can accept 10 values of
ANY type (including user defined types, provided certain conditions are
met) and sort them. Try this in BASIC/Assembler!! And I haven't even
mentioned polymorphism yet :)
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std; // not recommended, only for illustration
typedef int mytype; // substitute 'int' with almost any type
int main()
{
vector<mytype> vec;
cout << "Enter 10 values:\n";
for(int i = 0; i < 10; ++i)
{
mytype num;
cin >> num;
vec.push_back(num);
}
cout << "The sorted list is :\n";
sort(vec.begin(), vec.end());
for(int i = 0; i < 10; ++i)
{
cout << vec[i] << '\n';
}
return 0;
}