Home

Egg Directory / Search

New Eggs / Best of New

New Blogs / Pics / Activity
New Files / Movies
Community Forum

Group Directory

Stickers

 


 
THE EGG DIRECTORY
How To / Helpful Guides / Legal
Edit PageMessage arbysman9099Add CommentAdd to FavoritesEmail to Friend

Introduction to C++

DO NOT TRY THIS AT HOME : Our text files and message bases are for INFORMATIONAL PURPOSES ONLY. DO NOT undertake any project based upon any information obtained from this or any other web site.We are not responsible for, nor do we assume any liability for, damages resulting from the use of any information on this site.
(61 votes)
Published: Apr 30, 2008 5:55 p.m.
In 2 Favorites Lists
Viewed 525 times




Hello this egg is for people who are interested in learning a new programming language , in this case it is going to be an introduction to C++. For this I’ve been using Dev-C++ to download Dev-C++ here http://www.bloodshed.net/download.html

C++ has a structure that needs to be followed while programing or you will not be able to compile the code without errors. C++ has "includes" which are libraries that other people made. In these libraries have functions for coding this helps makes coding in C++ easier because you will be able to make your own for code that is repeat constantly in your programs. The includes go first in the structure because they are needed to call events and code from the libraries. To put an include in you put a number sign then the word "include" then the name of the library. After the includes you have three things which are functions, globals and the main function. You need to put your functions here so so main know they exist, you do not have to type the code for the function here you could just put void functionname(); in front so the main knows that functionname() is a function and will look for it after the main function. The global variables are also put in front, the global variable is a constant variable that every function can use and change and that change will remain throughout the program. Ok here is an example of the structure:

#include &#60stdio.h&#62
int globalvariable;
void function();
int main(){
}


Now you see in this example that I have a number sign in front of the include like i said before this is to tell the compiler to include this library. Next in this example, I put a variable called globalvariable using int which I will explain later. After that I put void function() telling main() that function() is indeed a function. O.K. now lets try actually writing a program, for this program we want to put the text "My first program" on the screen. So let me show you the code:

#include &#60stdio.h&#62 // This is the library needed.
int main(){ // The main function
printf("My first program"); // This puts the output onto the screen
return 0; // This tells the os that there was no problem.
}


Ok now looking over this code you should notice a bunch of things, starting with that I end every event with a semi-colon. I am doing this because C++ requires it. Also you should see the double forward slashes this is a comment. Comments are use for situations like you forget what the code is used for or when you take a break and come back you’ll have an idea what you were doing before you left. Also I used the printf() function this is just to output the text onto the screen.

That was easy right? So then let’s move on to a little more complicated things. For this program we will be putting "Hello Rotteneggs" on the screen ten times by using a for loop. A for loop is very simple all it does is first sets the variable equal to what you choose. Then it checks a statement and if its false it stops if its true then it does the code given then does the next statement in the for command. That probably sounds confusing so here is an example for (i=1; i&#60 10; i++). In this example the first thing the statement does is set i equal to one, then it checks if i is greater then ten if it is false it exits but if its true then it adds one to i and execute the code and continues the FOR statement. Ok now lets get the code for our new program.

#include &#60stdio.h&#62
#include &#60stdlib.h&#62 // used for system pause
int main(){
int i; // This loads the i so i can be used in the for statement.
for(i=1; i&#60 10; i++){ // This is the for statement
printf("Hello Rotteneggs");
}
system("PAUSE"); // Pauses so you can actually read it
return 0;}


Now in this code it first starts with the include statement loading in the library. Then we go into the main function, after in the function we needed to get our variable loaded in so we can use it in the FOR statement. After loading the variable we went right into the FOR statement, the for statement is the example I showed before it first sets i to one then checks if i is greater then 10 then it exits and if its true prints "Hello Rotteneggs" and it continues going through the loop adding one until i is greater then ten.
The FOR statement is particularly good for printing things on the screen many times in a row and other repetitive tasks that you may not want to do. In the next egg I will be showing the IF THEN statement, the WHILE statement and taking user input and using it in your program. For the next egg I would appreciate all input for the next egg to make it easier to understand.
 

Add Egg To Watchlist

m0rtified_p3nguin

Apr 30, 2008 8:06 pm -
it is tricky to do eggs that involve coding on this site. for future refrence, it might be better to use cropped screen clips when giving code examples.


slugger-9364

Apr 30, 2008 8:50 pm -
nice, lookign for soemthing like this.. 5*


siner

May 01, 2008 3:30 am - ed
ehhhh 5


Demosthenes-1789

May 01, 2008 4:24 pm - Too complicated for me.
But it looks like you put lots of work and effort into this egg, 5s for you!


timmydogman

May 01, 2008 6:55 pm -
Yeah, 5*


boiled_eggs

May 02, 2008 1:33 pm -
this is good but it needs pics of coding. 3*


Rock_In_Black

May 02, 2008 4:56 pm -
Needs an FAQ with questions like: "Why the hell should I learn C++?!" (I’m wondering)


berto-6193

M y 03, 2008 12:25 pm -
looks like alot of time and effort!
5*


H-Dogg

May 03, 2008 10:34 pm -
Yeah, and Apu and his five brothers in Bangalore will do it for a combined wage of less than half of yours. That said, this is a pretty good egg, and we need more good eggs.

 


Home | Contact Us | Sign Up | Advertise Here
Visit our companion site, Prankpedia.com
Please read the LEGAL DISCLAIMER & CONTENT GUIDELINES
© 2008 rotteneggs.com - A Social Network for Pranksters.
0.061884 (Server 2)