newsgroups-index (beta)

Current group: comp.programming

Self-studying C++

Self-studying C++  
Misery
 Re: Self-studying C++  
Chris Williams
 Re: Self-studying C++  
Alf P. Steinbach
 Re: Self-studying C++  
CBFalconer
 Re: Self-studying C++  
Gianni Mariani
 Re: Self-studying C++  
Percival
From:Misery
Subject:Self-studying C++
Date:23 Jan 2005 05:38:43 -0800
Hi!
I've been studying the VERY basics of C++ by myself now for a week or
so, and
I can make these simple programs that calculate stuff etc., so now I'm
wondering,
how can I continue my studies?
What should I try to study next? What's important and what's not?
And where can I get the proper material for "this-and-that"?

I really would like to learn graphics coding some day (I know it's not
happening in the next months, or next years!), but if someone could
give me some reference
about where to start/continue, I really would appreciate it.

Thanks!
From:Chris Williams
Subject:Re: Self-studying C++
Date:24 Jan 2005 00:00:21 -0800
Not certain what language/experience level you are coming from. For
instance, what do you make of the below program:

class Wall {
public:
int left, top, right, bottom;

Wall(int x, int y, int width, int height) {
myLeft = x;
myTop = y;
myRight = x + width - 1; //if leftmost pixel is 0 and width is 4
pixels, then the rightmost pixel is 3 not 4!
myBottom = top + height - 1;
}

bool hit(int x, int y, int width, int height) {
int testRight = x + width - 1;
int testBottom = y + height - 1;

if (
((x >= myLeft && x <= myRight) || (testRight >= myLeft &&
testRight <= myRight)) /* within horizontal */
&&
((y >= myTop && y <= myBottom) || (testBottom >= myTop &&
testBottom <= myBottom)) /* within vertical */
) {
return true;
}

return false;
}
};

class Map {
public:
#define MAX_WALLS
Wall myWalls[MAX_WALLS];
int wallCount;

public:
Map() : wallCount(0) {}

void addWall(int x, int y, int width, int height) {
if (wallCount < (MAX_WALLS - 1)) {
myWalls[wallCount] = Wall(x, y, width, height);
++wallCount;
}
}
};

class Ball {
private:
int myX, myY, myWidth, myHeight;
int myHDiff, myVDiff;

Map* myMap;

public:
Ball(Map* map, int x, int y) {
myMap = map;
myX = x;
myY = y;

myWidth = 10; //defaults
myHeight = 10;

myHDiff = 0;
myVDiff = 0;
}

void update() {
int tempX = myX + myHDiff;
int tempY = myY + myVDiff;

bool wallHit = false;
for (int L = 0; L < map->wallCount; L++) {
Wall* wall = map->wall[L]; //spare ourselves some carpal
tunnel

if (wall.hit(tempX, tempY, myWidth, myHeight)) { /*we will
hit a wall! */
wallHit = true;

/* do various arcane math to determine which side of the
wall we hit and where */
/* flip myHDiff and myVDiff appropriately */
/* move myX and myY to where we would have been after
bouncing off the wall */
}
}

if (!wallHit) {
myX = tempX;
myY = tempY;
}
}

void setSize(int width, int height) {
myWidth = width;
myHeight = height;
}

void setMovement(int hDiff, int vDiff) {
myHDiff = hDiff;
myVDiff = vDiff;
}
};

int main(void) {
Map myMap;
myMap.addWall(0, 0, 10, 100);
myMap.addWall(10, 0, 100, 10);
myMap.addWall(10, 90, 100, 10);
myMap.addWall(90, 10, 10, 80);

Ball b(&myMap, 45, 45);
b->setMovement(3, 5);

while (1) {
b->update();
}

return 0;
}

/* ^ just wrote that in, so good chances for lots of little errors that
will prevent compile */

So what did I just do and why would one write code like this? If you
got that part down already, then I will need to come up with more
examples of potential problem areas.

-Chris
From:Alf P. Steinbach
Subject:Re: Self-studying C++
Date:Sun, 23 Jan 2005 14:07:23 GMT
* Misery:
> I've been studying the VERY basics of C++ by myself now for a week or
> so, and
> I can make these simple programs that calculate stuff etc., so now I'm
> wondering,
> how can I continue my studies?
> What should I try to study next? What's important and what's not?
> And where can I get the proper material for "this-and-that"?
>
> I really would like to learn graphics coding some day (I know it's not
> happening in the next months, or next years!), but if someone could
> give me some reference
> about where to start/continue, I really would appreciate it.

