Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Linux > Support Documents

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-07-2006, 07:16 PM
mindfrost82's Avatar
Administrator
 
Join Date: Mar 2006
Location: Illinois
Posts: 2,168
Sex: Male
My Mood:
Thanks: 5
Thanked 5 Times in 5 Posts
Send a message via ICQ to mindfrost82 Send a message via AIM to mindfrost82 Send a message via MSN to mindfrost82 Send a message via Yahoo to mindfrost82
Learn C++

C++ is a really good language to learn. Read this to find out how. C++ has always been one of the most used languages. It is easy to learn, but hard to learn from example. I hope this LUG can help you learn C++ the easy way.



Step 1: First program
First, open up a text editor that you can use well (VI, PICO, gedit, MS Notepad, Dev-C++ etc.) In it, type:

int main(){
return 0;
}

Save the file as program1.cpp.

cd to the directory that you saved the file in and type:

gcc program1.cpp [if there are errors, make sure you typed everything right, then type the above command again]

./a.out

./a.out should end as soon as it starts.
Now, your probably wondering what all that means.

int main(){
int: the output is an intiger (see return #

main: everything between the {} happens when the program starts
(): The parenthsis are empty because the program does not take any command line input
return 0;
return: "return" is a command. You do not need this but no good programer would leave it out.
0: 0 is the number that the program returns. It could be anynumber (under a certain limit, but too wide a limit to worry about yet). In this case, it has to be a whole number, but not always. It all depends on the intiger that we put at the start of the program
}: Ends the program (in this case).

Step 2: Hello World

Nine out of ten tutorials and books teaching C (or any other language for that matter [even VB and HTML]) will include a Hello World program. This in fact originated from C (Hello World was the first program written in C). Here is one in C/C++:

#include
int main(){
printf("Hello, World");
return 0;
}

There are two new lines now:

#include : This inserts a file into your program called stdio.h. This file comes with any real compiler, and tells the program how to do Standard Input and Output.
.h means "header".
printf("Hello, World");: This prints "Hello, World" on your screen (without the quotation marks).
; ends all commands.

Step 3: Variables

int main(){
int gg;
gg = 7493;
return 0;
}

This program should seem to do the same thing as the first one, appear to do nothing.

int gg;: makes a space in memory called gg, which can store an intiger.
gg = 7493;: sets gg to 7493

Step 4: Calling Variables

#include
int main(){
int gg gg = 7493
printf("%d", gg);
return 0;
}

printf("%d", gg);

%d: This prints gg in decimal format
gg: the first %d is gg (the first number printed [to the screen] is gg, the first [and only] variable (or number, text etc.) after the comma.

Step 5: Math

Congradulations for making it this far. I hope your having fun. Not much longer to go.

#include
int main(){
int gg;
gg = 23 + 43
printf("%d", gg);
return 0;
}

This prints out 66 [23 + 43] to the screen.
gg = 23 + 43: This adds 23 and 43 and makes gg the sum [66].

Your probably thinking "thats good but there is no multiplication or division key on the keyboard", well maybe your not, but anyway, here are the operations:
Plus: +
Minus: -
Multiplied By: * [Astrik]
Divided By: /

Step 6: "if"

#include
int main(){
int gg;
gg = 23 + 25
if (gg < 45){
printf("%d is less than 45", gg);
}
return 0;
}

Basically, anything between the inner { and the inner } is done only if gg is less than 45.

Well, thats the basics. C++ gets a lot more fun. Again, congradulations for getting this far, and good luck learning more. There are many good books on C++ , and if I were you, thats where I would start [to continue ]
Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Linux > Support Documents


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 08:18 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109