Practice of basic concepts

T

TwistedRoar

I'm quite new to C++, I started learning it a few days ago and, even though I do have some good studying material with me, I feel I lack a lot of practice...is there any online tutorial with activities or anything like that you could recommend me?
 
J

Jorgen Grahn

I'm quite new to C++, I started learning it a few days ago

Good choice, congratulations!
and, even
though I do have some good studying material with me, I feel I lack a
lot of practice...is there any online tutorial with activities or
anything like that you could recommend me?

What material do you have? Many books come with exercises. The ones
from Stroustrup's latest edition are available from his web site:

http://www.stroustrup.com/4th.html

Probably a good choice, even if you don't own the book.

If you prefer to write real programs, one idea is to implement parts
of the Unix dc(1) command (it's a RPN calculator).

/Jorgen
 
A

Alf P. Steinbach

Good choice, congratulations!


What material do you have? Many books come with exercises. The ones
from Stroustrup's latest edition are available from his web site:

http://www.stroustrup.com/4th.html

Probably a good choice, even if you don't own the book.

If you prefer to write real programs, one idea is to implement parts
of the Unix dc(1) command (it's a RPN calculator).

Or the hoc[1] (which I suspect was really short for "ad hoc", not as was
claimed "high order calculator") calculator, which was the main
multi-stage example in the old "The Unix Programming Environment" book
by Brian Kernighan and, I think it was, Robert Pike.

It was developed in C with typical Unix toolset, including yacc and lex
(IIRC).

I think it could be instructive if someone redid all that with C++ and
modern portable toolset (which is not necessarily better in any way).


Cheers,

- Alf

Notes:
[1] See e.g. <url:
http://en.wikipedia.org/wiki/Hoc_(programming_language)>
 
T

TwistedRoar

I had already heard a lot about that book, I'm going after it right now. Thank you!
 
A

Alf P. Steinbach

I'm quite new to C++, I started learning it a few days ago and, even though I do have
some good studying material with me, I feel I lack a lot of practice...is there any
online tutorial with activities or anything like that you could recommend me?

There is a problem with online instruction material for C++: it's
generally FLAWED.

Very embarrassingly this was so even for MIT's first open courseware
about C++. It was full of Herb Schildt-like stuff, someone's creatively
invented facts, explanations and rationales, not to mention the
practices. They redid the courseware a year or two later with fewer
outright errors and less dis-information and bad practices, but still
that was (and probably still is) rather ungood, as I recall.

I once wrote the at that time only known /correct/ C++ tutorial,
unfinished but still. At that time the FAQ, for the
alt.comp.lang.learn-c-c++ newsgroup I think it was, mentioned that there
were no reliable, sufficiently correct C++ tutorials to find online,
which maybe was a result of the 1998 standardization radically changing
many aspects of C++, including header names! My tutorial ended up, as
the only one, in the C++ FAQ, that is, Marshall Cline's FAQ Lite.

In recent years, I think we're talking 4-5 years here, the quality has
improved, while my tutorial has first moved (as e.g. start.no free
hosting was discontinued) and then disappeared. Today I think the main
basically OK and reasonably complete online tutorial is the one at

http://www.cplusplus.com/doc/

However, the cplusplus site as a reference site is not so good. Instead
most people prefer the newer cppreference site (better quality). If
you're programming for Windows then Microsoft's MSDN Library (online) is
also a nice reference resource, as long as one keeps in mind that it's
not always very clear on what is Microsoft and what is standard, and
also that nearly all Microsoft example code is abomination-like.

I know almost nothing about the tutorial(s) at cppreference.com, but
even if they are of better quality than cplusplus.com, as is probable,
at a glance it seems to be very unfinished. Anyway, you find that at

http://en.cppreference.com/book

Finally, if you prefer to learn with this newsgroup as support then I
and others can suggest concrete exercises and discuss your solution
attempts. :)

As an example, in order to learn the basics of stream i/o, which you'll
need for most all other exploration,

Exercise 1 (formatted stream output)
Display a 10*10 multiplication table, nicely formatted.

Then if you post the code here, then we can review it. It should be
small enough to post directly in-message.

Cheers & hth.,

- Alf
 
S

Stefan Ram

Alf P. Steinbach said:
Display a 10*10 multiplication table, nicely formatted.

::std::cout << /* not tested */
" | 0 1 2 3 4 5 6 7 8 9\n"
"--|----------------------------------------\n"
" 0| 0 0 0 0 0 0 0 0 0 0\n"
" 1| 0 1 2 3 4 5 6 7 8 9\n"
" 2| 0 2 4 6 8 10 12 14 16 18\n"
" 3| 0 3 6 9 12 15 18 21 24 27\n"
" 4| 0 4 8 12 16 20 24 28 32 36\n"
" 5| 0 5 10 15 20 25 30 35 40 45\n"
" 6| 0 6 12 18 24 30 36 42 48 54\n"
" 7| 0 7 14 21 28 35 42 49 56 63\n"
" 8| 0 8 16 24 32 40 48 56 64 72\n"
" 9| 0 9 18 27 36 45 54 63 72 81\n";
 
A

Alf P. Steinbach

::std::cout << /* not tested */
" | 0 1 2 3 4 5 6 7 8 9\n"
"--|----------------------------------------\n"
" 0| 0 0 0 0 0 0 0 0 0 0\n"
" 1| 0 1 2 3 4 5 6 7 8 9\n"
" 2| 0 2 4 6 8 10 12 14 16 18\n"
" 3| 0 3 6 9 12 15 18 21 24 27\n"
" 4| 0 4 8 12 16 20 24 28 32 36\n"
" 5| 0 5 10 15 20 25 30 35 40 45\n"
" 6| 0 6 12 18 24 30 36 42 48 54\n"
" 7| 0 7 14 21 28 35 42 49 56 63\n"
" 8| 0 8 16 24 32 40 48 56 64 72\n"
" 9| 0 9 18 27 36 45 54 63 72 81\n";

This illustrates the nice difference between learning and modern
education, I think.

Also it nicely illustrates how to (not) interpret requirements. The
small multiplication table's upper leftmost item is most often 1, and
lower right item is nearly always 100. A host of examples here:

https://www.google.com/search?q=10+by+10+multiplication+table&tbm=isch

If the OP (or some other learned) posted this code, I think group
members would applaud the creativity, but would then focus on whether
the choice helped to learn anything about formatted output, and how easy
it would be to adapt the solution to, say, showing a 20*20 table.


Cheers,

- Alf
 
J

Jorgen Grahn

Waste of time. Never fall for this shit.
Focus on what you want to do, then do exactly that.

Unless you follow that up with a proper explanation, I count that as
trying to mislead a newbie coming here for advice. A rotten thing to
do.

/Jorgen
 
D

David Brown

No, you are simply a lying imbecile. Trying to sell products? What a lame
thing to do on usenet. Shame

You do realise that Jorgen is not selling anything here? He is pointing
to some useful exercises available freely online, along with a book by
the guy that made the C++ language. (That does not necessarily imply
that Stroustrup writes the best C++ books - though it turns out that he
/does/ write good books.)

Focusing on a particular aspect of C++ could be a good idea - if the OP
wants to write games, then a book on "C++ for games development" might
be a good choice. But at the moment he is looking for general C++ help
and pointers, and that is what he has been getting here.
 
V

Victor Bazarov

[..]
::std::cout << /* not tested */
" | 0 1 2 3 4 5 6 7 8 9\n"
"--|----------------------------------------\n"
^^^^^
I'd use a plus instead of the vertical line here.
" 0| 0 0 0 0 0 0 0 0 0 0\n"
" 1| 0 1 2 3 4 5 6 7 8 9\n"
" 2| 0 2 4 6 8 10 12 14 16 18\n"
" 3| 0 3 6 9 12 15 18 21 24 27\n"
" 4| 0 4 8 12 16 20 24 28 32 36\n"
" 5| 0 5 10 15 20 25 30 35 40 45\n"
" 6| 0 6 12 18 24 30 36 42 48 54\n"
" 7| 0 7 14 21 28 35 42 49 56 63\n"
" 8| 0 8 16 24 32 40 48 56 64 72\n"
" 9| 0 9 18 27 36 45 54 63 72 81\n";

V
 
L

Luca Risolia

Stefan said:
::std::cout << /* not tested */
" | 0 1 2 3 4 5 6 7 8 9\n"
"--|----------------------------------------\n"
" 0| 0 0 0 0 0 0 0 0 0 0\n"
" 1| 0 1 2 3 4 5 6 7 8 9\n"
" 2| 0 2 4 6 8 10 12 14 16 18\n"
" 3| 0 3 6 9 12 15 18 21 24 27\n"
" 4| 0 4 8 12 16 20 24 28 32 36\n"
" 5| 0 5 10 15 20 25 30 35 40 45\n"
" 6| 0 6 12 18 24 30 36 42 48 54\n"
" 7| 0 7 14 21 28 35 42 49 56 63\n"
" 8| 0 8 16 24 32 40 48 56 64 72\n"
" 9| 0 9 18 27 36 45 54 63 72 81\n";

::std::cout << R"(
| 0 1 2 3 4 5 6 7 8 9
--+----------------------------------------
0| 0 0 0 0 0 0 0 0 0 0
1| 0 1 2 3 4 5 6 7 8 9
2| 0 2 4 6 8 0 12 14 16 18
3| 0 3 6 9 12 15 18 21 24 27
4| 0 4 8 12 16 20 24 28 32 36
5| 0 5 10 15 20 25 30 35 40 45
6| 0 6 12 18 24 30 36 42 48 54
7| 0 7 14 21 28 35 42 49 56 63
8| 0 8 16 24 32 40 48 56 64 72
9| 0 9 18 27 36 45 54 63 72 81
)";
 

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
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top