<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4548120341762835112</id><updated>2012-02-16T17:56:30.118-08:00</updated><title type='text'>C++ 101 - Your guide to C++</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cpp101sg.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4548120341762835112/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://cpp101sg.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Joel Tong</name><uri>http://www.blogger.com/profile/05610658178781845711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4548120341762835112.post-1107532300750030972</id><published>2009-03-18T06:13:00.000-07:00</published><updated>2009-03-18T06:21:08.814-07:00</updated><title type='text'>Lesson 5: Arrays</title><content type='html'>In programming, you are most likely to need a collection of variables.  Let’s say I want to store a register of the different people in class:&lt;br /&gt;&lt;br /&gt;Register[0] = “John”&lt;br /&gt;Register[1] = “Mary”&lt;br /&gt;Register[2] = “Ah Seng”&lt;br /&gt;Register[3] = “Ah Beng”&lt;br /&gt;…&lt;br /&gt;Register[n-1] = “Ben”&lt;br /&gt;&lt;br /&gt;Well you get the picture.  This is where arrays come in.  &lt;br /&gt;&lt;br /&gt;In C++, there are 2 ways to declare an array: A Vector (Under STL) and an Array (inbuilt).  I will teach you Vector since it is more widely used and is dynamic (i.e., easier to understand) than Arrays.&lt;br /&gt;&lt;br /&gt;To declare a vector:&lt;br /&gt;&lt;pre name="code" class="cpp"&gt;&lt;br /&gt;vector&lt;[type]&gt; [name];&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;or &lt;br /&gt;&lt;pre name="code" class="cpp"&gt;&lt;br /&gt;vector&lt;[type]&gt; [name]([size], [fill]);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;where size is size of the array (i.e. the n), and the fill is the constant you want to fill those empty “slots”.&lt;br /&gt;&lt;br /&gt;To set a value manually after constructing the array, you just do this:&lt;br /&gt;&lt;pre name="code" class="cpp"&gt;&lt;br /&gt;[name][n] = “hi”;&lt;br /&gt;&lt;br /&gt;//eg&lt;br /&gt;vector&lt;string &gt; basket(3);&lt;br /&gt;basket[0] = “apples”;&lt;br /&gt;basket[2] = “grapes”;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;(Note that arrays are always zero-based, so the max reference is 2, and the starting is 0.)&lt;br /&gt;&lt;br /&gt;To iterate (loop) through an array, we use loops:&lt;br /&gt;&lt;pre name="code" class="cpp"&gt;&lt;br /&gt;vector&lt;int&gt; bla(5,20);&lt;br /&gt;&lt;br /&gt;for (int i = 0; i &lt; bla.size(); i++) {&lt;br /&gt; cout &lt;&lt; bla[i] &lt;&lt; endl;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is good particularly if you want to search for something in the array or do processing (for e.g. image convolution).&lt;br /&gt;&lt;br /&gt;What if your array is 2D, i.e. a picture’s pixel values?  Then you use multiarrays, or rather, a vector that contains another vector to form a 2D image, or a single extremely long vector. Multiarrays are referenced as such:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="cpp"&gt;&lt;br /&gt;[name] [x + y * w];&lt;br /&gt;//x = current x pos&lt;br /&gt;//y = current y pos&lt;br /&gt;//w = width of multiarray&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To give you an example of how to use them:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="cpp"&gt;&lt;br /&gt;//This prints out a 50 X 20 multiarray of 20s&lt;br /&gt;int w = 20, h = 50;&lt;br /&gt;vector&lt;int&gt; bla(w + h * w,20);&lt;br /&gt;&lt;br /&gt;for (int y = 0; y &lt; h; y++) {&lt;br /&gt; for (int x = 0; x &lt; w; x++) {&lt;br /&gt;  cout &lt;&lt; bla[x + y * w] &lt;&lt; " ";&lt;br /&gt; }&lt;br /&gt; cout &lt;&lt; endl;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So that’s arrays (rather, vectors) in a nutshell.  Ciao!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4548120341762835112-1107532300750030972?l=cpp101sg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp101sg.blogspot.com/feeds/1107532300750030972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp101sg.blogspot.com/2009/03/lesson-5-arrays.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4548120341762835112/posts/default/1107532300750030972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4548120341762835112/posts/default/1107532300750030972'/><link rel='alternate' type='text/html' href='http://cpp101sg.blogspot.com/2009/03/lesson-5-arrays.html' title='Lesson 5: Arrays'/><author><name>Joel Tong</name><uri>http://www.blogger.com/profile/05610658178781845711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4548120341762835112.post-1325170895898052376</id><published>2009-03-14T07:44:00.000-07:00</published><updated>2009-03-14T08:55:36.562-07:00</updated><title type='text'>Lesson 3: Program flow</title><content type='html'>Many a time, programs would have to make certain decisions.  We might want to control how our program runs.  This is where program flow comes in.&lt;br /&gt;&lt;br /&gt;Controlling program flow can come in the following or both: loops and decision-making statements.  The following illustrates this point:&lt;br /&gt;&lt;br /&gt;If-Else statements&lt;br /&gt;This is a very simple decision making programming tool.  It evaluates a statement.  Evaluative statements come in the form of:&lt;br /&gt;&lt;br /&gt;&lt;pre name = "code" class = "cpp"&gt;&lt;br /&gt;A [operator] B&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Operators can be one of below:&lt;br /&gt;==  //equal to&lt;br /&gt;&gt;=  //more than or equal to&lt;br /&gt;&lt;=  //less than or equal to&lt;br /&gt;!=  //not equal to&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To evaluate more than 2 statements, use the &amp;&amp; (meaning AND) and || (meaning OR).  The basic structure of an if-else decision is:&lt;br /&gt;&lt;br /&gt;&lt;pre name = "code" class = "cpp"&gt;&lt;br /&gt;if([evaluative statement 1]) {&lt;br /&gt; //do a;&lt;br /&gt;} else if ([evaluative statement 2] {&lt;br /&gt; //do b;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;…&lt;br /&gt;else {&lt;br /&gt; //do c;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Of course, you can omit the else and else if in certain cases which you might not need to use them.  Also, if your decision making statements are only one-liners, you can omit the curly braces as well.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For loops:&lt;br /&gt;&lt;br /&gt;As its name suggests, it would do the same statements in the brackets (scope) until the condition is satisfied.  For loops are good for iterating through arrays.  It is written this way:&lt;br /&gt;&lt;br /&gt;&lt;pre name = "code" class = "cpp"&gt;&lt;br /&gt;for ([initial variable value]; [evaluative statement]; [do something to variable if satisfied])  {&lt;br /&gt;…&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;While loops:&lt;br /&gt;&lt;br /&gt;Something like for loops, but only runs when that condition is satisfied.&lt;br /&gt;&lt;br /&gt;&lt;pre name = "code" class = "cpp"&gt;&lt;br /&gt;while(evaluative statement) {&lt;br /&gt;…&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;To make an infinite while loop, use “while(1) { … }”.  While loops can be for loops as well:&lt;br /&gt;&lt;br /&gt;&lt;pre name = "code" class = "cpp"&gt;&lt;br /&gt;int i = 0;&lt;br /&gt;while(i &lt; 5) {&lt;br /&gt; …&lt;br /&gt;…&lt;br /&gt;i++;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;However as you can see, this is not done usually as it is not very elegant.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;Write a program that evaluates the type of roots from a polynomial of maximum base 2 with discriminant d = (b^2) – 4ac, of polynomial a x^2 + b x + c.  d &gt; 1 for real distinct roots, d = 0 for single real roots and d &gt; 0 for no real roots.&lt;br /&gt;&lt;br /&gt;&lt;pre name = "code" class = "cpp"&gt;&lt;br /&gt;&lt;br /&gt;#include &amp;#60;iostream&amp;#62;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main() {&lt;br /&gt; int a,b,c,d&lt;br /&gt; while(1) {     //continue until break&lt;br /&gt;  cout &lt;&lt; "Enter coefficient of x^2: "; cin &gt;&gt; a;&lt;br /&gt;  cout &lt;&lt; "Enter coefficient of x^1: "; cin &gt;&gt; b;&lt;br /&gt;  cout &lt;&lt; "Enter coefficient of x^0: "; cin &gt;&gt; c;&lt;br /&gt;  d = b * b - 4 * a * c;&lt;br /&gt;  if (d &gt; 1) cout &lt;&lt; "REAL DISTINCT ROOTS";&lt;br /&gt;  else if (d == 0) cout &lt;&lt; "REAL SINGLE ROOT";&lt;br /&gt;  else cout &lt;&lt; "NO REAL ROOTS";&lt;br /&gt; }&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Program is self-explanatory; gives you a better picture of how to use loops and conditions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4548120341762835112-1325170895898052376?l=cpp101sg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp101sg.blogspot.com/feeds/1325170895898052376/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp101sg.blogspot.com/2009/03/lesson-3-program-flow.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4548120341762835112/posts/default/1325170895898052376'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4548120341762835112/posts/default/1325170895898052376'/><link rel='alternate' type='text/html' href='http://cpp101sg.blogspot.com/2009/03/lesson-3-program-flow.html' title='Lesson 3: Program flow'/><author><name>Joel Tong</name><uri>http://www.blogger.com/profile/05610658178781845711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4548120341762835112.post-3208617932038530686</id><published>2009-03-13T08:49:00.000-07:00</published><updated>2009-03-13T09:17:02.290-07:00</updated><title type='text'>Lesson 2: Data types</title><content type='html'>Now after gaining newfound knowledge on how to write a hello world app, let’s learn how to do computational arithmetic.&lt;br /&gt;&lt;br /&gt;As you know from your basic algebra, variables can be assigned any name.  However, in C++, the computer cannot solve equations.  Variables can only be assigned values.&lt;br /&gt;&lt;br /&gt;There are mainly 2 types of variables in C++: Strings and numbers.  Classification is as follows:&lt;br /&gt;&lt;br /&gt;String type:&lt;br /&gt;Char (character)&lt;br /&gt;string (an array of char)&lt;br /&gt;&lt;br /&gt;Number type:&lt;br /&gt;int&lt;br /&gt;unsigned long (big int)&lt;br /&gt;float (floating-point, i.e. decimal)&lt;br /&gt;double (super precise floating-point number)&lt;br /&gt;bool (Boolean, i.e. true and false)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To define a variable, we type in the code:&lt;br /&gt;&lt;pre name = "code" class = "cpp"&gt;&lt;br /&gt;[var_type] [var_name];&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And can be assigned values on instantiation:&lt;br /&gt;&lt;pre name = "code" class = "cpp"&gt;&lt;br /&gt;[var_type] [var_name] = [var_value];&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So for example, I can assign an int to hold value 3:&lt;br /&gt;&lt;pre name = "code" class = "cpp"&gt;&lt;br /&gt;int abc = 3;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;or Boolean xyz with false:&lt;br /&gt;&lt;pre name = "code" class = "cpp"&gt;&lt;br /&gt;bool xyz = false;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can assign multiple values:&lt;br /&gt;&lt;pre name = "code" class = "cpp"&gt;&lt;br /&gt;int a = 3, b, c = 5;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;to create a string hihi with value hello me:&lt;br /&gt;&lt;pre name = "code" class = "cpp"&gt;&lt;br /&gt;string hihi = “hello me”;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Arithmetic:&lt;br /&gt;C++ can do simple +, -, /, *, % (modulo)&lt;br /&gt;&lt;br /&gt;A definition is as follows:&lt;br /&gt;&lt;pre name = "code" class = "cpp"&gt;&lt;br /&gt;int a = 0;  //create a; assign a  = 0&lt;br /&gt;a + 1;   //add 1 to a&lt;br /&gt;a – 1;   //minus&lt;br /&gt;a /1;   //divide&lt;br /&gt;a*1;   //multiply&lt;br /&gt;a%1;   //modulo&lt;br /&gt;a++;   //a + 1 and store new value in a&lt;br /&gt;a--;   //a – 1 and store new value in a&lt;br /&gt;a += 2;   // add value 2 to a and store&lt;br /&gt;a -= 2;   // subtract 2 from a and store&lt;br /&gt;a /= 2;   //divide 2 from a and store&lt;br /&gt;a *= 2;   //multiply 2 to a and store&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;That done, let us analyse a simple problem.&lt;br /&gt;&lt;br /&gt;Evaluate the value of (9– 2) / ( (180.5 + 2) / 3):&lt;br /&gt;&lt;br /&gt;A simple c++ program:&lt;br /&gt;&lt;br /&gt;&lt;pre name = "code" class = "cpp"&gt;&lt;br /&gt;#include &amp;#60;iostream&amp;#62;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main() {&lt;br /&gt; int a,b,c;&lt;br /&gt; a = 9 - 2;&lt;br /&gt; b = 180.5 + 2;&lt;br /&gt; c = b / 3;&lt;br /&gt; cout &lt;&lt; a / c &lt;&lt; endl;&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Of course, I can put the whole expression (9– 2) / ( (180.5 + 2) / 3) into C++, but this is to illustrate the picture better.&lt;br /&gt;&lt;br /&gt;Hope you get a better picture of how to handle vars in C++, ciao!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4548120341762835112-3208617932038530686?l=cpp101sg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp101sg.blogspot.com/feeds/3208617932038530686/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp101sg.blogspot.com/2009/03/lesson-2-data-types.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4548120341762835112/posts/default/3208617932038530686'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4548120341762835112/posts/default/3208617932038530686'/><link rel='alternate' type='text/html' href='http://cpp101sg.blogspot.com/2009/03/lesson-2-data-types.html' title='Lesson 2: Data types'/><author><name>Joel Tong</name><uri>http://www.blogger.com/profile/05610658178781845711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4548120341762835112.post-1985399298320705748</id><published>2009-03-12T05:53:00.001-07:00</published><updated>2009-03-13T08:37:38.089-07:00</updated><title type='text'>test</title><content type='html'>&lt;pre class="cpp" name = "code"&gt;&lt;br /&gt;#include &amp;lt;iostream&gt;&lt;br /&gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main () {&lt;br /&gt; cout &amp;lt;&amp;lt; "hello world";&lt;br /&gt; return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4548120341762835112-1985399298320705748?l=cpp101sg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp101sg.blogspot.com/feeds/1985399298320705748/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp101sg.blogspot.com/2009/03/test.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4548120341762835112/posts/default/1985399298320705748'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4548120341762835112/posts/default/1985399298320705748'/><link rel='alternate' type='text/html' href='http://cpp101sg.blogspot.com/2009/03/test.html' title='test'/><author><name>Joel Tong</name><uri>http://www.blogger.com/profile/05610658178781845711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4548120341762835112.post-7451472800197600018</id><published>2009-03-12T04:42:00.000-07:00</published><updated>2009-03-12T05:39:34.623-07:00</updated><title type='text'>Lesson 1: Brief introduction to C++</title><content type='html'>Hi all, perhaps you have just started learning C++.  C++ shares its roots in C – the C++ really means “C added”.  Std C++ is a good language to start learning programming.  Perhaps you will need it for computing / engineering tests, and that is why you are here! (Cheers).  Will not bore you any further, let’s start with some basics.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;How a program works:&lt;br /&gt;&lt;br /&gt;To make a program is very simple.  The flow of making a program is as follows:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Cpp file -&gt; Compiler (You have your linkers here) -&gt; binary executable (i.e. your program)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Your cpp file can be in plaintext (i.e. using some editor such as Notepad, or on Linux, vim / gedit / Kate / etc.).  Your compiler is the intermediary step between human-readable code and binary code.  This is a one-way process. (i.e. you cannot turn binary exe into readable code without disassembling it).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Getting a compiler:&lt;br /&gt;&lt;br /&gt;For Windows, try Visual C++ which is now free or Bloodshed Dev C++.  Follow the instructions to compile a program.  In VCC, that usually means making a project first.  In Bloodshed Dev C++, you can do that by creating a cpp file, then pressing F9 to compile and F10 to run.&lt;br /&gt;&lt;br /&gt;For Linux, your OS should have g++ pre-installed.  If not, get g++ by running the command “&lt;span style="font-family:courier new;"&gt;sudo apt-get install g++&lt;/span&gt;” from terminal.  You need administrator rights to install it.   To compile a program using g++, type in the following:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;g++ -o [name of output file] [name of input c++ file]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;to run, type in “&lt;span style="font-family:courier new;"&gt;./[name of output file]&lt;/span&gt;”.&lt;br /&gt;&lt;br /&gt;These form the basics of a compiler.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Basic C++ structure:&lt;br /&gt;&lt;br /&gt;C++ follows C syntax.  This includes the demarcation of program flow using curly braces {}.  These will be elaborated in more detail later.  C++ is a top-down language, i.e. it processes commands from top to bottom, and not all at once within a code block.  This is very important to note.&lt;br /&gt;&lt;br /&gt;Writing your first C++ Program:&lt;br /&gt;&lt;br /&gt;A basic C++ hello world program goes like this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;#include &lt;iostream&gt;&lt;/iostream&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;using namespace std;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;int main() {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    cout &lt;&lt; "Hello world" &lt;&lt;&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    return 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;#include &lt;iostream&gt;&lt;/iostream&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#include is a preprocessor directive. I.e, it tells the compiler what to do before it compiles the program. In this case, a computer will not know how to input / handle certain things UNLESS you tell it how to. In this case, it includes a header file called “iostream” that contains definitions on how to output text to the command line, among other things. For this purpose, we will only need the “iostream” header. As noted, C++ has a top-down program flow. Hence include this statement at the beginning of every C++ file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;using namespace std;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This is like a shortcut.  If you do not do this, you will need to put a “std::cout” everytime you use “cout”.  So treat this like a general habit everytime you use standard C++.  Basically, it tells the compiler to always use the namespace std as a shortcut to std C++.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;NOTE THE SEMICOLON “;”.  This is to tell the compiler you are moving on to the next line in the program.  Just pressing the return key (i.e. enter) will not do the trick.  Do this for every line except for function declarations and the like.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;int main() {  }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The main body function.  This is where the compiler will look when you run the program.  This is a function, and by right, functions can return something.  In this case, an integer (int).  Don’t worry, you will learn more about functions in the functions chapter.  For now, just write it as is.  You just have to know that for C++ programs, traditionally to return a value 0 means the program has no error, and to return any other number means there was some error in processing.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;cout &lt;&lt; “hello world” &lt;&lt;&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Pronounce cout as C-out.  This tells the compiler to print the message (in this case, a string as denoted by “”) “hello world” to the command line.  The “endl” means “to add a newline, i.e. move to the next line.  What this does is add a “\n” to your output.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;return 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;End the main function.  Return a 0 since there will not be any error.  For windows users, you might want to add another line&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;system(“pause”)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;before the return 0 so that you can see what is generated on the screen.  This is not needed for Linux users.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;There you have it, your first hello world program in a nutshell.  Compile it and it should be ready to run.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Ciao!&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4548120341762835112-7451472800197600018?l=cpp101sg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp101sg.blogspot.com/feeds/7451472800197600018/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp101sg.blogspot.com/2009/03/lesson-1-brief-introduction-to-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4548120341762835112/posts/default/7451472800197600018'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4548120341762835112/posts/default/7451472800197600018'/><link rel='alternate' type='text/html' href='http://cpp101sg.blogspot.com/2009/03/lesson-1-brief-introduction-to-c.html' title='Lesson 1: Brief introduction to C++'/><author><name>Joel Tong</name><uri>http://www.blogger.com/profile/05610658178781845711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4548120341762835112.post-8163900751501665101</id><published>2009-03-12T04:36:00.000-07:00</published><updated>2009-03-12T04:42:04.762-07:00</updated><title type='text'>Introduction to C++ 101: Topics</title><content type='html'>Hey!&lt;br /&gt;&lt;br /&gt;Welcome!  This site will teach you the basics and help you solve computing problems related to std C++.  This site was started out of pure interest and fun.  Topics that will be included are:&lt;br /&gt;&lt;br /&gt;1.    Introduction&lt;br /&gt;a.    Brief history of C++ / programming&lt;br /&gt;b.    Program structure / syntax&lt;br /&gt;i.    Preprocessor directives&lt;br /&gt;ii.    Main function&lt;br /&gt;iii.    namespaces&lt;br /&gt;c.    Declarations&lt;br /&gt;d.    Cout / cin&lt;br /&gt;e.    Data types&lt;br /&gt;i.    Numbers&lt;br /&gt;ii.    Strings&lt;br /&gt;iii.    Streams&lt;br /&gt;f.    Operators&lt;br /&gt;&lt;br /&gt;2.    Conditions / loops&lt;br /&gt;a.    For loop&lt;br /&gt;b.    While loop&lt;br /&gt;c.    If /else condition / &amp;amp;&amp;amp; and ||&lt;br /&gt;d.    Switch / case&lt;br /&gt;&lt;br /&gt;3.    Vectors&lt;br /&gt;a.    Instantiate / access&lt;br /&gt;b.    Multi-vectors&lt;br /&gt;c.    Iterating through vectors&lt;br /&gt;&lt;br /&gt;4.    Strings&lt;br /&gt;a.    Definition&lt;br /&gt;b.    Converting string &gt; int, int &lt; string&lt;br /&gt;c.    Accessor functions / iterating&lt;br /&gt;&lt;br /&gt;5.    Functions&lt;br /&gt;a.    Void functions&lt;br /&gt;b.    Return functions&lt;br /&gt;c.    Passing by reference&lt;br /&gt;d.    Recursive functions&lt;br /&gt;&lt;br /&gt;6.    Common error handling&lt;br /&gt;a.    Int / string checker&lt;br /&gt;b.    Wrong input&lt;br /&gt;c.    Conversion&lt;br /&gt;&lt;br /&gt;7.    File I/O&lt;br /&gt;a.    Ifstream / ofstream&lt;br /&gt;b.    Read-only / read / write&lt;br /&gt;&lt;br /&gt;8.    Pointers&lt;br /&gt;&lt;br /&gt;9.    Problem solving&lt;br /&gt;a.    Greedy&lt;br /&gt;b.    Dynamic programming&lt;br /&gt;c.    Divide and conquer&lt;br /&gt;&lt;br /&gt;I will post this in my own free time.  Be sure to leave a message in the right column if you have any questions related to C++!  Be sure to join in the fun! =D&lt;br /&gt;&lt;br /&gt;Ciao!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4548120341762835112-8163900751501665101?l=cpp101sg.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp101sg.blogspot.com/feeds/8163900751501665101/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp101sg.blogspot.com/2009/03/introduction-to-c-101-topics.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4548120341762835112/posts/default/8163900751501665101'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4548120341762835112/posts/default/8163900751501665101'/><link rel='alternate' type='text/html' href='http://cpp101sg.blogspot.com/2009/03/introduction-to-c-101-topics.html' title='Introduction to C++ 101: Topics'/><author><name>Joel Tong</name><uri>http://www.blogger.com/profile/05610658178781845711</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
