Quick Search for:  in language:    
article,teaches,beginners,things,gonna,includ
   Code/Articles  |  Newest/Best  |  Community  |  Jobs  |  Other  |  Goto  | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
C/ C++ Stats

 Code: 681,728. lines
 Jobs: 96. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login





Latest Code Ticker for C/ C++.
Yet another Console Space Invaders
By Steven McElrea on 11/28


PrimeTester
By Titus Laska on 11/28


Click here to see a screenshot of this code!Commander
By Hylke Donker on 11/27

(Screen Shot)

Game Trees and minimax method (minima maxima)
By Hasan Alayli on 11/27


Origin of Computer Games!
By suneet singh on 11/27


CD Tray Open
By pr0ger on 11/27


Click here to see a screenshot of this code!Maze solver using backtacking & recursion
By Hasan Alayli on 11/27

(Screen Shot)

Grand TicAttackToy
By Divine Light on 11/27


Word Deriver thru stack operations
By Sayash Kumar on 11/26


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

A Beginners guide to C++

Print
Email
 

Submitted on: 11/17/2003 5:10:04 PM
By: James Dunne  
Level: Beginner
User Rating: By 1 Users
Compatibility:C++ (general)

Users have accessed this article 597 times.
 

(About the author)
 
     This article teaches beginners a few things, not all but I am gonna include in other tutorials, I will only make a sequel to tutorials if you like the prequal

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.

Introduction -

Okay, This is my first tutorial ive ever written for Planet-Source-Code so go light if I make mistakes :). I really hope this helps you as much as another tutorial helped me. In this tutorial you will learn (hopefully) how to compile source code and write a basic program that will display an Variable that you input.

Enjoy, ~Jamesy.

Part 1 : The first code of a beginner-

Well, if you dont have a clue what to do you probably haven't got
compiler yet so go to http://www.download.com and search Dev-C++, this will show up a single result, if not search for Bloodshed Dev-C++. This is a C++ and a C compiler also! So go ahead download it. Now, once you have installed it open it and click the new file icon to bring up a text editor-like window with this inside :

#include
#include

int main()
{

system("PAUSE");
return 0;
}


now, in between the sharp brackets (ones with a point in the middle) type or copy this :

cout << "Howdy there, Oh yeah, Hello World!";

Now you should have something like this :

#include
#include

int main()
{
cout << "Howdy there, Oh yeah, Hello World!";
system("PAUSE");
return 0;
}


Go to "Execute" on the toolbar (where File, Edit, etc is) then press "Compile & Run" and it should say in an MS-DOS prompt :

Hello there, Oh yeah, Hello World!

Congrats, you just programmed in C++! Sure you didnt write the program but you did compile it which means your a programmer.

Now for the explanation :

#include means to insert code out of a header file.

iostream.h is the file that lets you do the cout and cin commands. iostream means input-output-stream just if you are wondering.

stdlib.h lets you do the system("PAUSE"); command.

The blank line is just whitespace, ignore it but put it between every function.

int main() is a function that must be in every C++ program. Its like your motherboard to your PC, It cant be run with out it.

{ is the opening bracket and just for time keeping, } is the closing bracket.

cout prints to the console (<< must be present, cant be the other way round)

system("PAUSE"); stops the script from running after it, making the program to stop after it has printed to the console instead of printing then closing. Thank this for giving you the pleasure on seeing your pride joy in your first C++ program.

return 0; returns 0 to close the program.

On to Part 2 : The Juicey Stuff

Part 2 : The Juicey Stuff

Now click the New Code button again. Now we are gonna stick our fork in the steak this time and not the chips.

Click on the first whitespace and press enter then type :

int clouds;

then in the next white space put :

cout << "How many clouds do you see?\n";
cin >> clouds;
cout "\nThere are " << clouds << " in the sky!\n";

Now you should have something like this :

#include
#include

int clouds;
int main()
{
cout << "How many clouds are there?\n";
cin >> clouds;
cout << "\nThere are " << clouds << " in the sky!";
system("PAUSE");
return 0;
}


Now compiler and run and test :)

Now for the explanation :

*Note : I am only explaining things you have not already learnt


int clouds; is the variable, this stores the information you type in when you ran the program. Say for instance 86 its would say :

There are 86 clouds in the sky!

There are more types of Variable which I will explain in a later tutorial if you like my tutorial.

<< clouds << in the cout command basically displays the variable. You can do this with any variable and is used when using endl (another way to linebreak, I prefer \n for programs like these) You can even add, subtract, multiply, etc with it.

Ok now you have enough knowledge to add to the program and make it more instresting and stuff, after my next tutorial you will be able to make a Questionaire!

Other things!

Ok, if you want to get in contact with me, I dont use email, Only AIM! Contact me on chickenscooop if you need anything or want to recommend something.

Again, I would like feedback, please give me feedback :)

~James Dunne


 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this article(in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
11/17/2003 11:44:48 PM:Dan Anderson
Ahhhhh .. not another beginner's tutorial!!!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/20/2003 7:10:08 AM:
thankyou, i've been trying to start learning somewhere.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this article has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular article, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | C/ C++ Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.