I am experienced in BASIC programming and would love to learn C++ - this is my second attempt to do so.
I have written complicated BASIC programs of many thousands of lines using BBC BASIC and can plan a programme qite well, breaking it down to procedures that are easy to follow for instance.
What I am having trouble with is understanding how, if I plan a programme and flowchart it, how to translate that into C++ logic. I can write short programmmes in C++ which can take input, evaluate expressions etc and output results, but that is all in one 'main' procedure.
For instance, and I know this might sound really naff, but is it as easy as putting each procedure or sub-routine into a pair of curly braces and somehow calling that by a name that you can then reference from the main procedure.
Hopefully that gives an idea of what I am thinking and my question is, is there a book which explains this for me?
Or maybe am I trying to run before I can walk, if I persevere with 'Exploring C++' for instance will it become clearer to me.
For instance, and I know this might sound really naff, but is it as easy as putting each procedure or sub-routine into a pair of curly braces and somehow calling that by a name that you can then reference from the main procedure.
Yes. Notice that in C++ (and most other languages) there are no "sub-routines". Everything is a procedure, usually called a function. Defining and using functions is as easy as this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
int square(int n)
{
return n * n;
}
void print_int(int n) /* the void type denotes a function that
doesn't return a value ("sub-routine") */
{
std::cout << n << std::endl;
}
int main()
{
int n = 4;
print_int(square n);
}
I'm not sure, possibly if they are what I would call procedures and sub-routines. I have looked at some listings in C++ and can't see a logic in them or even follow the processing - maybe you are saying my last line is true and I should just persevere with the book.
Also maybe I am approaching it in the wrong way and should forget everything I know about writing a BASIC programme.
Also maybe I am approaching it in the wrong way and should forget everything I know about writing a BASIC programme.
You would not be the first to suggest such a thing.
The late great Edsger Dijkstra wrote:
It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.
As I understand Dijkstra's commentary, he posits that the nature of the BASIC programming language is such that the mental methods and understanding of programming that are constructed within the student's mind are such that they will struggle to adapt and indeed understand when confronted with languages adhering to other programming language concepts|philosophies.
I started with C++ then learned some other languages. Of course because of such I'm pretty bias when it comes to other language syntax.
I go into python or Visual or C# and every second I can't use C++ syntax I start raging at the language.
Surprising fact, my institution required us to take Visual Basic before C++, which I skipped via recommendation. Thing is good programmers struggle because they try to understand C++ using the view they understood from Visual Basic.
I go into python or Visual or C# and every second I can't use C++ syntax I start raging at the language.
Python, really? Since it's currently my favorite language I might be biased too, but one of the things I love about Python is that the language just gets out of the way. I even came to like significant indentation. It looks so much like pseudo code that one time I really thought I was looking at pseudo code instead of Python. Also, I find Python code just beautiful to look at. It's just so clean and expressive.
Oh I didn't mean I hate the language. The language and the way Python works is great. It really is a get small tasks done language. I love it. But since C++ is just the first language I learned and use consistently I constantly type semicolons and brackets at the end of lines.
I'm also so use to C++ ignoring whitespace in code that having to have proper indentation for a language drives me a little up the wall. Otherwise the language is great and I use it as a quick calculator and write small test programs in it.
I started with BASIC (TRS-80 Level 2 BASIC ) as well. The transition from BASIC (no scoped variables -- every variable was global) to C and then to C++ (over a decade or more) was almost certainly much easier than trying to go from BASIC to (modern) C++ in one hop as you are attempting. One's brain has to completely rethink how to break down problems and how to write programs.
Grey Wolf pointed you to the right place. Start with the tutorial.
Additionally, flowcharts are only suitable for a small subset of problems that can be addressed with a language like C++. I would go so far as to say that relying solely on flowcharts to help solve problems will get in the way of writing C++ programs. They are only suitable for designing procedural programs. One has to start using the various forms of UML to design proper OO programs, where scope and ownership are important.
The criticisms in the Wikipedia article are all well-deserved, but UML has become the lingua franca of software design the way flowcharts were 20+ years ago.
Having started this thread I would like to say that the tutorial on this site which I have now downloaded is streets ahead of anything I have seen before with regard to starting out learning C++.
It explains things in a way I can understand and has already given me new hope that I may be able to learn this language as well as explaining some of my most basic questions.
I started with BASIC (TRS-80 Level 2 BASIC ) as well. The transition from BASIC (no scoped variables -- every variable was global)
Have to take you to task there - you can define local variables within procedures which are then local to that procedure only and definitely not global
It has been a very long time since I wrote anything in that language. But I do know that there were no procedures in TRS-80 Level 2 BASIC. And it's not just me that remembers the language that way.
there were no named subroutines (like functions in C++), and all variables were global.
No apology necessary. I had no idea BASIC was being versioned. I knew of GW-BASIC and then various versions of Visual Basic, which seemed to me to have little relation to the original language. I had never heard of BBC BASIC.