<?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:blogger='http://schemas.google.com/blogger/2008' 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-3010028171272234388</id><updated>2024-09-07T08:41:47.682-07:00</updated><category term="education on line"/><category term="cpp"/><category term="online course"/><category term="online learning"/><category term="computer programming"/><category term="e-learning"/><category term="computer training"/><category term="Typcasting"/><category term="arrays"/><category term="structures"/><category term="strings"/><category term="File I/O"/><category term="Introduction to Classes"/><category term="C++ tutorial for C users"/><category term="Functions"/><title type='text'>C++ Tutorials| CPP Online Learning</title><subtitle type='html'> C++ is a different breed of programming language.  It has only a few keywords for DOS, and it has no keywords to use for output.  This means that almost everything is stored in a header file.  This gives the use of many functions.  But lets see a real program...</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>15</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-4099567453294210453</id><published>2011-05-01T12:58:00.001-07:00</published><updated>2011-05-01T13:02:46.739-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="cpp"/><category scheme="http://www.blogger.com/atom/ns#" term="e-learning"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="online learning"/><category scheme="http://www.blogger.com/atom/ns#" term="Typcasting"/><title type='text'>C++ Transparencys</title><content type='html'>&lt;div&gt;&lt;object id=&quot;_ds_78418095&quot; name=&quot;_ds_78418095&quot; width=&quot;570&quot; height=&quot;550&quot; type=&quot;application/x-shockwave-flash&quot; data=&quot;http://viewer.docstoc.com/&quot;&gt; &lt;param name=&quot;FlashVars&quot; value=&quot;doc_id=78418095&amp;mem_id=1313633&amp;doc_type=pdf&amp;fullscreen=0&amp;showrelated=0&amp;showotherdocs=0&amp;showstats=0 &quot;/&gt;&lt;param name=&quot;movie&quot; value=&quot;http://viewer.docstoc.com/&quot; /&gt;&lt;param name=&quot;allowScriptAccess&quot; value=&quot;always&quot; /&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot; /&gt;&lt;/object&gt; &lt;br /&gt; &lt;script type=&quot;text/javascript&quot;&gt;var docstoc_docid=&quot;78418095&quot;;var docstoc_title=&quot;C  TransparencysTOC.pdf&quot;;var docstoc_urltitle=&quot;C  TransparencysTOC.pdf&quot;;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;http://i.docstoccdn.com/js/check-flash.js&quot;&gt;&lt;/script&gt;&lt;font size=&quot;1&quot;&gt;&lt;a href=&quot;http://www.docstoc.com/docs/78418095/C  TransparencysTOC.pdf&quot;&gt; C  TransparencysTOC.pdf&lt;/a&gt; - &lt;/font&gt; &lt;/div&gt;&lt;div&gt;&lt;object id=&quot;_ds_78418112&quot; name=&quot;_ds_78418112&quot; width=&quot;570&quot; height=&quot;550&quot; type=&quot;application/x-shockwave-flash&quot; data=&quot;http://viewer.docstoc.com/&quot;&gt; &lt;param name=&quot;FlashVars&quot; value=&quot;doc_id=78418112&amp;mem_id=1313633&amp;doc_type=pdf&amp;fullscreen=0&amp;showrelated=0&amp;showotherdocs=0&amp;showstats=0 &quot;/&gt;&lt;param name=&quot;movie&quot; value=&quot;http://viewer.docstoc.com/&quot; /&gt;&lt;param name=&quot;allowScriptAccess&quot; value=&quot;always&quot; /&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot; /&gt;&lt;/object&gt; &lt;br /&gt; &lt;script type=&quot;text/javascript&quot;&gt;var docstoc_docid=&quot;78418112&quot;;var docstoc_title=&quot;C  Transparencys01-06.pdf&quot;;var docstoc_urltitle=&quot;C  Transparencys01-06.pdf&quot;;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;http://i.docstoccdn.com/js/check-flash.js&quot;&gt;&lt;/script&gt;&lt;font size=&quot;1&quot;&gt;&lt;a href=&quot;http://www.docstoc.com/docs/78418112/C  Transparencys01-06.pdf&quot;&gt; C  Transparencys01-06.pdf&lt;/a&gt; - &lt;/font&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;object id=&quot;_ds_78418143&quot; name=&quot;_ds_78418143&quot; width=&quot;570&quot; height=&quot;550&quot; type=&quot;application/x-shockwave-flash&quot; data=&quot;http://viewer.docstoc.com/&quot;&gt; &lt;param name=&quot;FlashVars&quot; value=&quot;doc_id=78418143&amp;mem_id=1313633&amp;doc_type=pdf&amp;fullscreen=0&amp;showrelated=0&amp;showotherdocs=0&amp;showstats=0 &quot;/&gt;&lt;param name=&quot;movie&quot; value=&quot;http://viewer.docstoc.com/&quot; /&gt;&lt;param name=&quot;allowScriptAccess&quot; value=&quot;always&quot; /&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot; /&gt;&lt;/object&gt; &lt;br /&gt; &lt;script type=&quot;text/javascript&quot;&gt;var docstoc_docid=&quot;78418143&quot;;var docstoc_title=&quot;C  Transparencys07-14.pdf&quot;;var docstoc_urltitle=&quot;C  Transparencys07-14.pdf&quot;;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;http://i.docstoccdn.com/js/check-flash.js&quot;&gt;&lt;/script&gt;&lt;font size=&quot;1&quot;&gt;&lt;a href=&quot;http://www.docstoc.com/docs/78418143/C  Transparencys07-14.pdf&quot;&gt; C  Transparencys07-14.pdf&lt;/a&gt; - &lt;/font&gt; &lt;/div&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;object id=&quot;_ds_78418162&quot; name=&quot;_ds_78418162&quot; width=&quot;570&quot; height=&quot;550&quot; type=&quot;application/x-shockwave-flash&quot; data=&quot;http://viewer.docstoc.com/&quot;&gt; &lt;param name=&quot;FlashVars&quot; value=&quot;doc_id=78418162&amp;mem_id=1313633&amp;doc_type=pdf&amp;fullscreen=0&amp;showrelated=0&amp;showotherdocs=0&amp;showstats=0 &quot;/&gt;&lt;param name=&quot;movie&quot; value=&quot;http://viewer.docstoc.com/&quot; /&gt;&lt;param name=&quot;allowScriptAccess&quot; value=&quot;always&quot; /&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot; /&gt;&lt;/object&gt; &lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;var docstoc_docid=&quot;78418162&quot;;var docstoc_title=&quot;C  Transparencys15-18.pdf&quot;;var docstoc_urltitle=&quot;C  Transparencys15-18.pdf&quot;;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;http://i.docstoccdn.com/js/check-flash.js&quot;&gt;&lt;/script&gt;&lt;font size=&quot;1&quot;&gt;&lt;a href=&quot;http://www.docstoc.com/docs/78418162/C  Transparencys15-18.pdf&quot;&gt; C  Transparencys15-18.pdf&lt;/a&gt; - &lt;/font&gt; &lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;object id=&quot;_ds_78418087&quot; name=&quot;_ds_78418087&quot; width=&quot;570&quot; height=&quot;550&quot; type=&quot;application/x-shockwave-flash&quot; data=&quot;http://viewer.docstoc.com/&quot;&gt; &lt;param name=&quot;FlashVars&quot; value=&quot;doc_id=78418087&amp;mem_id=1313633&amp;doc_type=pdf&amp;fullscreen=0&amp;showrelated=0&amp;showotherdocs=0&amp;showstats=0 &quot;/&gt;&lt;param name=&quot;movie&quot; value=&quot;http://viewer.docstoc.com/&quot; /&gt;&lt;param name=&quot;allowScriptAccess&quot; value=&quot;always&quot; /&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot; /&gt;&lt;/object&gt; &lt;br /&gt; &lt;script type=&quot;text/javascript&quot;&gt;var docstoc_docid=&quot;78418087&quot;;var docstoc_title=&quot;C  Transparencys19-23.pdf&quot;;var docstoc_urltitle=&quot;C  Transparencys19-23.pdf&quot;;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;http://i.docstoccdn.com/js/check-flash.js&quot;&gt;&lt;/script&gt;&lt;font size=&quot;1&quot;&gt;&lt;a href=&quot;http://www.docstoc.com/docs/78418087/C  Transparencys19-23.pdf&quot;&gt; C  Transparencys19-23.pdf&lt;/a&gt; - &lt;/font&gt; &lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/4099567453294210453/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/c-transparencys.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/4099567453294210453'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/4099567453294210453'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/c-transparencys.html' title='C++ Transparencys'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-2740899372441850489</id><published>2011-05-01T12:49:00.000-07:00</published><updated>2011-05-01T12:49:01.982-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++ tutorial for C users"/><category scheme="http://www.blogger.com/atom/ns#" term="cpp"/><category scheme="http://www.blogger.com/atom/ns#" term="e-learning"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="Introduction to Classes"/><category scheme="http://www.blogger.com/atom/ns#" term="online course"/><category scheme="http://www.blogger.com/atom/ns#" term="structures"/><category scheme="http://www.blogger.com/atom/ns#" term="Typcasting"/><title type='text'>C++ tutorial for C users</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;C++ tutorial for C users&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
This text is aimed at C users who wish to learn C++. It is also interesting for experienced C++ users&lt;br /&gt;
who leaved out some features of the language. The possibilities of C++ are briefly enunciated and&lt;br /&gt;
illustrated. When you will try to use them for your own programs you will encounter a lot of problems&lt;br /&gt;
and compilation errors. Come back to this text and look carefully at the examples. Make use of the&lt;br /&gt;
help files of your development environment. Do not hesitate to copy the examples from this text and&lt;br /&gt;
paste them inside your development environment in order to test and modify them.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;a href=&quot;http://www.docstoc.com/docs/78417847/C---tutorial-for-C-users&quot;&gt;C   tutorial for C users&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;object data=&quot;http://viewer.docstoc.com/&quot; height=&quot;550&quot; id=&quot;_ds_78417847&quot; name=&quot;_ds_78417847&quot; type=&quot;application/x-shockwave-flash&quot; width=&quot;530&quot;&gt;&lt;param name=&quot;FlashVars&quot; value=&quot;doc_id=78417847&amp;mem_id=1313633&amp;doc_type=PDF&amp;fullscreen=0&amp;allowdownload=1&quot; /&gt;&lt;param name=&quot;movie&quot; value=&quot;http://viewer.docstoc.com/&quot;/&gt;&lt;param name=&quot;allowScriptAccess&quot; value=&quot;always&quot; /&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot; /&gt;&lt;/object&gt;&lt;script type=&quot;text/javascript&quot;&gt;
var docstoc_docid=&quot;78417847&quot;;var docstoc_title=&quot;C   tutorial for C users&quot;;var docstoc_urltitle=&quot;C   tutorial for C users&quot;;
&lt;/script&gt;&lt;script src=&quot;http://i.docstoccdn.com/js/check-flash.js&quot; type=&quot;text/javascript&quot;&gt;
&lt;/script&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/2740899372441850489/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/c-tutorial-for-c-users.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/2740899372441850489'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/2740899372441850489'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/c-tutorial-for-c-users.html' title='C++ tutorial for C users'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-6361458937091924316</id><published>2011-05-01T12:39:00.001-07:00</published><updated>2011-05-01T12:39:23.501-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="arrays"/><category scheme="http://www.blogger.com/atom/ns#" term="computer programming"/><category scheme="http://www.blogger.com/atom/ns#" term="computer training"/><category scheme="http://www.blogger.com/atom/ns#" term="cpp"/><category scheme="http://www.blogger.com/atom/ns#" term="e-learning"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="File I/O"/><category scheme="http://www.blogger.com/atom/ns#" term="Functions"/><category scheme="http://www.blogger.com/atom/ns#" term="Introduction to Classes"/><category scheme="http://www.blogger.com/atom/ns#" term="online course"/><category scheme="http://www.blogger.com/atom/ns#" term="online learning"/><category scheme="http://www.blogger.com/atom/ns#" term="strings"/><category scheme="http://www.blogger.com/atom/ns#" term="structures"/><category scheme="http://www.blogger.com/atom/ns#" term="Typcasting"/><title type='text'>Lesson 13: More on Functions</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;        &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Lesson 13: More on Functions&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;The reason I have placed this tutorial at the end of the list, rather than as an addition to&lt;br /&gt;
&lt;br /&gt;
my other lesson is simple, I don&#39;t want people who already read that tutorial to miss this!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;In lesson 4 you were given the basic information on tutorials. &amp;nbsp;However, I left out two items&lt;br /&gt;
&lt;br /&gt;
of interest. &amp;nbsp;First, when you declare a function you don&#39;t have to prototype it! &amp;nbsp;However, you must&lt;br /&gt;
&lt;br /&gt;
give the function definition physically before you call the function. &amp;nbsp;You simply type in the entire&lt;br /&gt;
&lt;br /&gt;
definition of the function where you would normally put the prototype. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void function(void) &amp;nbsp;//Normally this would be the prototype. &amp;nbsp;Don&#39;t forget to exclude the semicolon&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;//Only prototypes have semicolons&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;HA! &amp;nbsp;NO PROTOTYPE!&quot;;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; function(); //It works like a normal function now.&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The other programming concept is the inline function. &amp;nbsp;Inline functions are not very important,&lt;br /&gt;
&lt;br /&gt;
but it is good to understand them. &amp;nbsp;The basic idea is to save time at a cost in space. &lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;How does an inline function make the program go faster? &amp;nbsp;How does it make the program larger?&lt;br /&gt;
&lt;br /&gt;
Does this remind you of relativity? &amp;nbsp;Inline functions are really a lot like a placeholder. &amp;nbsp;Once&lt;br /&gt;
&lt;br /&gt;
you define an inline function,using the &#39;inline&#39; keyword, whenever you call that function the&lt;br /&gt;
&lt;br /&gt;
compiler will replace the function call with the actual code from the function. &amp;nbsp;How does this&lt;br /&gt;
&lt;br /&gt;
make the program go faster? &amp;nbsp;Simple, function calls are simply more time consuming than writing&lt;br /&gt;
&lt;br /&gt;
all of the code without functions. &amp;nbsp;However, to go through your program and replace a function&lt;br /&gt;
&lt;br /&gt;
you have used 100 times with the code from the function would be time consuming. &amp;nbsp;Of course, by&lt;br /&gt;
&lt;br /&gt;
using the inline function to replace the function calls with code you will also greatly increase&lt;br /&gt;
&lt;br /&gt;
the size of your program. &lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Using the inline keyword is simple, just put it before the name of a function. &amp;nbsp;Then, when&lt;br /&gt;
&lt;br /&gt;
you use that function, just pretend it is a non-inline function. &amp;nbsp;For example:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
inline void hello(void) //Just use the inline keyword before the function&lt;br /&gt;
&lt;br /&gt;
{&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt; &amp;nbsp; &amp;nbsp;//Note that this is a non-prototyed function&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;hello&quot;;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; hello(); &amp;nbsp; //Call it like a normal function...&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;However, once the program is compiled, the call to hello(); will be replaced by the code&lt;br /&gt;
&lt;br /&gt;
making up the function. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;A WORD OF WARNING: Inline functions are very good for saving time, but if you use them too often&lt;br /&gt;
&lt;br /&gt;
or with large functions &amp;nbsp;you will have a tremendously large program. &amp;nbsp;Sometimes large programs are&lt;br /&gt;
&lt;br /&gt;
actually less efficient, and therefore they will run slower than before. &amp;nbsp;Inline functions are best&lt;br /&gt;
&lt;br /&gt;
for small functions that are called often. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;In the future we will discuss inline functions in terms of C++ classes. &amp;nbsp;However, now that&lt;br /&gt;
&lt;br /&gt;
you understand the concept I will feel comfortable using inline functions in later tutorials. &lt;br /&gt;
&lt;br /&gt;
At this point I do not wish to add something about classes that individuals could easily miss if&lt;br /&gt;
&lt;br /&gt;
they did not realize that the information was in the tutorial.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Note: My homepage is&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;My email is&amp;nbsp;&lt;a href=&quot;mailto:webmaster@madezee.com&quot;&gt;webmaster@madezee.com&lt;/a&gt;. &amp;nbsp;Please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me with comments and or suggestions. &amp;nbsp;If you want to use this on your own site please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me and add a link to&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;Thanks :)&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/6361458937091924316/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-13-more-on-functions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/6361458937091924316'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/6361458937091924316'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-13-more-on-functions.html' title='Lesson 13: More on Functions'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-2322254194023784744</id><published>2011-05-01T12:38:00.001-07:00</published><updated>2011-05-01T12:38:38.897-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="arrays"/><category scheme="http://www.blogger.com/atom/ns#" term="computer programming"/><category scheme="http://www.blogger.com/atom/ns#" term="cpp"/><category scheme="http://www.blogger.com/atom/ns#" term="e-learning"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="Introduction to Classes"/><category scheme="http://www.blogger.com/atom/ns#" term="online course"/><category scheme="http://www.blogger.com/atom/ns#" term="online learning"/><category scheme="http://www.blogger.com/atom/ns#" term="strings"/><category scheme="http://www.blogger.com/atom/ns#" term="structures"/><category scheme="http://www.blogger.com/atom/ns#" term="Typcasting"/><title type='text'>Lesson 12: Introduction to Classes</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Lesson 12: Introduction to Classes&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;C++ is a bunch of small additions to C, and one major addition. &amp;nbsp;This one addition is the&lt;br /&gt;
object oriented approach. &amp;nbsp;As its name suggests, this deals with objects. &amp;nbsp;Of course, these are&lt;br /&gt;
not real-life objects. &amp;nbsp;Instead, this objects are the essential definitions of real world&lt;br /&gt;
objects, or people. &amp;nbsp;Structures are one step away from these objects, they do not possess one&lt;br /&gt;
element of them: functions. &amp;nbsp;The definition of these objects are called classes. &amp;nbsp;The easiest&lt;br /&gt;
way to think about a class is to imagine a structure that has functions. &lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;What is this mysterious structure? &amp;nbsp;Well, it is not only a collection of variables under&lt;br /&gt;
one heading, but it is a collection of functions under that same heading. &amp;nbsp;If the structure is&lt;br /&gt;
a house, then the functions will be the doors. &amp;nbsp;They usually will be the only way to modify the&lt;br /&gt;
variables in this structure, and they are usually the only to to access the variables in this&lt;br /&gt;
structure. &lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;From now on, we shall call these structures with functions classes(I guess Marx would not&lt;br /&gt;
like C++). &amp;nbsp;The syntax for these classes is simple. &amp;nbsp;First, you put the keyword &#39;class&#39; then&lt;br /&gt;
the name of the class. &amp;nbsp;Our example will use the name computer. &amp;nbsp;Then you put the different&lt;br /&gt;
variables you want the class to hold. &amp;nbsp;In our example, there will be only one, processor speed.&lt;br /&gt;
However, before putting down the different variable, it is necessary to put the degree of&lt;br /&gt;
restriction on the variable. &amp;nbsp;There are three levels of restriction. &amp;nbsp;The first is public, the&lt;br /&gt;
second protected, and the third private. &amp;nbsp;For now, all you need to know is that the public&lt;br /&gt;
specifier allows any part of the program, including what is not part of the class, access the&lt;br /&gt;
variables specified as public. &amp;nbsp;The private specifier allows only the functions of the class&lt;br /&gt;
that owns (not a technical term) the variable to access that variable.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class computer //Standard way of defining the class&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;private: //This means that all the variables under this, until a new type of restriction is &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;//placed, will only be accessible to functions that are part of this class.&lt;br /&gt;
&amp;nbsp;//NOTE: That is a colon, NOT a semicolon...&lt;br /&gt;
&amp;nbsp;int processorspeed;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;public: //This means that all of the functions below this(and variables, if there were any) &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; //are accessible to the rest of the program.&lt;br /&gt;
&amp;nbsp;//NOTE: That is a colon, NOT a semicolon...&lt;br /&gt;
&amp;nbsp;void setspeed(int p); //These two functions will be defined outside the class&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;int readspeed();&lt;br /&gt;
};&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt; &amp;nbsp; //Don&#39;t forget the trailing semi-colon&lt;br /&gt;
&lt;br /&gt;
void computer::setspeed(int p) //To define a function outside put the name of the function&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt; &amp;nbsp; //after the return type and then two colons, and then the name&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt; &amp;nbsp; //of the function.&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; processorspeed = p;&lt;br /&gt;
}&lt;br /&gt;
int computer::readspeed() &amp;nbsp;//The two colons simply tell the compiler that the function is part&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt; &amp;nbsp; //of the class&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; return processorspeed;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; computer compute; &amp;nbsp;//To create an &#39;instance&#39; of the function, simply treat it like you would &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt; //a structure. &amp;nbsp;(An instance is simply when you create an actual object&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt; //from the class, as opposed to having the definition of the class)&lt;br /&gt;
&amp;nbsp; compute.setspeed(100); &amp;nbsp;//To call functions in the class, you put the name of the instance,&lt;br /&gt;
&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt; &amp;nbsp;//and then the function name.&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;compute.readspeed(); //See above note.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
As you can see, this is a rather simple concept. &amp;nbsp;However, it is very powerful. &amp;nbsp;It makes it&lt;br /&gt;
easy to prevent variables that are contained(or owned) by the class being overwritten&lt;br /&gt;
accidentally. &amp;nbsp;It also allows a totally different way of viewing programming. &amp;nbsp;However, I want&lt;br /&gt;
to end this tutorial as an introduction. &amp;nbsp;I am going to be writing more tutorials on classes,&lt;br /&gt;
which will go into more details on classes.&lt;br /&gt;
&lt;br /&gt;
PLEASE send comments on this tutorial. &amp;nbsp;It was written much after all the others had been&lt;br /&gt;
written, and I am want to ensure that I am upholding the standard of the previous tutorials. &amp;nbsp;I&lt;br /&gt;
want to be certain this tutorial is clear. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Note: My homepage is&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;My email is&amp;nbsp;&lt;a href=&quot;mailto:webmaster@madezee.com&quot;&gt;webmaster@madezee.com&lt;/a&gt;. &amp;nbsp;Please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me with comments and or suggestions. &amp;nbsp;If you want to use this on your own site please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me and add a link to&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;Thanks :)&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/2322254194023784744/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-12-introduction-to-classes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/2322254194023784744'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/2322254194023784744'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-12-introduction-to-classes.html' title='Lesson 12: Introduction to Classes'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-3679839589034075463</id><published>2011-05-01T12:37:00.002-07:00</published><updated>2011-05-01T12:37:55.574-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="arrays"/><category scheme="http://www.blogger.com/atom/ns#" term="computer programming"/><category scheme="http://www.blogger.com/atom/ns#" term="cpp"/><category scheme="http://www.blogger.com/atom/ns#" term="e-learning"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="File I/O"/><category scheme="http://www.blogger.com/atom/ns#" term="online course"/><category scheme="http://www.blogger.com/atom/ns#" term="online learning"/><category scheme="http://www.blogger.com/atom/ns#" term="strings"/><category scheme="http://www.blogger.com/atom/ns#" term="structures"/><category scheme="http://www.blogger.com/atom/ns#" term="Typcasting"/><title type='text'>Lesson 11: Typcasting</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Lesson 11: Typcasting&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Admitedly, typecasting is not a huge part of C or C++ programming. &amp;nbsp;However, there are times&lt;br /&gt;
when it is actually the best, or perhaps only, way to accomplish something. &amp;nbsp;Typecasting is&lt;br /&gt;
basically turning a variable of one type, say an int, into another type, a char, for one a single&lt;br /&gt;
application. &lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Typecasts look like a data-type, like int, in between two parentheses. (char)aninteger will&lt;br /&gt;
interpreted as a character for purposes of the function.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt; //For cout&lt;br /&gt;
&lt;br /&gt;
void main() &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;(char)65; //The (char) is a type cast, telling the computer to interpret the 64 as a&lt;br /&gt;
&amp;nbsp; //character, not as a number. &amp;nbsp;It is going to give the ASCII output of the&lt;br /&gt;
&amp;nbsp; //equivalent of the number 64(It should be the letter A).&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;One use of typecasting is when you want to use the ASCII characters. &amp;nbsp;For example, what if&lt;br /&gt;
you want to create your own chart of all 255 ASCII characters. &amp;nbsp;To do this, you will need to use&lt;br /&gt;
a typecast to allow you to print out the integer as a character.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include &amp;lt;conio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; for(int x=1; x&amp;lt;256; x++) //The ASCII character set is from 1 to 255&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;&quot;. &quot;&amp;lt;&amp;lt;(char)x&amp;lt;&amp;lt;&quot; &quot;; //Note the use of the int version of x to output a number&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;//and the use of (char) to typecast the x into a character&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt; //which outputs the ASCII character that corresponds to the&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt; //current number&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&amp;nbsp; getch();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;You can make a version of this program that will allow the user to enter a number, and the&lt;br /&gt;
program could give the user the character corresponding to the number. &lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Typecasting is more useful than this, but this was just an introduction. &amp;nbsp;Admittedly, not&lt;br /&gt;
the most advanced lesson, but one that can be very useful none-the-less.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Note: My homepage is&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;My email is&amp;nbsp;&lt;a href=&quot;mailto:webmaster@madezee.com&quot;&gt;webmaster@madezee.com&lt;/a&gt;. &amp;nbsp;Please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me with comments and or suggestions. &amp;nbsp;If you want to use this on your own site please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me and add a link to&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;Thanks :)&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/3679839589034075463/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-11-typcasting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/3679839589034075463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/3679839589034075463'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-11-typcasting.html' title='Lesson 11: Typcasting'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-947031237627220224</id><published>2011-05-01T12:37:00.000-07:00</published><updated>2011-05-01T12:37:14.139-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="arrays"/><category scheme="http://www.blogger.com/atom/ns#" term="computer programming"/><category scheme="http://www.blogger.com/atom/ns#" term="cpp"/><category scheme="http://www.blogger.com/atom/ns#" term="e-learning"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="File I/O"/><category scheme="http://www.blogger.com/atom/ns#" term="online course"/><category scheme="http://www.blogger.com/atom/ns#" term="online learning"/><title type='text'>Lesson 10: File I/O(part 1)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Lesson 10: File I/O(part 1)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;This is a slightly more advanced topic than what I have covered so far, but I think that it&lt;br /&gt;
is useful, and I think it will be useful to many people. &amp;nbsp;File i/o is basically reading, and&lt;br /&gt;
writing files. &amp;nbsp;This lesson will only cover text files, that is, files that are readable&lt;br /&gt;
through a text editor, as opposed to binary files(exes for example). &amp;nbsp;It will not cover a great&lt;br /&gt;
deal, for example, this lesson will not deal with searching files or reading specific data from&lt;br /&gt;
files. &amp;nbsp;It will merely be concerned with opening, writing, and reading text files. &amp;nbsp;Don&#39;t worry&lt;br /&gt;
though, lesson 11 will cover much more on this topic.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Well, how does it all start anyway? &amp;nbsp;Files have their own specific functions to use, as&lt;br /&gt;
well as their own data-type, called a FILE(There is more to this, but right not it is not&lt;br /&gt;
important, and it will be explained later, when it is useful). &amp;nbsp;The way to use the FILE type is&lt;br /&gt;
the same way as using an integer, or a float, or a char:&lt;br /&gt;
&lt;br /&gt;
FILE *newfile; //Creates a FILE called newfile(don&#39;t forget that it is a pointer)&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Now, we can&#39;t use this unless there is a way to give the FILE(*newfile) a file to point to. &lt;br /&gt;
The way this works is that it is what is called a stream. &amp;nbsp;That means that it is where the&lt;br /&gt;
output will go to. &amp;nbsp;To direct *newfile to a file the command to use is FILE *fopen(const char&lt;br /&gt;
*filename, const char *mode), found in stdio.h. &amp;nbsp;It simply returns a pointer to a FILE, but it is easy enough to use. &amp;nbsp;For example:&lt;br /&gt;
&lt;br /&gt;
FILE *newfile: //Creates a FILE called newfile&lt;br /&gt;
newfile=fopen(&quot;c:\AUTOEXEC.BAT&quot;, &quot;r&quot;);//open up for reading your autoexec.bat file, and assign &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;         &lt;/span&gt; &amp;nbsp;//it to newfile&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Basically, fopen accepts two strings. &amp;nbsp;One of them is the file name, including the path,and&lt;br /&gt;
the other is what the file will be used for(the mode). &amp;nbsp;In this case, the r designates the file will only be opened for reading. &amp;nbsp;Therefore, the file cannot be modified while it is open. &amp;nbsp;That is probably a good idea, because editing your autoexec.bat file with giberish is not a good idea!&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;For a reference here is a chart listing the different ways you open a file:&lt;br /&gt;
&lt;br /&gt;
r&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Open for reading only.&lt;br /&gt;
&lt;br /&gt;
w&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Creates a file for writing. If a file by that name already exists, it will be overwritten.&lt;br /&gt;
&lt;br /&gt;
a&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Append; open for writing at the end of the file, or create the file if it does not exist.&lt;br /&gt;
&lt;br /&gt;
r+&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Open an existing file for reading and writing.&lt;br /&gt;
&lt;br /&gt;
w+&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Create a new file for reading and writing. If a file by that name already exists, it will&lt;br /&gt;
&amp;nbsp; &amp;nbsp; be overwritten.&lt;br /&gt;
&lt;br /&gt;
a+&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Open for append; open (or create if the file does not exist) for update at the end of the&lt;br /&gt;
&amp;nbsp; &amp;nbsp; file.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Keep in mind that each of these has a different use, and that you should choose the one&lt;br /&gt;
most appropriate for you task. &amp;nbsp;For now however, lets concentrate on reading a file.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Now, let&#39;s say you want to print the contents of autoexec.bat to your screen. &amp;nbsp;Assuming you&lt;br /&gt;
want to make a program to do this you would need a function for reading from a file. &amp;nbsp;There are numerous useful ones, but for now we will use int fgetc(FILE *stream)(Note that it returns an int, but the range will still be printable(so it is the same as a char), defined in iostream.h. &amp;nbsp;Basically, fgetc will get the next character from a file you give it(that is, the stream you give it). &amp;nbsp;An example would be the following code to display the first few characters of your autoexec.bat file:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt; //For cout&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt; &amp;nbsp;//For all file i/o functions&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; int count=0; //Just a variable to keep from reading the file forever.&lt;br /&gt;
&amp;nbsp; FILE *afile; &amp;nbsp;//We need a FILE to point to the stream to allow access to the fil&lt;br /&gt;
&amp;nbsp; afile=fopen(&quot;c:/AUTOEXEC.BAT&quot;, &quot;r&quot;); //Open up the autoexec.bat file for reading&lt;br /&gt;
&amp;nbsp; //No, I do not know why it must be a forward slash.&lt;br /&gt;
&amp;nbsp; while(count&amp;lt;10)&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;(char)fgetc(afile); //Notice that fgetc returns an int, which can be printed.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//Please note the use of (char) to &#39;typecast&#39; the returned integer. &amp;nbsp;That means that it makes&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//it into a printable character from the number. &amp;nbsp;There is more on this in lesson 11, which&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//I suggest you read.(Note that chars basically convert their ASCII numbers into the&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//appropriate printable characters. &amp;nbsp;65=&#39;A&#39; for example.&lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
&amp;nbsp; count++; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//I don&#39;t think it should read forever, right?&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&amp;nbsp; fclose(afile);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//A surprise(don&#39;t worry, just use it to close a file when done).&lt;br /&gt;
&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;//Just put in the pointer to the stream(the FILE thingy)&lt;br /&gt;
&amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;This program is fairly simple, and it does not take advantage of many of C&#39;s more useful&lt;br /&gt;
file operations. &amp;nbsp;Note though, that it is going to print out only a few characters. &amp;nbsp;What if you wanted to print the entire file out, though? &amp;nbsp;Well, that is where a thing called the EOF(end-of-file) comes into play. &amp;nbsp;It is essentially a null that will signal the end of the file has been reached. &lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;So, how would you make a program to use this? &amp;nbsp;Well, fgetc retrieves a character from the&lt;br /&gt;
file, and it will return the EOF when it reaches the end of the file. &amp;nbsp;Now, it is possible to use a loop that will check to see if the last character is equal to the EOF. &amp;nbsp;For example, CHARACTERREAD!=EOF. &amp;nbsp;This would return true if the CHARACTERREAD is not the EOF.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Here&#39;s how I would do it:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt; //For cout&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt; &amp;nbsp; //For all file i/o functions&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;FILE *afile; &amp;nbsp; //We need to define a FILE type to open a file&lt;br /&gt;
&amp;nbsp;afile=fopen(&quot;c:/AUTOEXEC.BAT&quot;, &quot;r&quot;); &amp;nbsp;//Opens autoexec.bat, only to read, not write it. &amp;nbsp;afile&lt;br /&gt;
&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;         &lt;/span&gt; &amp;nbsp; //is now &amp;nbsp;the stream pointing to the file autoexec.bat,&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;         &lt;/span&gt; &amp;nbsp; //and is used to do operations with autoexec.bat&lt;br /&gt;
&amp;nbsp;char c; &amp;nbsp; &amp;nbsp; //Without a character to store the information the program won&#39;t work&lt;br /&gt;
&amp;nbsp;while(c!=EOF) //Checking to see if the character just read is the end of the file&lt;br /&gt;
&amp;nbsp;{&lt;br /&gt;
&amp;nbsp; &amp;nbsp;c=fgetc(afile); //This reads in the character&lt;br /&gt;
&amp;nbsp; &amp;nbsp;//Note that it is not necessary to typecast the fgetc return, as it is automatically turned&lt;br /&gt;
&amp;nbsp; &amp;nbsp;//into a printable character when char c is a character.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;c; //The prints out the character(as you SHOULD know!)&lt;br /&gt;
&amp;nbsp;}&lt;br /&gt;
&amp;nbsp;fclose(afile); //Just to be safe, close the file!&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Ok, so you finally got it to print out! &amp;nbsp;Well, what is the next thing to do? &amp;nbsp;Why not have&lt;br /&gt;
a program to make a backup of autoexec.bat? &amp;nbsp;There is a new function that you will need to add to your repetoire before this can be done. &amp;nbsp;The new function is fputc, defined in stdio.h. &amp;nbsp;int futc(int c, FILE *filethinghere);. &amp;nbsp;Basically, it will return the character given to it, or it will return an EOF. &amp;nbsp;It accepts a character as the first argument, and a pointer to a stream(the FILE thing) as the second argument. &amp;nbsp;Here is an example of how to use it:&lt;br /&gt;
&lt;br /&gt;
fputc(&#39;A&#39;, newfile); //Writes the character &#39;A&#39; to the file pointed to by newfile&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;However, don&#39;t forget that this does not always work. &amp;nbsp;The file the stream points to has to&lt;br /&gt;
have been opened for writing, not just reading. &amp;nbsp;Usually you will want to append to a file, but in the case of our next example we want to create a new file, and overwrite an old one.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Now that we have a function to print to a file, why not finish up with one program to&lt;br /&gt;
backup autoexec.bat. &amp;nbsp;Basically, we will use the same loop as in the first function, that is, checking to see if the end of the file is reached, otherwise it will continue to print out characters. &amp;nbsp;This time however, it will not print the characters to the screen. &amp;nbsp;Instead, it will print the characters to another file(In the example, backup.aut).&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------------------------------&lt;br /&gt;
WARNING: If you currently have a file called backup.aut you will have it overwritten! &amp;nbsp;DO NOT run the example program if you have the file backup.aut in the directory with your compiler! &amp;nbsp;Otherwise, you will hae it overwritten.&lt;br /&gt;
-----------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt; //Needed for file i/o functions(including fopen!)&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; FILE *autoexec, *backup; //There are two files this time, the AUTOEXEC.BAT and the backup &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;       &lt;/span&gt;// file&lt;br /&gt;
&amp;nbsp; autoexec=fopen(&quot;c:\AUTOEXEC.BAT&quot;, &quot;r&quot;);//Open autoexec.bat to read the file&lt;br /&gt;
&amp;nbsp; backup=fopen(&quot;backup.aut&quot;, &quot;w&quot;); //Create(or overwrite)backup.aut for writing&lt;br /&gt;
&amp;nbsp; char c; &amp;nbsp;//We need a buffer for reading in the charactesr&lt;br /&gt;
&amp;nbsp; while(c!=EOF) &amp;nbsp;//Just checking to see if it&#39;s the end of the file&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; c=fgetc(autoexec); //Reading in a character from autoexec.bat&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;fputc(c, backup); //Writing a character to the backup file!&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&amp;nbsp; fclose(autoexec);&lt;br /&gt;
&amp;nbsp; fclose(backup); &amp;nbsp;//Closing the files to finish it all up!&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Wow! &amp;nbsp;It&#39;s a program that could be useful. &amp;nbsp;Feel free to use it anytime you like. &amp;nbsp;Just&lt;br /&gt;
remember how it works. &amp;nbsp;Don&#39;t think this is the end of the file i/o information. &amp;nbsp;There is more, but for now this should be enough to whet your appetite. &amp;nbsp;Oh, and you case use fputc to write user input to a file also! &amp;nbsp;I think you can figure it out!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Note: My homepage is&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;My email is&amp;nbsp;&lt;a href=&quot;mailto:webmaster@madezee.com&quot;&gt;webmaster@madezee.com&lt;/a&gt;. &amp;nbsp;Please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me with comments and or suggestions. &amp;nbsp;If you want to use this on your own site please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me and add a link to&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;Thanks :)&lt;/div&gt;&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/947031237627220224/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-10-file-iopart-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/947031237627220224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/947031237627220224'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-10-file-iopart-1.html' title='Lesson 10: File I/O(part 1)'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-3460385312675527041</id><published>2011-05-01T12:36:00.000-07:00</published><updated>2011-05-01T12:36:20.747-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="computer training"/><category scheme="http://www.blogger.com/atom/ns#" term="cpp"/><category scheme="http://www.blogger.com/atom/ns#" term="e-learning"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="online course"/><category scheme="http://www.blogger.com/atom/ns#" term="online learning"/><category scheme="http://www.blogger.com/atom/ns#" term="strings"/><title type='text'>Lesson 9: Strings</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Lesson 9: Strings&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;This lesson is one on strings. &amp;nbsp;Strings are really arrays, but there are some different&lt;br /&gt;
functions that are used for strings, like adding to strings, finding the length of strings, and&lt;br /&gt;
also of checking to see if strings match. &amp;nbsp;Strings are basically sentences, or words. &amp;nbsp;Like,&lt;br /&gt;
&quot;This is a string&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Strings are basically character arrays. &amp;nbsp;For example, to declare a string of 50 letters, you&lt;br /&gt;
would want to say:&lt;br /&gt;
&lt;br /&gt;
char string[50];&lt;br /&gt;
&lt;br /&gt;
This would declare a string with a length of 50 characters. &amp;nbsp;Don&#39;t forget that arrays begin at&lt;br /&gt;
0, not 1 for the index-number. &amp;nbsp;Also, a string ends with a null character, literally a &#39;/0&#39;&lt;br /&gt;
character. &amp;nbsp;But, just remember that there will be an extra character on the end on a string. &amp;nbsp;It&lt;br /&gt;
is like a period at the end of a sentence, it is not counted as a letter, but it still takes up&lt;br /&gt;
a space.&lt;br /&gt;
&lt;br /&gt;
What are strings useful for? &amp;nbsp;Well, for one thing, you might want to get a person&#39;s name. &amp;nbsp;If you&lt;br /&gt;
wanted to, you would need a string, because a name can&#39;t fit in one variable! &amp;nbsp;It is, however, a&lt;br /&gt;
collection of characters, and so fits nicely into a character array. &lt;br /&gt;
&lt;br /&gt;
Now, what if you want to input a string? &amp;nbsp;Well, if you try to use cin&amp;gt;&amp;gt; then it won&#39;t work! &amp;nbsp;It&lt;br /&gt;
terminates at the first space. &amp;nbsp;However, you can use the function gets(char *s);&lt;br /&gt;
.&lt;br /&gt;
&lt;br /&gt;
Gets is basically a function that reads in a string and stops reading at the first new-line, for&lt;br /&gt;
example, when a user hits enter. &amp;nbsp;Gets is in stdio.h. All you do, is put the name of the array and it will work out,&lt;br /&gt;
because the pointer char *s is basically one way you tell a function that you will be passing an&lt;br /&gt;
array, although it is a pointer, it is still the string you give. &amp;nbsp;Essentially, char *s points to&lt;br /&gt;
a string, and you can access this string just like an array. &lt;br /&gt;
&lt;br /&gt;
I will touch upon this relationship as described above in another lesson that will be a more&lt;br /&gt;
advanced lesson on pointers and arrays. &lt;br /&gt;
&lt;br /&gt;
Anyway, to get a string from a user you want to use gets. &amp;nbsp;An example program of this would be:&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//For gets&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;//For all other input/output functions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; char astring[50]; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //This declares a character array that can be used as a string&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Please enter a string&quot;; &amp;nbsp;//You should know this one!&lt;br /&gt;
&amp;nbsp; gets(astring); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//The user will input a string(with spaces)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;You input: &quot;&amp;lt;&amp;lt;endl;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;//You know this one too!&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;astring; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;//This is how you output character arrays, but not others!&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Ok, thats pretty simple. &amp;nbsp;But, what if you want to use some of the nifty functions from string.h?&lt;br /&gt;
&lt;br /&gt;
Well, these include the following functions:&lt;br /&gt;
&lt;br /&gt;
int strcmp(const char *s1, const char *s2);&lt;br /&gt;
&lt;br /&gt;
strcmp will accept two strings. &amp;nbsp;It will return an integer. &amp;nbsp;This integer will either be:&lt;br /&gt;
Negative if s1 is less than s2.&lt;br /&gt;
Zero if s1 and s2 are equal.&lt;br /&gt;
Positive if s1 is greater than s2.&lt;br /&gt;
&lt;br /&gt;
Strcmp is case sensitive.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int strcmpi(const char *s1, const char *s2);&lt;br /&gt;
&lt;br /&gt;
strcmp will accept two strings. &amp;nbsp;It will return an integer. &amp;nbsp;This integer will either be:&lt;br /&gt;
Negative if s1 is less than s2.&lt;br /&gt;
Zero if the s1 and s2 are equal.&lt;br /&gt;
Positive if s1 is greater than s2.&lt;br /&gt;
&lt;br /&gt;
Strcmpi is not case sensitive, if the words are capitalized it doesn&#39;t matter.&lt;br /&gt;
&lt;br /&gt;
char *strcat(char *desc, char *src);&lt;br /&gt;
&lt;br /&gt;
strcat is short for string cacatenate, which means to add to the end, or append. &amp;nbsp;It does just this,&lt;br /&gt;
the first string is what the second string is stuck on the end of. &amp;nbsp;It basically returns the&lt;br /&gt;
cacatenated string. &amp;nbsp;The first string will also have the entire string added to it.&lt;br /&gt;
&lt;br /&gt;
char *strupr(char *s);&lt;br /&gt;
&lt;br /&gt;
strupr converts a string to uppercase. &amp;nbsp;It also returns a string, which will all be in uppercase.&lt;br /&gt;
The input string, if it is an array, will also all be uppercase.&lt;br /&gt;
&lt;br /&gt;
char *strlwr(char *s);&lt;br /&gt;
&lt;br /&gt;
strlwr converts a string to lowercase. &amp;nbsp;It also returns a string, which will all be in uppercase.&lt;br /&gt;
The input string, if it is an array, will also all be uppercase.&lt;br /&gt;
&lt;br /&gt;
size_t strlen(const char *s);&lt;br /&gt;
&lt;br /&gt;
strlen will return the length of a string, minus the termating character(/0). &amp;nbsp;The size_t is&lt;br /&gt;
nothing to worry about. &amp;nbsp;Just treat it as an integer.&lt;br /&gt;
&lt;br /&gt;
Some of the stuff in the strings may be confusing. &amp;nbsp;The const char *s stuff, for example. &amp;nbsp;But,&lt;br /&gt;
just remember that basically all of that will be a string! &amp;nbsp;It doesn&#39;t matter what the code is&lt;br /&gt;
right now, just what the functions do.&lt;br /&gt;
&lt;br /&gt;
Now, a small program using many of the string functions!&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt; &amp;nbsp; //For cout&lt;br /&gt;
#include &amp;lt;string.h&amp;gt; &amp;nbsp; &amp;nbsp; //For many of the string functions&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;//For gets&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
&amp;nbsp; char name[50]; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Declare variables&lt;br /&gt;
&amp;nbsp; char lastname[50]; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//This could have been declared on the last line...&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Please enter your name: &quot;; &amp;nbsp; //Tell the user what to do&lt;br /&gt;
&amp;nbsp; gets(name); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Use gets to input strings with spaces or just to get strings after the user presses enter&lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
&amp;nbsp; if(!strcmpi(&quot;Alexander&quot;, name)) &amp;nbsp;//The ! means not, strcmpi returns 0 for equal strings&lt;br /&gt;
&amp;nbsp; { &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//strcmpi is not case sensitive&lt;br /&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;That&#39;s my name too.&quot;&amp;lt;&amp;lt;endl; //Tell the user if its my name&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&amp;nbsp; else &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//else is used to keep it from always outputting cout&amp;lt;&amp;lt;&quot;That&#39;s not my name.&quot;&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;That&#39;s not my name.&quot;&amp;lt;&amp;lt;endl;&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;What is your name in uppercase...&quot;&amp;lt;&amp;lt;endl;&lt;br /&gt;
&amp;nbsp; strupr(name); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //strupr converts the string to uppercase&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;name&amp;lt;&amp;lt;endl; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;And, your name in lowercase...&quot;&amp;lt;&amp;lt;endl;&lt;br /&gt;
&amp;nbsp; strlwr(name); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//strlwr converts the string to lowercase&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;name&amp;lt;&amp;lt;endl;&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Your name is &quot;&amp;lt;&amp;lt;strlen(name)&amp;lt;&amp;lt;&quot; letters long&quot;&amp;lt;&amp;lt;endl; &amp;nbsp;//strlen returns the length of the string&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Enter your last name:&quot;;&lt;br /&gt;
&amp;nbsp; gets(lastname); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//lastname is also a string&lt;br /&gt;
&amp;nbsp; strcat(name, &quot; &quot;);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;//We want to space the two names apart&lt;br /&gt;
&amp;nbsp; strcat(name, lastname); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Now we put them together,we a space in the middle&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Your full name is &quot;&amp;lt;&amp;lt;name; //Outputting it all...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Note: My homepage is&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;My email is&amp;nbsp;&lt;a href=&quot;mailto:webmaster@madezee.com&quot;&gt;webmaster@madezee.com&lt;/a&gt;. &amp;nbsp;Please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me with comments and or suggestions. &amp;nbsp;If you want to use this on your own site please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me and add a link to&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;Thanks :)&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/3460385312675527041/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-9-strings.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/3460385312675527041'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/3460385312675527041'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-9-strings.html' title='Lesson 9: Strings'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-9129947184556102242</id><published>2011-05-01T12:35:00.001-07:00</published><updated>2011-05-01T12:35:40.104-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="arrays"/><category scheme="http://www.blogger.com/atom/ns#" term="computer programming"/><category scheme="http://www.blogger.com/atom/ns#" term="computer training"/><category scheme="http://www.blogger.com/atom/ns#" term="cpp"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="online course"/><category scheme="http://www.blogger.com/atom/ns#" term="online learning"/><title type='text'>Lesson 8: Array basics</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Lesson 8: Array basics&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This is the eight installment of my lessons, and it is on arrays. &amp;nbsp;Arrays are essentially a way&lt;br /&gt;
to store many values under the same name. &amp;nbsp;You can make an array out of any data-type,&lt;br /&gt;
including structures. &amp;nbsp;For example, you could say&lt;br /&gt;
&lt;br /&gt;
int examplearray[100]; &amp;nbsp;//This declares an array&lt;br /&gt;
&lt;br /&gt;
This would make an integer array with 100 slots, or places to store values. The only difficult&lt;br /&gt;
thing is that it starts off with the first index-number, that is, the number that you put in&lt;br /&gt;
the brackets to access a certain element, is zero, not one!&lt;br /&gt;
&lt;br /&gt;
Think about arrays like this: [][][][][][] &amp;nbsp; Each of the slots is a slot in the array, and&lt;br /&gt;
you can put information into each one of them. &amp;nbsp;It is like a group of variables side by side&lt;br /&gt;
almost.&lt;br /&gt;
&lt;br /&gt;
What can you do with this simple knowledge? &amp;nbsp;Lets say you want to store a string, since C++ has&lt;br /&gt;
no built-in datatype for strings, in DOS, you can make an array of characters.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
char astring[100];&lt;br /&gt;
&lt;br /&gt;
Will allow you to declare a char array of 100 elements, or slots. &amp;nbsp;Then you could get it from&lt;br /&gt;
the user, and if the user types in a long string, it will all go in the array. &amp;nbsp;The neat thing&lt;br /&gt;
is that it is very easy to work with strings in this way, and there is even a header file&lt;br /&gt;
called STRING.H. &amp;nbsp;I will have a lesson in the future on the functions in string.h, but for now,&lt;br /&gt;
lets concentrate on arrays.&lt;br /&gt;
&lt;br /&gt;
The most useful aspect of arrays is multidimensional arrays. &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
int twodimensionalarray[8][8];&lt;br /&gt;
&lt;br /&gt;
Think about multidimensional arrays:&lt;br /&gt;
&lt;br /&gt;
[][][][][]&lt;br /&gt;
[][][][][]&lt;br /&gt;
[][][][][]&lt;br /&gt;
[][][][][]&lt;br /&gt;
[][][][][]&lt;br /&gt;
&lt;br /&gt;
This is a graphic of what a two-dimensional array looks like when I visualize it.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&lt;br /&gt;
declares an array that has two dimensions. &amp;nbsp;Think of it as a chessboard. &amp;nbsp;You can easily use&lt;br /&gt;
this to store information about some kind of game, or write something like tic-tac-toe. &amp;nbsp;To&lt;br /&gt;
access it, all you need are two variables, one that goes in the first slot, one that goes in&lt;br /&gt;
the slot. &amp;nbsp;You can even make a three dimensional array, though you probably won&#39;t need to. &amp;nbsp;In&lt;br /&gt;
fact, you could make a four-hundred dimensional array. &amp;nbsp;It is just is very confusing to visualize.&lt;br /&gt;
&lt;br /&gt;
Now, arrays are basically treated like any other variable. You can modify one value in it by&lt;br /&gt;
putting:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;arrayname[arrayindexnumber]=whatever; &lt;br /&gt;
&lt;br /&gt;
You will find lots of useful things to do with arrays, from store information about certain&lt;br /&gt;
things under one name, to making games like tic-tac-toe. &amp;nbsp;One little tip I have is that you use&lt;br /&gt;
for loops to access arrays. &amp;nbsp;It is easy:&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; int x, y, anarray[8][8];//declares an array like a chessboard&lt;br /&gt;
&amp;nbsp; for(x=0; x&amp;lt;8; x++)&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for(y=0; y&amp;lt;8; y++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; anarray[x][y]=0;//sets all members to zero once loops is done&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&amp;nbsp; for(x=0; x&amp;lt;8;x++)&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for(y=0; y&amp;lt;8; y++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;anarray[&quot;&amp;lt;&amp;lt;x&amp;lt;&amp;lt;&quot;][&quot;&amp;lt;&amp;lt;y&amp;lt;&amp;lt;&quot;]=&quot;&amp;lt;&amp;lt;anarray[x][y]&amp;lt;&amp;lt;&quot; &quot;;//you&#39;ll see&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Here you see that the loops work well because they increment the variable for you, and you only&lt;br /&gt;
need to increment by one. &amp;nbsp;It is simple, and you access the entire array, would you want to use&lt;br /&gt;
while loops?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Note: My homepage is&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;My email is&amp;nbsp;&lt;a href=&quot;mailto:webmaster@madezee.com&quot;&gt;webmaster@madezee.com&lt;/a&gt;. &amp;nbsp;Please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me with comments and or suggestions. &amp;nbsp;If you want to use this on your own site please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me and add a link to&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;Thanks :)&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/9129947184556102242/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-8-array-basics.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/9129947184556102242'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/9129947184556102242'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-8-array-basics.html' title='Lesson 8: Array basics'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-4783025367672025159</id><published>2011-05-01T12:34:00.003-07:00</published><updated>2011-05-01T12:34:58.253-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="computer programming"/><category scheme="http://www.blogger.com/atom/ns#" term="computer training"/><category scheme="http://www.blogger.com/atom/ns#" term="cpp"/><category scheme="http://www.blogger.com/atom/ns#" term="e-learning"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="online course"/><category scheme="http://www.blogger.com/atom/ns#" term="online learning"/><category scheme="http://www.blogger.com/atom/ns#" term="structures"/><title type='text'>Lesson 7: Structures</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Lesson 7: Structures&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Welcome to the seventh lesson. &amp;nbsp;This is my first lesson that I will explain classes. &amp;nbsp;However,&lt;br /&gt;
I will explain more about structures, because they can be useful, and they are a good way&lt;br /&gt;
to get a feel for how a class works.&lt;br /&gt;
&lt;br /&gt;
What are structures? &amp;nbsp;They are a way to store more than one data-type under the same name.&lt;br /&gt;
Fore example:&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;string.h&amp;gt; //For strcpy&lt;br /&gt;
struct database&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; int age;&lt;br /&gt;
&amp;nbsp; char name[20];&lt;br /&gt;
&amp;nbsp; float salary;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; database employee;&lt;br /&gt;
&amp;nbsp; employee.age=22;&lt;br /&gt;
&amp;nbsp; strcpy(employee.name, &quot;Joe&quot;);&lt;br /&gt;
&amp;nbsp; employee.salary=12000.21;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Don&#39;t worry about the name[20]. &amp;nbsp;That is just an array. &amp;nbsp;It can hold more than one&lt;br /&gt;
character all called under the same name. &amp;nbsp;They are used like strings. &amp;nbsp;I will do my next&lt;br /&gt;
lesson on arrays, I promise, because they are very important. &amp;nbsp;The struct database declares&lt;br /&gt;
that database has three variables in it, age, name, and salary.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
Eventually, you can use database like a variable type like int. &amp;nbsp;You can create an employee&lt;br /&gt;
with the database type like I did above. &amp;nbsp;Then, to modify it you call everything with the&lt;br /&gt;
employee. in front of it. &amp;nbsp;You can also return structures from functions by defining their&lt;br /&gt;
return type as a structure type. &amp;nbsp;Example:&lt;br /&gt;
&lt;br /&gt;
struct database fn();&lt;br /&gt;
&lt;br /&gt;
You can make arrays of structures as well. &amp;nbsp; I will show you how to do this in lesson 8.&lt;br /&gt;
That will be up in a few days. &amp;nbsp;I suppose I should explain unions a little bit. &amp;nbsp;They are&lt;br /&gt;
like structures except that all the variables share the same memory. &amp;nbsp; When a union is&lt;br /&gt;
declared the compiler allocates enough memory for the largest data-type in the union.&lt;br /&gt;
&lt;br /&gt;
To access the union you use the . like in structures. &amp;nbsp;Also, if you are accessing the union&lt;br /&gt;
of structure through a pointer use the -&amp;gt; operator. &amp;nbsp;for example, database-&amp;gt;employee . &amp;nbsp;The&lt;br /&gt;
most useful thing about unions is that you can manipulate the bytes of the data-types. &amp;nbsp;You&lt;br /&gt;
might want to see what you can do if you understand that sort of stuff. &amp;nbsp;Personally, I have&lt;br /&gt;
never used a union.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Note: My homepage is&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;My email is&amp;nbsp;&lt;a href=&quot;mailto:webmaster@madezee.com&quot;&gt;webmaster@madezee.com&lt;/a&gt;. &amp;nbsp;Please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me with comments and or suggestions. &amp;nbsp;If you want to use this on your own site please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me and add a link to&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;Thanks :)&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/4783025367672025159/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-7-structures.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/4783025367672025159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/4783025367672025159'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-7-structures.html' title='Lesson 7: Structures'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-7576307644612758402</id><published>2011-05-01T12:34:00.001-07:00</published><updated>2011-05-01T12:34:03.376-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="computer programming"/><category scheme="http://www.blogger.com/atom/ns#" term="computer training"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="online course"/><category scheme="http://www.blogger.com/atom/ns#" term="online learning"/><title type='text'>Lesson 6: An introduction to pointers</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Lesson 6: An introduction to pointers&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Welcome to the sixth in my series of tutorials. &amp;nbsp;This is one about a topic that you may or&lt;br /&gt;
may not have already heard about...pointers. &amp;nbsp;What are they, what do they do, why do we&lt;br /&gt;
care? First, why do we care.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We care about pointers because they allow access to memory, the also make array-access&lt;br /&gt;
faster, they are also somewhat necessary to understand some functions. &amp;nbsp;Most importantly,&lt;br /&gt;
you will see them a lot in other people&#39;s code. &amp;nbsp;You may not need to use them much, but it&lt;br /&gt;
will be tremendously important to understand them.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Second, what do they do. &amp;nbsp;Well, I might as well address this issue as well as what they are&lt;br /&gt;
at the same time. &amp;nbsp;Pointers are what they sound like...pointers. &amp;nbsp;They point to locations&lt;br /&gt;
in memory. &amp;nbsp;Picture this: a big jar that holds one thing, the name of another jar. &amp;nbsp;In the&lt;br /&gt;
other jar is the value of an integer. &amp;nbsp;The jars are memory locations. &amp;nbsp;The jar that holds&lt;br /&gt;
the name of the other jar is a pointer. &amp;nbsp;It points to the other drawer.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How can you use this? &amp;nbsp;Well, look at this little piece of code:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; int x;&lt;br /&gt;
&amp;nbsp; int *pointer;&lt;br /&gt;
&amp;nbsp; pointer=&amp;amp;x; &lt;br /&gt;
&amp;nbsp; cin&amp;gt;&amp;gt;x;&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;*pointer;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Guess what! &amp;nbsp;The cout outputs the value in x. &amp;nbsp;Why is that? &amp;nbsp;Well, look at the code. &amp;nbsp;The&lt;br /&gt;
integer is called x. &amp;nbsp;Then a pointer to an integer is defined as pointer. &amp;nbsp;The astrick(*)&lt;br /&gt;
symbol means that it is a pointer. &amp;nbsp;Then I give the memory location of x to pointer by&lt;br /&gt;
using the ampersand(&amp;amp;) symbol. &amp;nbsp;It gives the memory location of the variable it is in front&lt;br /&gt;
of. &amp;nbsp;For example, if the jar that had an integer had a ampersand in it it would output its&lt;br /&gt;
name, or location.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Then the user inputs the value for x. &amp;nbsp;Then the cout uses the * to put the value stored in&lt;br /&gt;
the memory location of pointer. &amp;nbsp;Huh? &amp;nbsp;Picture the jars again. &amp;nbsp;If the jar with the name of&lt;br /&gt;
the other jar in it had a * in front of it it would give the value stored in the jar with&lt;br /&gt;
the same name as the one in the jar with the name. &amp;nbsp;It&#39;s not too hard, the * gives the&lt;br /&gt;
value in the location. &amp;nbsp;The unastricked gives the memory location.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
I hope this has been at least an interesting introduction to pointers. &amp;nbsp;I do not suggest&lt;br /&gt;
that you play around with them too much as you can do unpleasant things on your computer,&lt;br /&gt;
but you now should have a better understand of what they are.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Note: My homepage is&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;My email is&amp;nbsp;&lt;a href=&quot;mailto:webmaster@madezee.com&quot;&gt;webmaster@madezee.com&lt;/a&gt;. &amp;nbsp;Please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me with comments and or suggestions. &amp;nbsp;If you want to use this on your own site please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me and add a link to&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;Thanks :)&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/7576307644612758402/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-6-introduction-to-pointers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/7576307644612758402'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/7576307644612758402'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-6-introduction-to-pointers.html' title='Lesson 6: An introduction to pointers'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-3626045653315614217</id><published>2011-05-01T12:33:00.001-07:00</published><updated>2011-05-01T12:33:30.380-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="computer programming"/><category scheme="http://www.blogger.com/atom/ns#" term="computer training"/><category scheme="http://www.blogger.com/atom/ns#" term="cpp"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="online course"/><category scheme="http://www.blogger.com/atom/ns#" term="online learning"/><title type='text'>Lesson 5: switch...case</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Lesson 5: switch...case&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I know that this is probably a let-down, after you learned all about functions, but&lt;br /&gt;
switch...case is important to know. &amp;nbsp;After all, it can save space with if statements, and&lt;br /&gt;
it is useful. &amp;nbsp;Besides, I couldn&#39;t think of anything else that I wanted to write about.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Switch...case looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;switch(expression or variable)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;case it equals this:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;do this;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;break;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;case it equals this:&lt;br /&gt;
&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;do this;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;break;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;case it equals this:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;do this;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;break;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;...&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;default&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;do this&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So, it works like this. &amp;nbsp;The expression or variable has a value. &amp;nbsp;The case says that if it&lt;br /&gt;
has the value of whatever is after this case then do whatever follows the colon. &amp;nbsp;The break&lt;br /&gt;
says to break out of the case statements. &amp;nbsp;Break is a keyword that breaks out of the&lt;br /&gt;
code-block, surrounded by braces, that it is in. &amp;nbsp;So unless you want it to try the next&lt;br /&gt;
case then use break. --You can also use it to break out of loops, something that I failed&lt;br /&gt;
to mention at the time.--&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
What is it used for, the switch...case? &amp;nbsp;Well, let&#39;s say that you are writing a menu&lt;br /&gt;
program, then you would want to process some input, right? &amp;nbsp;Well, you would want to use a&lt;br /&gt;
switch...case statement to process more than one input, because it is more easily used than&lt;br /&gt;
if statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is an example program:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;#include &amp;lt;conio.h&amp;gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;void main()&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;br /&gt;
&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;char input;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;1. Play game&quot;;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;2. Load game&quot;;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;3. Play multiplayer&quot;;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;4. Exit&quot;;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;input=getch();&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//Remember I said you don&#39;t need many functions...&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;switch(input)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;case 1:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;playgame();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;case 2:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;loadgame();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;case 3:&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;//Note use of : not ;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;playmultiplayer();&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;case 4:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;default:&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;Error, bad input, quitting&quot;;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you are not understand this, then try putting in if statements for the case statements.&lt;br /&gt;
Also, the reason exit works with a break is that after you break out of the switch&lt;br /&gt;
statement then it would be the end of the program. &amp;nbsp;The same thing would be for default.&lt;br /&gt;
If you don&#39;t like that, then make a loop around the whole thing. &amp;nbsp;I know I did not&lt;br /&gt;
prototype the functions, but it was a very simple example. You could easily make a few&lt;br /&gt;
small functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Note: My homepage is&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;My email is&amp;nbsp;&lt;a href=&quot;mailto:webmaster@madezee.com&quot;&gt;webmaster@madezee.com&lt;/a&gt;. &amp;nbsp;Please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me with comments and or suggestions. &amp;nbsp;If you want to use this on your own site please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me and add a link to&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;Thanks :)&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/3626045653315614217/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-5-switchcase.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/3626045653315614217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/3626045653315614217'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-5-switchcase.html' title='Lesson 5: switch...case'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-218173439593994463</id><published>2011-05-01T12:32:00.001-07:00</published><updated>2011-05-01T12:32:51.507-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="computer programming"/><category scheme="http://www.blogger.com/atom/ns#" term="computer training"/><category scheme="http://www.blogger.com/atom/ns#" term="cpp"/><category scheme="http://www.blogger.com/atom/ns#" term="e-learning"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="online course"/><category scheme="http://www.blogger.com/atom/ns#" term="online learning"/><title type='text'>Lesson 4: Functions</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;Lesson 4: Functions&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that you have learned all about variables, loops, and if statements it is time to learn&lt;br /&gt;
the next thing in programming: Functions. &amp;nbsp;Obviously, you should have a good idea about&lt;br /&gt;
what a function is, as you have used ones like cout before. &amp;nbsp;However, this lesson will be&lt;br /&gt;
more in detail about not only functions that are already made, but about making your own,&lt;br /&gt;
or maybe I will continue this later...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A good way to describe a function is to show its prototype. &amp;nbsp;That means, what it should return,&lt;br /&gt;
and what it should take as an argument. &amp;nbsp;For example, the prototype of getch() is... int&lt;br /&gt;
getch(void); The int means that it returns an integer, the void means that it does not take an&lt;br /&gt;
argument. &amp;nbsp;Now, you may know that getch returns a character! &amp;nbsp;However, that does not mean it&lt;br /&gt;
must return a character. &amp;nbsp;The fact that the return type is an integer makes no difference,&lt;br /&gt;
because the ASCII character set does not care what type of number it is, as long as it is a&lt;br /&gt;
number...don&#39;t worry if you don&#39;t understand, it is not too important right now.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What is important is that you understand prototypes. &amp;nbsp;Another prototype is... int kbhit(void);&lt;br /&gt;
It returns an integer, and it takes no value. &amp;nbsp;Now that I hope you understand this then you&lt;br /&gt;
will be able to use the help files much more easily, and I can go into more about functions.&lt;br /&gt;
First, what functions are useful.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are many useful functions, and often they are hard to find. &amp;nbsp;For Turbo C++ Lite some&lt;br /&gt;
useful functions include, but are no limited to:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;cout&amp;lt;&amp;lt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt; &amp;nbsp; &amp;nbsp;iostream.h&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;output&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;cin&amp;gt;&amp;gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt; &amp;nbsp; &amp;nbsp;iostream.h&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;input&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int getch(void)&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;conio.h&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;get characters&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;void clrscr(void)&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;conio.h&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;clear screen&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Okay, you might be thinking that this is nothing! &amp;nbsp;Four measly functions, and you are&lt;br /&gt;
right! &amp;nbsp;If there were only a few functions then C/C++ would not be useful. &amp;nbsp;However, a lot&lt;br /&gt;
of programs do not need all that many functions. &amp;nbsp;Of course, I suggest that you know ever&lt;br /&gt;
function that you can, or at least the name. &amp;nbsp;For this purpose, I will be posting an entire&lt;br /&gt;
listing of ever function that I can find out of either help or books I have read. &amp;nbsp;However,&lt;br /&gt;
for now, these are probably the most useful functions. &amp;nbsp;After all, if you can clear the&lt;br /&gt;
screen, get input and output, and get keypresses, which are useful for stopping the program&lt;br /&gt;
from immediately going back to the IDE you can do quite a bit! &amp;nbsp;Believe me, there are a few&lt;br /&gt;
specialized, but very useful functions, the thing is, you don&#39;t really need to use them all&lt;br /&gt;
the time! &amp;nbsp;If you have a problem with a function that you need, and I have not put up my&lt;br /&gt;
list yet, then email me at webmaster@madezee.com, and I will find you what you need!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Anyway, after that long spiel on not needing a lot of functions, I am going to show you how&lt;br /&gt;
to make your own functions! &amp;nbsp;Wow, I can do that? &amp;nbsp;Of course, otherwise C/C++ would not be&lt;br /&gt;
useful! &amp;nbsp;So, prepare to learn how to make functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First let me give you an entire example program. &amp;nbsp;Then we will look at it, and learn how to&lt;br /&gt;
make our own programs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include &amp;lt;conio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int mult(int x, int y);&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; int x, y;&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Input a number, and what number to multiply it by&quot;;&lt;br /&gt;
&amp;nbsp; cin&amp;gt;&amp;gt;x&amp;gt;&amp;gt;y;&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;mult(x, y);&lt;br /&gt;
&amp;nbsp; getch();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int mult(int x, int y)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; return x*y;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How is this useful...Well, in this program the function is totally useless, and it can only&lt;br /&gt;
multiply integers! &amp;nbsp;But this is just to show you how to make functions, after you&lt;br /&gt;
understand the basics I hope you will be able to do anything yourself.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What my example does: #includes...basic includes What is int mult(int x, int y); ? &amp;nbsp;That is&lt;br /&gt;
a prototype of the function, without it you would not be able to use mult! What&lt;br /&gt;
is void main()? &amp;nbsp;You should know that. What is cout&amp;lt;&amp;lt;endl&amp;lt;&amp;lt;mult(x,y); &amp;nbsp;Well, basically it&lt;br /&gt;
puts us down a line, and then it outputs what mult returns. &amp;nbsp;More on this later. What is&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int mult(int x, int y)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;return x*y;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Well, it is a function! &amp;nbsp;It says that the return type is an integer. When the keywork&lt;br /&gt;
return is used it says that the function mult has a value of whatever x*y would be...as it&lt;br /&gt;
says return x*y. &amp;nbsp;The two ints that it takes are x and y. &amp;nbsp;So it multiplies&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;them and returns&lt;br /&gt;
that value. &amp;nbsp;Then outputs mult(x, y); &amp;nbsp;It is perfectly legal. &amp;nbsp;Perhaps it would help if you&lt;br /&gt;
think of it as saying that the function mult has a value of whatever x*y is. &amp;nbsp;This is not&lt;br /&gt;
true really, it just returns that value, and you can do whatever you want with it, but I&lt;br /&gt;
hope it helps.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What can you do? &amp;nbsp;You can make void functions that do anything...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
void function(void);&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; function();&lt;br /&gt;
}&lt;br /&gt;
void function(void)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;This is a useless and totally wasteful function&quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What is does is declare that there is going to be a function, by prototyping, and then at&lt;br /&gt;
the bottom the function is defined, and it only does one thing...outputs &quot;This is a useless&lt;br /&gt;
and totally wasteful function&quot; &amp;nbsp;However, what if you wanted to do something that took 3&lt;br /&gt;
lines four hundred times in different places? &amp;nbsp;Say,&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
void function(void);&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; LOTS OF CODE THAT NEEDS TO OUTPUT Line 1Line 2Line 3&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void function(void)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Line 1&quot;;&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Line 2&quot;;&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Line 3&quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
That, aside from the fact that it is a bad example, is where you would use it. &amp;nbsp;When you&lt;br /&gt;
need to call something a lot of times, but don&#39;t want to cut and paste. &amp;nbsp;Functions are very&lt;br /&gt;
useful, and I hope I explained them well enough for you to understand.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;Note: My homepage is&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;My email is&amp;nbsp;&lt;a href=&quot;mailto:webmaster@madezee.com&quot;&gt;webmaster@madezee.com&lt;/a&gt;. &amp;nbsp;Please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me with comments and or suggestions. &amp;nbsp;If you want to use this on your own site please&lt;/div&gt;&lt;div style=&quot;margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;&quot;&gt;email me and add a link to&amp;nbsp;&lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;Thanks :)&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/218173439593994463/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-4-functions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/218173439593994463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/218173439593994463'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-4-functions.html' title='Lesson 4: Functions'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-93353203007300517</id><published>2011-05-01T12:31:00.001-07:00</published><updated>2011-05-01T12:31:27.421-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="computer programming"/><category scheme="http://www.blogger.com/atom/ns#" term="computer training"/><category scheme="http://www.blogger.com/atom/ns#" term="cpp"/><category scheme="http://www.blogger.com/atom/ns#" term="e-learning"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="online course"/><category scheme="http://www.blogger.com/atom/ns#" term="online learning"/><title type='text'>Lesson 3: Loops</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;b&gt; &lt;/b&gt;&lt;/span&gt;&lt;b&gt;Lesson 3: Loops&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the third installment of the Lessons in C programming tutorials created by me,&lt;br /&gt;
Alexander. &amp;nbsp;In this lesson I will cover loops. &amp;nbsp;Loops basically do what it sounds like,&lt;br /&gt;
loop. &amp;nbsp;If you have read lesson 2 you should understand some Boolean expressions. &amp;nbsp;If you do&lt;br /&gt;
not, you should read it again. &amp;nbsp;When working with loops it is important to understand truth&lt;br /&gt;
and false. &amp;nbsp;Maybe you should try doing some truth tables with problems.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are basically 3 types of loops. &amp;nbsp;FOR, WHILE, DO WHILE &amp;nbsp;Each of them has their uses.&lt;br /&gt;
They are all outlined below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
FOR - FOR loops are the most useful type, I believe. &amp;nbsp;The layout is for(variable&lt;br /&gt;
initialization, conditional, incrementing variable) &amp;nbsp;It is very versatile, and the layout&lt;br /&gt;
can be changed somewhat. &amp;nbsp;Basically, the variable initialization allows you to either&lt;br /&gt;
declare a variable and give it a value, or give a value to another variable. &amp;nbsp;Second, the&lt;br /&gt;
conditional statement. &amp;nbsp;What it does is it says that while the conditional is true then it&lt;br /&gt;
would do what in is in the body. &amp;nbsp;Third, the incrementing variable section. &amp;nbsp;It does not&lt;br /&gt;
have to increment a variable. &amp;nbsp;It can decrement, which is subtracting one, or it can&lt;br /&gt;
perform various other manipulations on the variable.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Ex. #include &amp;lt;iostream.h&amp;gt; &amp;nbsp;//We only need one header file&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;void main()&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//We always need this&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //The loop goes while x&amp;lt;100, and x has one&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;for(int x=0;x&amp;lt;100;x++)/*THE LOOP*/ //added to it every time the loops&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;endl; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Outputting x&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;} &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This program is a very simple example of a for loop. &amp;nbsp;x is set to zero, while x is less&lt;br /&gt;
than 100 do cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;endl; add 1 to x until the loop ends. &amp;nbsp;Pretty simple to understand,&lt;br /&gt;
but it is a very powerful loop, and much better than WHILE and DO WHILE loops.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
WHILE - WHILE loops are very simple, but not as useful as FOR loops. &amp;nbsp;The basic structure&lt;br /&gt;
is...WHILE(true) then do whatever is in the body. &amp;nbsp;The truth could be x==1 or while(x!=7)&lt;br /&gt;
(x does not equal 7)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Ex. #include &amp;lt;iostream.h&amp;gt; //We only need this header file&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;void main()&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//Of course...&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{ int x=0; &amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//Don&#39;t forget to declare variables&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;while(x&amp;lt;100)&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//While x is less than 100 do&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;endl;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//Same output as the above loop&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;x++;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//Adds 1 to x every time it repeats&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;}&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This was another pretty simple example, but it is longer than the above FOR loop, showing&lt;br /&gt;
why I like for better than while, though while is a very easy loop to use, so if you are&lt;br /&gt;
having trouble then you can use it, but try to use for.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
DO WHILE - DO WHILE loops are useful for only things that want to loop at least once.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; basically it goes DO { THIS } WHILE(TRUE)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, it is your turn to try and do a loop! &amp;nbsp;make a DO WHILE loop that does what the above&lt;br /&gt;
programs do...output 0 to 99! &amp;nbsp;It is not hard, if you have trouble email me at&lt;br /&gt;
webmaster@madezee.com and I will give you some help... Best of luck :) &amp;nbsp;Check back again for&lt;br /&gt;
more programming in C!&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int x=0;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;do while(x&amp;lt;100)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;cout &amp;lt;&amp;lt; x &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;x++;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Note: My homepage is &lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;My email is &lt;a href=&quot;mailto:webmaster@madezee.com&quot;&gt;webmaster@madezee.com&lt;/a&gt;. &amp;nbsp;Please&lt;br /&gt;
email me with comments and or suggestions. &amp;nbsp;If you want to use this on your own site please&lt;br /&gt;
email me and add a link to &lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;Thanks :)&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/93353203007300517/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-3-loops.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/93353203007300517'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/93353203007300517'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-3-loops.html' title='Lesson 3: Loops'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-5312098068514594058</id><published>2011-05-01T12:30:00.001-07:00</published><updated>2011-05-01T12:30:39.302-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="computer programming"/><category scheme="http://www.blogger.com/atom/ns#" term="computer training"/><category scheme="http://www.blogger.com/atom/ns#" term="cpp"/><category scheme="http://www.blogger.com/atom/ns#" term="e-learning"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="online course"/><category scheme="http://www.blogger.com/atom/ns#" term="online learning"/><title type='text'>Learning C: lesson 2</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;&lt;b&gt;Learning C: lesson 2&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Hello, this is Alexander. &amp;nbsp;Since I finally got an email from someone who liked my previous&lt;br /&gt;
lesson, I am going to make the second installment. &amp;nbsp;This one will be about variables, and&lt;br /&gt;
stuff like &#39;if&#39; statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#39;IF&#39; is the most important word in programming for many programs. &amp;nbsp;Without it there is no&lt;br /&gt;
conditional statements. &amp;nbsp;This means that there can be only one way a program can execute.&lt;br /&gt;
It would almost impossible to make a program without this one simple word.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
There are many things to understand when using IF statements. &amp;nbsp;First, you must understand&lt;br /&gt;
stuff like OR NOT etc. &amp;nbsp;This are the most important, so I will describe how to use them in&lt;br /&gt;
C and C++ programming below: &amp;nbsp;(NOTE: ZERO IS FALSE! &amp;nbsp;ONE IS TRUE!)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
NOT: This just says that the program should reverse the value...for example NOT(1) would be&lt;br /&gt;
0. &amp;nbsp;NOT(0) would be 1. &amp;nbsp;NOT(any number but zero) would be 0. &amp;nbsp;In C and C++ NOT is written&lt;br /&gt;
as - ! - just one simple little character. &amp;nbsp;It is very useful and can save lots of time.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
AND: This is another important command, and it is used to say that if this AND this is&lt;br /&gt;
true... for example &amp;nbsp;(1)AND(0) would come out as 0. &amp;nbsp;(1)AND(1) would come out as 1. &amp;nbsp; (ANY&lt;br /&gt;
REAL NUMBER BUT ZERO)AND(0) would be 0. &amp;nbsp;(ANY REAL NUMBER BUT ZERO)AND(ANY REAL NUMBER BUT&lt;br /&gt;
ZERO) would be 1. &amp;nbsp;The AND is written as - &amp;amp;&amp;amp; - in C++. &amp;nbsp;It is just two simple characters.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
OR: Very useful is the OR statement! &amp;nbsp;For example (1)OR(0) would be 1! &amp;nbsp;(0)OR(0) would be&lt;br /&gt;
0. &amp;nbsp;(ANY REAL NUMBER)OR(ANY REAL NUMBER BUT ZERO) would be 1! &amp;nbsp;It is simple, either one can&lt;br /&gt;
be true and make the whole thing true. &amp;nbsp;The OR is written as - || - in C++. &amp;nbsp;It is also two&lt;br /&gt;
simple characters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next thing to learn is to combine them... &amp;nbsp;What is !(1 &amp;amp;&amp;amp; 0)? &amp;nbsp;Of course, it would be&lt;br /&gt;
1. &amp;nbsp;This is because 1 &amp;amp;&amp;amp; 0 evaluates two 0 and ! 0 equals 1. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Try some of these...they are not hard. &amp;nbsp;If you have questions about them, you can email me&lt;br /&gt;
at webmaster@madezee.com.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;A. !(1 || 0)&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;ANSWER: 0&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;B. !(1 || 1 &amp;amp;&amp;amp; 0)&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;ANSWER: 0 (AND is evaluated before OR)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;C. !((1 || 0) &amp;amp;&amp;amp; 0)&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;ANSWER: 1 (Parenthesis are useful)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you find you enjoy this you might want to look more at Boolean Algebra, which is also&lt;br /&gt;
very helpful to programmers as it can be good for helping program conditional statements.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;IF is used like this IF(TRUE)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;{ DO WHAT IS IN THE BRACKETS }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;ELSE is basically &amp;nbsp; &amp;nbsp;ELSE&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;{ DO WHAT IS IN THE BRACKETS }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Let&#39;s look at a simple program for you to try out on your own...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;//For output&lt;br /&gt;
#include &amp;lt;conio.h&amp;gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;//For getch()&lt;br /&gt;
&lt;br /&gt;
void main()&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;//Most important part of the program!&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; int age;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;//Need a variable...&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Please input your age: &quot;;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//Asks for age&lt;br /&gt;
&amp;nbsp; cin&amp;gt;&amp;gt;age;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;//The input is put in age&lt;br /&gt;
&amp;nbsp; if(age&amp;lt;100)&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;//If the age is less than 100&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;You are pretty young!&quot;; &amp;nbsp; &amp;nbsp; //Just to show you the output&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&amp;nbsp; if(age==100)&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;//Remember, if the age equals 100 needs two =&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;cout&amp;lt;&amp;lt;&quot;You are old&quot;;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//Just to show you it works...&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&amp;nbsp; if(age&amp;gt;100)&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; cout&amp;lt;&amp;lt;&quot;You are really old&quot;;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//Proof that it works for all conditions&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now, this program did not use &amp;amp;&amp;amp; || ! or anything in it. &amp;nbsp;This is because it didn&#39;t need&lt;br /&gt;
too. &amp;nbsp;I think you should probably be able to make your own if statements with them without&lt;br /&gt;
having to worry too much about problems. &amp;nbsp;As always, you can email me at&lt;br /&gt;
&lt;a href=&quot;mailto:webmaster@madezee.com&quot;&gt;webmaster@madezee.com&lt;/a&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Note: My homepage is &lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;My email is &lt;a href=&quot;mailto:webmaster@madezee.com&quot;&gt;webmaster@madezee.com&lt;/a&gt;. &amp;nbsp;Please&lt;br /&gt;
email me with comments and or suggestions. &amp;nbsp;If you want to use this on your own site please&lt;br /&gt;
email me and add a link to &lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;Thanks :)&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/5312098068514594058/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/learning-c-lesson-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/5312098068514594058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/5312098068514594058'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/learning-c-lesson-2.html' title='Learning C: lesson 2'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3010028171272234388.post-8223776395726744614</id><published>2011-05-01T12:29:00.000-07:00</published><updated>2011-05-01T12:29:46.643-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="computer programming"/><category scheme="http://www.blogger.com/atom/ns#" term="computer training"/><category scheme="http://www.blogger.com/atom/ns#" term="cpp"/><category scheme="http://www.blogger.com/atom/ns#" term="e-learning"/><category scheme="http://www.blogger.com/atom/ns#" term="education on line"/><category scheme="http://www.blogger.com/atom/ns#" term="online course"/><category scheme="http://www.blogger.com/atom/ns#" term="online learning"/><title type='text'>Lesson 1: The basics of C++</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;b&gt; Lesson 1: The basics of C++&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;I am writing this for those people who want to learn how to program in&lt;br /&gt;
&amp;nbsp;C++, especially those &amp;nbsp;who had trouble. &amp;nbsp;It is for those of you who want a sense of accomplishment every time your &amp;nbsp;program works perfectly. &amp;nbsp;If you want the sense of accomplishment, read on.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;C++ is a programming language. &amp;nbsp;It is a programming language of many&lt;br /&gt;
different dialects, just like each language that is spoken has many dialects. &amp;nbsp;In C though, they are not because the &quot;speakers&quot; live in the North, South, or grew up in some other place, it is because there are so many compilers. &amp;nbsp;There are about four major ones: Borland C++, Microsoft Visual C++, Watcom C/386, and DJGPP. &amp;nbsp;You can download DJGPP http://www.delorie.com/djgpp/ or you may already have another compiler. &lt;br /&gt;
&lt;br /&gt;
Each of these compilers is a little different. &amp;nbsp;The library functions of one will have all of the standard C++ functions, but they will also have other functions or, continuing the analogy, words. &amp;nbsp;At times, this can lead to confusion, as certain programs will only run under certain compilers, though I do not believe this to be the case with the programs in these tutorials.&lt;br /&gt;
&lt;br /&gt;
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++&lt;br /&gt;
If you don&#39;t have a compiler, I strongly suggest you get one. A simple one is good enough for&lt;br /&gt;
my tutorials, but get one. &lt;br /&gt;
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++&lt;br /&gt;
C++ is a different breed of programming language. &amp;nbsp;It has only a few keywords for DOS, and it has no keywords to use for output. &amp;nbsp;This means that almost everything is stored in a header file. &amp;nbsp;This gives the use of many functions. &amp;nbsp;But lets see a real program...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;HEY, you, I&#39;m alive! &amp;nbsp;Oh, and Hello World!&quot;;&lt;br /&gt;
&amp;nbsp; return 0; &amp;nbsp; &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
That does not look too hard, right? &amp;nbsp;Lets break down the program and then look at it. &amp;nbsp;The #include is a preprocessor directive which tells the compiler to put code in the header file iostream.h into our program! &amp;nbsp;By including header files, you ~can gain access to many different functions. &amp;nbsp;For example, the cout function requires iostream.h.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The next thing is int main() what this is saying is that there is a function called main, and that it returns an integer, hence int. &amp;nbsp;Then those little braces ( { and } ) are used to signal the beginning and ending of functions, as well as other code blocks. &amp;nbsp;If you have programmed in Pascal, you will know them as BEGIN and END. &lt;br /&gt;
&lt;br /&gt;
The next line of the program may seem strange. &amp;nbsp;If you have programmed in other languages you might think that print would be used to display text. &amp;nbsp;However, in C++ the cout function is used to display text. &amp;nbsp;It uses the &amp;lt;&amp;lt; symbols, known as insertion operators. &amp;nbsp;The quotes tell the compiler that you want to output the literal string as-is. &amp;nbsp;The ; is added to the end of all function calls in C++.&lt;br /&gt;
&lt;br /&gt;
The penultimate line of code is ordering main to return 0. &amp;nbsp;When one returns a value to main, it is passed on to the operating system. &amp;nbsp;As a note, declaring int main() or void main() both will generally work. &amp;nbsp;It is accepted practice to some to declare main as a void, but to others it is&lt;br /&gt;
extremely upsetting. &amp;nbsp;Previously, these tutorials had used void main, however, this is NO LONGER recommended, as it does not conform to the ANSI standard.&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
After, the brace closes off the function. &amp;nbsp; You can try out this program if you want, just cut and paste it into the IDE of a compiler such as DJGPP, or save it to a file ending with a .cpp extension, and use a command-line compiler to compile and link it.&lt;br /&gt;
&lt;br /&gt;
Comments are extremely important to understand. &amp;nbsp; When you declare that an &amp;nbsp;area is a comment, the compiler will IGNORE it. &amp;nbsp;To comment it is possible to use either &amp;nbsp;// , which declares that the entire line past that point is a comment, or it is possible to use &amp;nbsp;/* and then */ to block off everything between the two as a comment. &amp;nbsp; Certain compilers will change the color of a commented area, but some will not. &amp;nbsp;Be certain not accidently declare part of your code a comment. &amp;nbsp;Note that this is what is known as &quot;commenting-out&quot; a section of code, and it is useful when you are debugging. &lt;br /&gt;
&lt;br /&gt;
So far you should be able to write a simple program to display information typed in by you, the programmer. &amp;nbsp;However, it is also possible for your program to accept input. &amp;nbsp;the function you use is known as cin&amp;gt;&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Wait! &amp;nbsp;Before you can receive input you must have a place to store input! &amp;nbsp;In programming, these locations where input and other forms of data are stored, are called variables. &amp;nbsp;There are a few different types of variables, which must be stated. &amp;nbsp;The basic types are char, int, and float.&lt;br /&gt;
&lt;br /&gt;
Char is used to create variables that store characters, int is used to create variables that store integers (numbers such as 1, 2, 0, -3, 44, -44), and float is used to delare numbers with decimal places. &amp;nbsp;In fact, they are all keywords that are used in front of variable names to tell the compiler that you have created a variable. &amp;nbsp;That is known as &quot;declaring a variable&quot;. &amp;nbsp;When you declare a variable, or variables, you must end the line with a semi-colon, the same as if you were to call a function. &amp;nbsp;If you do not declare the variable you are attempting to use, you will receive numerous error messages and the program will not run.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here are some examples of declaring variables:&lt;br /&gt;
&lt;br /&gt;
int x;&lt;br /&gt;
int a, b, c, d;&lt;br /&gt;
char letter;&lt;br /&gt;
float the_float;&lt;br /&gt;
&lt;br /&gt;
It is not possible, however, to declare two variables of different types with the same name.&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; int thisisanumber;&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;Please enter a number:&quot;;&lt;br /&gt;
&amp;nbsp; cin&amp;gt;&amp;gt;thisisanumber;&lt;br /&gt;
&amp;nbsp; cout&amp;lt;&amp;lt;&quot;You entered: &quot;&amp;lt;&amp;lt;thisisanumber;&lt;br /&gt;
&amp;nbsp; return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Let&#39;s break apart this program and examine it line by line. &amp;nbsp;Int is the keyword that is used when delcaring a variable which is an integer. &amp;nbsp;The cin&amp;gt;&amp;gt; sets the value of thisisanumber to be whatever the user types into the program when prompted. &amp;nbsp;Keep in mind that the variable was declared an integer, which means the output will be in the form of an integer. &amp;nbsp;Try typing in a sequence of charaters, or a decimal when you run the example program to see what you get as a response. &amp;nbsp;Notice that when printing out a variable, there are not any quotation marks. &amp;nbsp;If there were quotation marks, the output would be &quot;You Entered: thisisanumber.&quot; &amp;nbsp;Do not be confused by the inclusion of two separate insertion operators on a line. &amp;nbsp;It is allowable, as long as you make certain to have each separate output of variable or string with its own insertion operator. Do not try to put two variables together with only one &amp;lt;&amp;lt; because it will give you an error message. &amp;nbsp;Do not forget to end functions and declarations with the semi-colon(;). &amp;nbsp;Otherwise you will get an error message when you try to compile the program.&lt;br /&gt;
&lt;br /&gt;
Now that you know a little bit about variables, here are some ways to manipulate them. &amp;nbsp;*, -, +, /, =, ==, &amp;gt;, &amp;lt; are all operators used on numbers, these are the simple ones. &amp;nbsp;The * multiplies, the - subtracts, and the + adds. &amp;nbsp;Of course, the most important for changing variables&lt;br /&gt;
is the equal sign. &amp;nbsp;In some languages, = checks if one side is equal to the other side, but in C++ == is used for that task. &amp;nbsp;However, the equal sign is still extremely useful. &amp;nbsp;It sets the left side of the equal sign, which must be one AND ONLY one variable, equal to the right side. &amp;nbsp;The right side of the equal sign is where the other operators can be used. &lt;br /&gt;
&lt;br /&gt;
Here are a few examples:&lt;br /&gt;
&lt;br /&gt;
a=4*6; &amp;nbsp;//(Note use of comments and of semi-colon) a is 24&lt;br /&gt;
a=a+5; &amp;nbsp;// a equals the original value of a with five additional units&lt;br /&gt;
a==5 &amp;nbsp; &amp;nbsp;//Does NOT assign five to a. &amp;nbsp;Rather, it checks to see if a equals 5.&lt;br /&gt;
&lt;br /&gt;
The other form of equal, ==, is not a way to assign a value to a variable. &amp;nbsp;Rather, it checks to see if the variables are equal. &amp;nbsp;It is useful in other areas of C++ such as if statements and loops. &lt;br /&gt;
&lt;br /&gt;
You can probably guess what the &amp;lt; and &amp;gt; are for. &amp;nbsp;They are greater than and less than checks. &lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
a&amp;lt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; //Checks to see if a is less than five&lt;br /&gt;
a&amp;gt;5&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt; &amp;nbsp;//Checks to see if a is greater than five&lt;br /&gt;
a==5 &amp;nbsp; &amp;nbsp; &amp;nbsp;//Checks to see if a equals five, for good measure&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
Note: My homepage is &lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;My email is &lt;a href=&quot;mailto:webmaster@madezee.com&quot;&gt;webmaster@madezee.com&lt;/a&gt;. &amp;nbsp;Please email me with comments and or suggestions. &amp;nbsp;If you want to use this on your own site please&lt;br /&gt;
email me and add a link to &lt;a href=&quot;http://www.madezee.com/&quot;&gt;http://www.madezee.com&lt;/a&gt;. &amp;nbsp;Thanks :)&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-online-learning.blogspot.com/feeds/8223776395726744614/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-1-basics-of-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/8223776395726744614'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3010028171272234388/posts/default/8223776395726744614'/><link rel='alternate' type='text/html' href='http://cpp-online-learning.blogspot.com/2011/05/lesson-1-basics-of-c.html' title='Lesson 1: The basics of C++'/><author><name>Praveen Sudarsan</name><uri>http://www.blogger.com/profile/10268980123164130652</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>