Is C++ any better than BASIC?

G

Gerry Lintonice

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++?
 
J

Jim Langston

Gerry Lintonice said:
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++?

Better is subjective, especially in this case when you didn't ask better for
anything in particular.

Languages are tools. If I'm working on an IBM AS/400 and I want to do a
quick report, I'm going to use RPG not C++.

Personally, I would always use C++ instead of any flavor of BASIC if I'm
given the choice, but there may be cases where BASIC is preferred
(especially on some platforms that it may be my only choice).
 
H

hacker++

Gerry said:
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 << '\n';
}

return 0;
}
 
D

Dave Rahardja

I wonder if C++ is any better than a common BASIC, for example GW
BASIC.

Define "better".

What can you do with C++ that BASIC can't do?
Plenty.


C++ seems so incredibly complicated, even more complicated than
Assembler.Why bother with C++?

Because each language represents a cost/benefit tradeoff. C++ has proven to be
quite profitable to learn and use so far.

-dr
 
W

Walter Bright

hacker++ said:
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 :)

Just for fun I did the same with D, a little shorter and simpler:

import std.cstream;
import std.stdio;

alias int myint;

void main()
{
writefln("Enter 10 values:");
myint[] vec;
for (int i = 0; i < 10; i++)
{ myint j;
din.readf(&j);
vec ~= j;
}
vec.sort;
writefln("The sorted list is: ", vec);
}

-Walter
www.digitalmars.com C, C++, D compilers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top