<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hassan Ahmad</title>
	<atom:link href="http://www.hassan-ahmad.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hassan-ahmad.com</link>
	<description>a web-developer and programmer</description>
	<lastBuildDate>Fri, 01 Jul 2011 07:02:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Cyber Chat &#8211; Artificial Intelligence Chat-bot</title>
		<link>http://www.hassan-ahmad.com/2011/07/cyber-chat-artificial-intelligence-chat-bot/</link>
		<comments>http://www.hassan-ahmad.com/2011/07/cyber-chat-artificial-intelligence-chat-bot/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 06:59:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Softwares]]></category>

		<guid isPermaLink="false">http://www.hassan-ahmad.com/?p=309</guid>
		<description><![CDATA[It&#8217;s my new project in C++. About Cyber Chat: Cyber Chat is an Artificial Intelligence chatter-bot that interacts with the user in simple English language and can simulate a conversation. It has a repository or knowledge-base of patterns, which are matched with the input to give the best possible reply. More generally, the technique which [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s my new project in C++.</p>
<p><b>About Cyber Chat:</b></p>
<blockquote><p>Cyber Chat is an Artificial Intelligence chatter-bot that interacts with the user in simple English language and can simulate a conversation. It has a repository or knowledge-base of <b>patterns</b>, which are matched with the input to give the best possible reply. More generally, the technique which is used in the knowledge-base to represent the Cyber Chat knowledge is known as &#8220;Case Base Reasoning&#8221; or CBR.</p></blockquote>
<p>It has a large database consisting of 22 files.</p>
<p>- <a href="http://www.hassan-ahmad.com/cyberchat.zip" target="_blank">Download Link</a><br />
- <a href="http://www.freeimagehosting.net/uploads/5cd26a7327.png" target="_blank"><b>Sample Chat-log</b></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hassan-ahmad.com/2011/07/cyber-chat-artificial-intelligence-chat-bot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ &#8211; Hanoi Towers Solution</title>
		<link>http://www.hassan-ahmad.com/2011/04/c-hanoi-towers-solution/</link>
		<comments>http://www.hassan-ahmad.com/2011/04/c-hanoi-towers-solution/#comments</comments>
		<pubDate>Sun, 03 Apr 2011 21:00:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://www.hassan-ahmad.com/?p=306</guid>
		<description><![CDATA[Please don&#8217;t ask me how this code works! #include &#60;iostream&#62; &#160; using namespace std; &#160; void hanoi&#40;int n, char source, char intermediate, char destination&#41; &#123; &#160; if &#40;n &#62; 0&#41; &#123; hanoi&#40;n - 1, source, destination, intermediate&#41;; cout &#60;&#60; &#34; - Moving disk &#34; &#60;&#60; n &#60;&#60; &#34; from &#34; &#60;&#60; source &#60;&#60; &#34; to [...]]]></description>
			<content:encoded><![CDATA[<p>Please don&#8217;t ask me how this code works! <img src='http://www.hassan-ahmad.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">void</span> hanoi<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> n, <span style="color: #0000ff;">char</span> source, <span style="color: #0000ff;">char</span> intermediate, <span style="color: #0000ff;">char</span> destination<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
    <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>n <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        hanoi<span style="color: #008000;">&#40;</span>n <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span>, source, destination, intermediate<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
        <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; - Moving disk &quot;</span> <span style="color: #000080;">&lt;&lt;</span> n <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; from &quot;</span> <span style="color: #000080;">&lt;&lt;</span> source <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; to &quot;</span> <span style="color: #000080;">&lt;&lt;</span> destination <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
        hanoi<span style="color: #008000;">&#40;</span>n <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span>, intermediate, source, destination<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> n<span style="color: #008080;">;</span>
    <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Enter the no. of disks: &quot;</span><span style="color: #008080;">;</span> <span style="color: #0000dd;">cin</span> <span style="color: #000080;">&gt;&gt;</span> n<span style="color: #008080;">;</span>
    hanoi<span style="color: #008000;">&#40;</span>n, <span style="color: #FF0000;">'A'</span>, <span style="color: #FF0000;">'B'</span>, <span style="color: #FF0000;">'C'</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.hassan-ahmad.com/2011/04/c-hanoi-towers-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ &#8211; Quadratic Equation Solver</title>
		<link>http://www.hassan-ahmad.com/2011/04/quadratic-equation-c/</link>
		<comments>http://www.hassan-ahmad.com/2011/04/quadratic-equation-c/#comments</comments>
		<pubDate>Sun, 03 Apr 2011 20:02:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[quadratic equation c++]]></category>

		<guid isPermaLink="false">http://www.hassan-ahmad.com/?p=292</guid>
		<description><![CDATA[Functions: checkRoots() calculateRoots() #include &#60;iostream&#62; #include &#60;iomanip&#62; #include &#60;math.h&#62; &#160; using namespace std; &#160; int checkRoots&#40;double A, double B, double C&#41; &#123; &#160; int D = pow&#40;B, 2&#41; - 4 * A * C; &#160; if &#40;D &#62; 0&#41; &#123; return 0; &#125; else &#123; return D; &#125; &#160; &#125; &#160; void calculateRoots&#40;double A, double [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.hassan-ahmad.com/wp-content/uploads/2011/04/untitled.png" alt="" title="untitled" width="225" height="71" class="aligncenter size-full wp-image-299" /></p>
<h3>Functions:</h3>
<p>checkRoots()<br />
calculateRoots()</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#include &lt;iomanip&gt;</span>
<span style="color: #339900;">#include &lt;math.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> checkRoots<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">double</span> A, <span style="color: #0000ff;">double</span> B, <span style="color: #0000ff;">double</span> C<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #0000ff;">int</span> D <span style="color: #000080;">=</span> <span style="color: #0000dd;">pow</span><span style="color: #008000;">&#40;</span>B, <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> <span style="color: #0000dd;">4</span> <span style="color: #000040;">*</span> A <span style="color: #000040;">*</span> C<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>D <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">return</span> D<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> calculateRoots<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">double</span> A, <span style="color: #0000ff;">double</span> B, <span style="color: #0000ff;">double</span> C<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #0000ff;">double</span> x1, x2<span style="color: #008080;">;</span>
&nbsp;
	x1 <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">-</span> B <span style="color: #000040;">+</span> <span style="color: #0000dd;">sqrt</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">pow</span><span style="color: #008000;">&#40;</span>B, <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> <span style="color: #0000dd;">4</span> <span style="color: #000040;">*</span> A <span style="color: #000040;">*</span> C<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">2</span> <span style="color: #000040;">*</span> A<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	x2 <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">-</span> B <span style="color: #000040;">-</span> <span style="color: #0000dd;">sqrt</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">pow</span><span style="color: #008000;">&#40;</span>B, <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> <span style="color: #0000dd;">4</span> <span style="color: #000040;">*</span> A <span style="color: #000040;">*</span> C<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">2</span> <span style="color: #000040;">*</span> A<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>x1 <span style="color: #000040;">!</span><span style="color: #000080;">=</span> x2<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;1. X = &quot;</span> <span style="color: #000080;">&lt;&lt;</span> setprecision<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">5</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> x1 <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;2. X = &quot;</span> <span style="color: #000080;">&lt;&lt;</span> setprecision<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">5</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> x2 <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;X = &quot;</span> <span style="color: #000080;">&lt;&lt;</span> setprecision<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">5</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> x1 <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #0000ff;">double</span> A, B, C<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Quadratic Equation Solver&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;A = &quot;</span><span style="color: #008080;">;</span> <span style="color: #0000dd;">cin</span> <span style="color: #000080;">&gt;&gt;</span> A<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;B = &quot;</span><span style="color: #008080;">;</span> <span style="color: #0000dd;">cin</span> <span style="color: #000080;">&gt;&gt;</span> B<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;C = &quot;</span><span style="color: #008080;">;</span> <span style="color: #0000dd;">cin</span> <span style="color: #000080;">&gt;&gt;</span> C<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">int</span> result <span style="color: #000080;">=</span> checkRoots<span style="color: #008000;">&#40;</span>A, B, C<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>result <span style="color: #000080;">==</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		calculateRoots<span style="color: #008000;">&#40;</span>A, B, C<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">else</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Complex Roots&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;[Discriminant = &quot;</span> <span style="color: #000080;">&lt;&lt;</span> result <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;]&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.hassan-ahmad.com/2011/04/quadratic-equation-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Astericks Program Code – Lab #5</title>
		<link>http://www.hassan-ahmad.com/2011/03/lab5/</link>
		<comments>http://www.hassan-ahmad.com/2011/03/lab5/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 03:56:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.hassan-ahmad.com/?p=271</guid>
		<description><![CDATA[Change ROWS variable to the number of rows you want to print. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #include &#60;iostream&#62; #include &#60;iomanip&#62; // for the setw() manipulator &#160; using namespace std; &#160; int main&#40;&#41; &#123; &#160; int ROWS [...]]]></description>
			<content:encoded><![CDATA[<p>Change <b>ROWS</b> variable to the number of rows you want to print.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#include &lt;iomanip&gt; // for the setw() manipulator</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #0000ff;">int</span> ROWS <span style="color: #000080;">=</span> <span style="color: #0000dd;">4</span><span style="color: #008080;">;</span> <span style="color: #666666;">// Yeah in capitals, just to make it look cool!</span>
	<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> x<span style="color: #000080;">=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> x <span style="color: #000080;">&lt;</span> ROWS <span style="color: #000040;">+</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> x<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> setw <span style="color: #008000;">&#40;</span>ROWS <span style="color: #000040;">+</span> <span style="color: #0000dd;">1</span> <span style="color: #000040;">-</span> x<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;=</span> x <span style="color: #000040;">*</span> <span style="color: #0000dd;">2</span> <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;*&quot;</span><span style="color: #008080;">;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>x<span style="color: #000080;">=</span>ROWS<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> x <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> x<span style="color: #000040;">--</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> setw <span style="color: #008000;">&#40;</span>ROWS <span style="color: #000040;">+</span> <span style="color: #0000dd;">1</span> <span style="color: #000040;">-</span> x<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;=</span> x <span style="color: #000040;">*</span> <span style="color: #0000dd;">2</span> <span style="color: #000040;">-</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;*&quot;</span><span style="color: #008080;">;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
	<span style="color: #666666;">// This comment is self explanatory... no need to explain :)</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<h2>Output:</h2>
<p>
<a href="http://www.hassan-ahmad.com/wp-content/uploads/2011/03/untitled.png"><img src="http://www.hassan-ahmad.com/wp-content/uploads/2011/03/untitled.png" alt="" title="untitled" width="541" height="187" class="alignleft size-full wp-image-283" /></a><br /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hassan-ahmad.com/2011/03/lab5/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>C++ List All Files in a Directory</title>
		<link>http://www.hassan-ahmad.com/2011/03/c-list-all-the-files-in-directory-recursively/</link>
		<comments>http://www.hassan-ahmad.com/2011/03/c-list-all-the-files-in-directory-recursively/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 10:56:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Software & Website Development]]></category>
		<category><![CDATA[directory tree]]></category>
		<category><![CDATA[list all files]]></category>
		<category><![CDATA[list files]]></category>
		<category><![CDATA[list files in a directory]]></category>
		<category><![CDATA[recursive]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://www.hassan-ahmad.com/?p=218</guid>
		<description><![CDATA[If you need to do a certain task on all files or folders in a directory, the following code does the job. The following function recursively calls itself for all contained subfolders and prints all the files found. Note that this code will only run on Windows operating system as it uses Win32 API&#8217;s, namely [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to do a certain task on all files or folders in a directory, the following code does the job. The following function recursively calls itself for all contained subfolders and prints all the files found. Note that this code will only run on Windows operating system as it uses <b>Win32 API&#8217;s</b>, namely FindFirstFile, FindNextFile and FindClose.</p>
<p><b>GetAllFiles()</b> is called with the path of the base folder from where you want to start the enumeration.</p>
<p><b>Example Usage: </b> GetAllFiles(&#8220;D:&#8221;);</p>
<p><b>Required Headers: </b> &lt;string&gt; and &lt;windows.h&gt;</p>
<hr />
<pre style="width: 580px; height: 800px; font-family:monospace; overflow:scroll">
void GetAllFiles( string sPath )
{
    WIN32_FIND_DATA FindFileData;
    string sTmpPath = sPath;
    sTmpPath += "\\*.*";

    HANDLE hFind = FindFirstFile( sTmpPath.c_str(), &#038;FindFileData );

    if ( hFind == INVALID_HANDLE_VALUE )
        return;
    else {
        do {
            if ( ( FindFileData.dwFileAttributes &#038; FILE_ATTRIBUTE_DIRECTORY ) ) {
		// if directory:
                if ( strcmp(".", FindFileData.cFileName ) &#038;&#038; strcmp("..", FindFileData.cFileName) ) {
		    sTmpPath = sPath;
                    sTmpPath += "\\";
		    sTmpPath += FindFileData.cFileName;
                    GetAllFiles( sTmpPath.c_str() );
                }
            }
            else // if file:
            {
		sTmpPath = sPath;
                sTmpPath += "\\";
		sTmpPath += FindFileData.cFileName;
                cout << sTmpPath << endl;
            }
        } while ( FindNextFile( hFind, &#038;FindFileData) != 0 );

        FindClose( hFind );
    }
    return;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.hassan-ahmad.com/2011/03/c-list-all-the-files-in-directory-recursively/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Bitwise Operations</title>
		<link>http://www.hassan-ahmad.com/2011/02/c-bitwise-operations-example-functions/</link>
		<comments>http://www.hassan-ahmad.com/2011/02/c-bitwise-operations-example-functions/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 22:58:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Software & Website Development]]></category>
		<category><![CDATA[c++ bit operation]]></category>
		<category><![CDATA[c++ bitwise examples]]></category>
		<category><![CDATA[c++ bitwise mask]]></category>

		<guid isPermaLink="false">http://www.hassan-ahmad.com/?p=193</guid>
		<description><![CDATA[Awhile ago, I was working on to create a bit array in order to compactly store individual boolean values. So that a typical 1 byte could be used to store an array of 8 boolean values (since each boolean value requires only one bit in order to be represented, i.e 0 or 1). This is [...]]]></description>
			<content:encoded><![CDATA[<p>Awhile ago, I was working on to create a <b>bit array</b> in order to compactly store individual <b>boolean values</b>. So that a typical 1 byte could be used to store an array of 8 boolean values (since each boolean value requires only one bit in order to be represented, i.e 0 or 1). This is a much better strategy, since on the other hand if we use simple array for storing 8 boolean values, it would take 8 bytes in memory instead of just one.</p>
<p>I created a class for this purpose which implemented this functionality and provided a clean interface to the user for using that array. However, I came to know later that such type of optimization is  already done internally by the <b>vector&lt;bool&gt;</b> standard library, so it&#8217;s not particularly useful to code it ourselves.</p>
<p>I coded two functions for the purpose of setting individual bits ON or OFF in a byte. These functions perform the basic ON and OFF bit-wise operations and checking the status of a bit. So I thought it would be useful to share them with others too.</p>
<h3>Functions for setting a particular bit ON or OFF in a byte:</h3>
<p>Below is the code for the functions. This will give you some idea of how <b>bit-wise operations</b> can be used in C++ to perform some meaningful operation.</p>
<p>These functions do not return any values.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> setBitOn<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> <span style="color: #000040;">&amp;</span>value, <span style="color: #0000ff;">int</span> num<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> SHIFT <span style="color: #000080;">=</span> num<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> MASK <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span> <span style="color: #000080;">&lt;&lt;</span> SHIFT<span style="color: #008080;">;</span>
	value <span style="color: #000080;">=</span> value <span style="color: #000040;">|</span> MASK<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> setBitOff<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> <span style="color: #000040;">&amp;</span>value, <span style="color: #0000ff;">int</span> num<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> SHIFT <span style="color: #000080;">=</span> num<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> MASK <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span> <span style="color: #000080;">&lt;&lt;</span> SHIFT<span style="color: #008080;">;</span>
	value <span style="color: #000080;">=</span> value <span style="color: #000040;">&amp;</span> <span style="color: #008000;">&#40;</span>~MASK<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h3>Function to check if a particular bit is ON or OFF:</h3>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">bool</span> checkBit<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> value, <span style="color: #0000ff;">int</span> num<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> SHIFT <span style="color: #000080;">=</span> num<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> MASK <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span> <span style="color: #000080;">&lt;&lt;</span> SHIFT<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>value <span style="color: #000040;">|</span> MASK<span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> value <span style="color: #008080;">?</span> <span style="color: #0000ff;">true</span> <span style="color: #008080;">:</span> <span style="color: #0000ff;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h4>Parameters defined:</h4>
<p>In these functions, <b>int num</b> parameter is the offset of the bit which is to be reset. Thus <b>num = 0</b> would be the right-most bit in the byte.<br />
While, <b>value</b> is an unsigned int on which the operation is to be performed.</p>
<h3>Example usage of the functions:</h3>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
&nbsp;
	<span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> x <span style="color: #000080;">=</span> <span style="color: #0000dd;">244</span><span style="color: #008080;">;</span>
	setBitOn<span style="color: #008000;">&#40;</span>x, <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>   <span style="color: #666666;">// set right-most bit to 1</span>
	<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">7</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&gt;=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000040;">--</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> checkBit<span style="color: #008000;">&#40;</span>x, i<span style="color: #008000;">&#41;</span> <span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><b>Output</b> of the above code would be: <b>11110101</b>. Note that the binary of 244 is 11110100.</p>
<p>That&#8217;s all. I hope you learnt something from my code. </p>
<p>Happy coding, <img src='http://www.hassan-ahmad.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Hassan</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hassan-ahmad.com/2011/02/c-bitwise-operations-example-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Learning Ebooks</title>
		<link>http://www.hassan-ahmad.com/2011/02/c-learning-ebooks/</link>
		<comments>http://www.hassan-ahmad.com/2011/02/c-learning-ebooks/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 17:28:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ebooks]]></category>
		<category><![CDATA[c++ books]]></category>
		<category><![CDATA[c++ ebooks]]></category>
		<category><![CDATA[C++ How to program]]></category>
		<category><![CDATA[download c++ book]]></category>
		<category><![CDATA[The C++ Programming Language]]></category>
		<category><![CDATA[Wrox Press C++ Tutorial]]></category>

		<guid isPermaLink="false">http://www.hassan-ahmad.com/?p=135</guid>
		<description><![CDATA[C++ How to program, By Deitel &#38; Deitel (5th Edition) ISBN: 0-13-185757-6 © 2005 Author: Dr. Harvey Deitel &#38; Paul Deitel Filesize: 10.8 MB Deitel&#8217;s C++ How to Program is a C++ teaching book included in our course. Although current edition of the book is seventh we&#8217;ll be using the 5th one, and so I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<h3 style="margin-top: 25px;"><a href="http://www.hassan-ahmad.com/c-books/deitel.zip">C++ How to program, By Deitel &amp; Deitel (5th Edition)</a></h3>
<p><strong>ISBN:</strong> 0-13-185757-6 © 2005<br />
<strong>Author:</strong> Dr. Harvey Deitel &amp; Paul Deitel</p>
<p><strong>Filesize:</strong> 10.8 MB</p>
<p><a href="http://www.hassan-ahmad.com/wp-content/uploads/2011/02/index.jpeg"><img src="http://www.hassan-ahmad.com/wp-content/uploads/2011/02/index.jpeg" alt="" title="index" width="92" height="78" class="alignright size-full wp-image-158" /></a></p>
<p><strong>Deitel&#8217;s C++ How to Program</strong> is a C++ teaching book included in our course. Although current edition of the book is seventh we&#8217;ll be using the 5th one, and so I&#8217;ve uploaded it here. The zip file also contains the source-code of the examples provided in the book.</p>
<blockquote><p>The Deitels&#8217; C++ How to Program is the most comprehensive, practical introduction to C++ ever published &#8212; with hundreds of hands-on exercises, roughly 250 complete programs written and documented for easy learning, and exceptional insight into good programming practices, maximizing performance, avoiding errors, debugging, and testing.</p></blockquote>
<p>Plus, this book has thousands of cute &#8220;bumble bees&#8221; as well. <img src='http://www.hassan-ahmad.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p><a href="http://www.hassan-ahmad.com/c-books/deitel.zip">Download Link</a></p>
<h3><a href="http://www.hassan-ahmad.com/c-books/bjarne-stroutsup.pdf">The C++ Programming Language (Special 3rd Edition)</a></h3>
<p><strong>ISBN:</strong> 0-201-70073-5<br />
<strong>Author:</strong> Bjarne Stroustrup</p>
<p><strong>Filesize:</strong> 3.38 MB</p>
<p>A book by the creator of C++, <strong>Bjarne Stroustrup</strong>. This book presents the full specification for the C++ language and the design of its standard library. This book is a must have for those seeking to do some serious programming in C++.</p>
<p>While The C++ Programming Language is not a C++ tutorial, strictly speaking, anyone learning the language, especially those with C background, will greatly benefit from the clear presentation of all its elements. It is impossible to overstate the importance of this book for anyone who is serious about using and learning C++.</p>
<p><a href="http://www.hassan-ahmad.com/c-books/bjarne-stroutsup.pdf">Download Link</a></p>
<blockquote><p>&#8220;I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone.&#8221; &#8211; Bjarne Stroutsup</p></blockquote>
<h3 class="red">Other C++ Reference Books:</h3>
<ul>
<li><a href="http://www.hassan-ahmad.com/c-books/WroxTutorial.zip">Wrox Press C++ Tutorial</a>
<p>Although this book comes packed with the MS Visual C++ software, I&#8217;ve uploaded it anyway.</p>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.hassan-ahmad.com/2011/02/c-learning-ebooks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HA Computer Dictionary</title>
		<link>http://www.hassan-ahmad.com/2010/08/ha-computer-dictionary/</link>
		<comments>http://www.hassan-ahmad.com/2010/08/ha-computer-dictionary/#comments</comments>
		<pubDate>Sat, 14 Aug 2010 23:58:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Softwares]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[dictionary]]></category>
		<category><![CDATA[download.com]]></category>

		<guid isPermaLink="false">http://www.hassan-ahmad.com/?p=100</guid>
		<description><![CDATA[HA Computer Dictionary is a comprehensive dictionary of about 10,000 computer related terms and abbreviations. The dictionary includes terms drawn from a wide variety of topics relevant to computer users, including software, hardware, networking and so on. You can download this software from Download.com. Here is the link: http://download.cnet.com/HA-Computer-Dictionary/3000-2051_4-10885269.html]]></description>
			<content:encoded><![CDATA[<p><img src="http://i.i.com.com/cnwk.1d/i/tim/2009/11/01/202147_257x193.jpg" class="alignleft" /></p>
<p><b>HA Computer Dictionary</b> is a comprehensive dictionary of about 10,000 computer related terms and abbreviations. The dictionary includes terms drawn from a wide variety of topics relevant to computer users, including software, hardware, networking and so on.</p>
<p>You can download this software from Download.com. Here is the link:<br />
<a href="http://download.cnet.com/HA-Computer-Dictionary/3000-2051_4-10885269.html">http://download.cnet.com/HA-Computer-Dictionary/3000-2051_4-10885269.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hassan-ahmad.com/2010/08/ha-computer-dictionary/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bomberman Game</title>
		<link>http://www.hassan-ahmad.com/2010/08/bomberman-game-by-hassan-ahmad/</link>
		<comments>http://www.hassan-ahmad.com/2010/08/bomberman-game-by-hassan-ahmad/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 13:26:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Softwares]]></category>
		<category><![CDATA[bomber man]]></category>
		<category><![CDATA[bomberman]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[vb.net]]></category>

		<guid isPermaLink="false">http://www.hassan-ahmad.com/?p=33</guid>
		<description><![CDATA[Here is a very nice clone of classic old game: Bomberman. I developed this game about two years ago, but I just remembered it today so thought to post it on my blog. This is my first real application in VB.NET. Download the Game Download Source Code Note: This game requires .NET Framework to be [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a very nice clone of classic old game: <strong>Bomberman</strong>. I developed this game about two years ago, but I just remembered it today so thought to post it on my blog. This is my first real application in VB.NET.</p>
<p><a href="http://www.hassan-ahmad.com/wp-content/uploads/2010/08/bomberman.png"><img class="alignnone size-full wp-image-35" src="http://www.hassan-ahmad.com/wp-content/uploads/2010/12/bomberman.png" alt="" width="310" height="360" /></a></p>
<p><a href="http://www.hassan-ahmad.com/wp-content/uploads/2010/12/Bomberman.zip">Download the Game</a><br />
<a href="http://www.hassan-ahmad.com/wp-content/uploads/2010/12/Bomberman-source.zip">Download Source Code</a></p>
<p>Note: This game requires .NET Framework to be installed on your computer in order to run.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hassan-ahmad.com/2010/08/bomberman-game-by-hassan-ahmad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Login to website using VB.NET</title>
		<link>http://www.hassan-ahmad.com/2009/11/vb-net-login-to-website-programmatically-example-code/</link>
		<comments>http://www.hassan-ahmad.com/2009/11/vb-net-login-to-website-programmatically-example-code/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 16:47:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Software & Website Development]]></category>
		<category><![CDATA[code for login in vb.net]]></category>
		<category><![CDATA[cookiecontainer]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebook vb.net]]></category>
		<category><![CDATA[httpwebrequest]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[login to facebook vb.net]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[vb facebook login]]></category>
		<category><![CDATA[vb login facebook]]></category>
		<category><![CDATA[vb.net]]></category>
		<category><![CDATA[vb.net facebook login]]></category>
		<category><![CDATA[vb.net login example]]></category>

		<guid isPermaLink="false">http://www.hassan-ahmad.com/?p=4</guid>
		<description><![CDATA[The example below uses HttpWebRequest and HttpWebResponse classes to log in to Facebook. Dim cookieJar As New Net.CookieContainer&#40;&#41; Dim request As Net.HttpWebRequest Dim response As Net.HttpWebResponse Dim strURL As String &#160; Try 'Get Cookies strURL = &#34;https://login.facebook.com/login.php&#34; request = Net.HttpWebRequest.Create&#40;strURL&#41; request.UserAgent = &#34;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3&#34; request.Method = &#34;GET&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>The example below uses <strong>HttpWebRequest</strong> and <strong>HttpWebResponse</strong> classes to log in to Facebook.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Dim</span> cookieJar <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> Net.<span style="color: #0000FF;">CookieContainer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">Dim</span> request <span style="color: #FF8000;">As</span> Net.<span style="color: #0000FF;">HttpWebRequest</span>
<span style="color: #0600FF;">Dim</span> response <span style="color: #FF8000;">As</span> Net.<span style="color: #0000FF;">HttpWebResponse</span>
<span style="color: #0600FF;">Dim</span> strURL <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
&nbsp;
<span style="color: #0600FF;">Try</span>
     <span style="color: #008080; font-style: italic;">'Get Cookies</span>
     strURL <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;https://login.facebook.com/login.php&quot;</span>
     request <span style="color: #008000;">=</span> Net.<span style="color: #0000FF;">HttpWebRequest</span>.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span>strURL<span style="color: #000000;">&#41;</span>
     request.<span style="color: #0000FF;">UserAgent</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3&quot;</span>
     request.<span style="color: #0600FF;">Method</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;GET&quot;</span>
     request.<span style="color: #0000FF;">CookieContainer</span> <span style="color: #008000;">=</span> cookieJar
     response <span style="color: #008000;">=</span> request.<span style="color: #0000FF;">GetResponse</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
     <span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> tempCookie <span style="color: #FF8000;">As</span> Net.<span style="color: #0000FF;">Cookie</span> In response.<span style="color: #0000FF;">Cookies</span>
            cookieJar.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>tempCookie<span style="color: #000000;">&#41;</span>
     <span style="color: #FF8000;">Next</span>
&nbsp;
     <span style="color: #008080; font-style: italic;">'Send the post data now</span>
     request <span style="color: #008000;">=</span> Net.<span style="color: #0000FF;">HttpWebRequest</span>.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span>strURL<span style="color: #000000;">&#41;</span>
     request.<span style="color: #0000FF;">UserAgent</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3&quot;</span>
     request.<span style="color: #0600FF;">Method</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;POST&quot;</span>
     request.<span style="color: #0000FF;">AllowAutoRedirect</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
     request.<span style="color: #0000FF;">CookieContainer</span> <span style="color: #008000;">=</span> cookieJar
&nbsp;
     <span style="color: #0600FF;">Dim</span> writer <span style="color: #FF8000;">As</span> StreamWriter <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> StreamWriter<span style="color: #000000;">&#40;</span>request.<span style="color: #0000FF;">GetRequestStream</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
     writer.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;email=username&amp;pass=password&quot;</span><span style="color: #000000;">&#41;</span>
     writer.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
     response <span style="color: #008000;">=</span> request.<span style="color: #0000FF;">GetResponse</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
     <span style="color: #008080; font-style: italic;">'Get the data from the page</span>
     <span style="color: #0600FF;">Dim</span> stream <span style="color: #FF8000;">As</span> StreamReader <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> StreamReader<span style="color: #000000;">&#40;</span>response.<span style="color: #0000FF;">GetResponseStream</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
     <span style="color: #0600FF;">Dim</span> data <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> stream.<span style="color: #0000FF;">ReadToEnd</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
     response.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
     <span style="color: #0600FF;">If</span> data.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;title&gt;Facebook&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #008080; font-style: italic;">'LOGGED IN SUCCESSFULLY</span>
     <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
<span style="color: #0600FF;">Catch</span> ex <span style="color: #FF8000;">As</span> Exception
     <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Try</span></pre></div></div>

<p>Now, here is some explanation:</p>
<h2>Get Cookies</h2>
<p>The following block of code gets all the cookies from Facebook and stores them in a collection. These cookies are returned upon visiting the webpage: <span style="text-decoration: underline;">https://login.facebook.com/login.php</span>. Getting the cookies is very important, because they must be passed back to the webpage when you are going to login.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> tempCookie <span style="color: #FF8000;">As</span> Net.<span style="color: #0000FF;">Cookie</span> In response.<span style="color: #0000FF;">Cookies</span>
     cookieJar.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>tempCookie<span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">Next</span></pre></div></div>

<h2>Passing post data to the website</h2>
<p>Next, I created a <strong>StreamWriter</strong> class and wrote the post data to it. You can pass any data to the website here in <strong>name=value&amp;name=value</strong> format.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Dim</span> writer <span style="color: #FF8000;">As</span> StreamWriter <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> StreamWriter<span style="color: #000000;">&#40;</span>request.<span style="color: #0000FF;">GetRequestStream</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
writer.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;email=username&amp;pass=password&quot;</span><span style="color: #000000;">&#41;</span>
writer.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<h2>Finally&#8230;</h2>
<p>The following code gets the source code of the webpage returned which is the homepage of your account (i.e <strong>home.php</strong>), and checks if you are logged in successfully or not.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Dim</span> stream <span style="color: #FF8000;">As</span> StreamReader <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> StreamReader<span style="color: #000000;">&#40;</span>response.<span style="color: #0000FF;">GetResponseStream</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">Dim</span> data <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> stream.<span style="color: #0000FF;">ReadToEnd</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
response.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #0600FF;">If</span> data.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;&lt;title&gt;Facebook&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span> <span style="color: #FF8000;">Then</span>
     <span style="color: #008080; font-style: italic;">'LOGGED IN SUCCESSFULLY</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span></pre></div></div>

<p>I hope this simple example will help you save some time. If you find it useful then do let me know via your comments.</p>
<p>Happy Coding <img src='http://www.hassan-ahmad.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.hassan-ahmad.com/2009/11/vb-net-login-to-website-programmatically-example-code/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