Well, I've half-promised to do some graphics in part 5, not yet to be
written, of my attempted Correct C++ tutorial at



In the mean time, enjoy parts 1 through 4! :-)

Comments welcome (in the newsgroup).

Cheers,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
From:CBFalconer
Subject:Re: Self-studying C++
Date:Sun, 23 Jan 2005 22:13:38 GMT
"Alf P. Steinbach" wrote:
>
.... snip ...
>
> Well, I've half-promised to do some graphics in part 5, not yet
> to be written, of my attempted Correct C++ tutorial at
>
>
>
> In the mean time, enjoy parts 1 through 4! :-)
>
> Comments welcome (in the newsgroup).

Pack the whole thing up in a single zip file for download and
examination offline. What I saw of it seemed sound. Far too many
pages, though. Better to have a much larger page with local
labels, equivalent to the complete word files. Then you can again
pack them, with the necessary graphics, into one file for
download. The advantage of html is that it can easily adapt to the
display size available.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
From:Gianni Mariani
Subject:Re: Self-studying C++
Date:Sun, 23 Jan 2005 23:42:09 -0800
Alf P. Steinbach wrote:
....
>
> Comments welcome (in the newsgroup).

Do you think you need to reconsider the std::endl vs '\n' ?

std::endl should really only be used when data must be flushed.
From:Percival
Subject:Re: Self-studying C++
Date:Sun, 23 Jan 2005 16:37:10 -0500
On Sun, 23 Jan 2005 05:38:43 -0800, Misery wrote:

> but if someone could
> give me some reference
> about where to start/continue, I really would appreciate it.
>
> Thanks!

Well, first I'd say you should make many little programs to make sure you
are in the deal.

Some quick things off the top of my head. (I don't know how good you are,
so if these are insultingly easy don't blame me :) )

* "Guess the number" game, you make a random number between 1 and 100, and
every time the user gets it wrong, the computer tells him if he guessed
too high or too low. Be sure to have the number random.

* "Computer guesses the number" game. The user makes a number, and the
computer guesses it, with the user telling the computer if he guessed too
high or too low. You can do this by going half way inbetween the numbers
each turn. Example:

(user chooses the number 40)

Computer guesses: 50 -> 25 -> 37 -> 43 -> 40
First 50, then it moves 25 in the direction (it was lower), then moves
25/2 in the direction, then 25/4 in the direction, then 25/8 in the
direction until the computer guesses the number.

* Tic tac toe, connect 4, etc. These games can be made text based, so you
don't really have to worry about graphics. And if you do make them
graphical, then it isn't too hard.

* Calculator. Make a calculator. Text based or graphical. Support
addition, subtraction, etc etc. You can make them backwards if you like,
like 1 1 + turns into 2. I think it is easier to make reverse-polish
notation calculators, but do whatever you want.

*Game clones. Galaga, Pong, etc are all good games to know once you
understand how to do graphics.

*Simple application clones. Paint, Notepad, etc.

=====

If you ready for graphics, I really like the SDL package for making games,
and GTK+ for making windows or applications. They are both cross platform
and reletivly easy to use. Be sure to understand pointers and etc before
SDL, and callback functions before using GTK+. SDL is sorta like DirectX
but easier and portable, and GTK+ is used if you wanna make a NotePad
clone.

http://www.libsdl.org/index.php
Info on SDL. Google comes up with good tutorials.

http://www.gtk.org/
Homepage on GTK+.

http://www.cppreference.com/
A good C++ reference. It is incomplete in certain parts, but it serves its
job very well.

I also find that studying different languages tend to give me a more
complete understanding of programming in general. Assembly and Lisp and
Perl and Python are other languages you should try out a bit. IMO, it is
important for every programmer to know how stuff is done at the lowest
level.

For a good assembly tutorial, try here:
http://webster.cs.ucr.edu/AoA/index.html
That for x86 based processors only (Pentium, AMD Athelon etc etc) If you
running a Mac, i don't know any useful books on PowerPC assembly.

If you wanna find alot of good books, try out freetechbooks.com It has
plenty of freetechbooks :) They are all online though, but if you got a
pdf reader (like adobe acrobat) it isn't too hard to read.

Percival
   

Copyright © 2006 newsgroups-index   -   All rights reserved   -   Impressum