<?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>Open source blog, linux, php, python, security &#187; C++</title>
	<atom:link href="http://www.alonon.net/tag/cpp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alonon.net</link>
	<description></description>
	<lastBuildDate>Sat, 04 Feb 2012 07:23:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>

   <image>
    <title>Open source blog, linux, php, python, security</title>
    <url>http://0.gravatar.com/avatar/5152c5736f5f8dd9570ffb2f9068e8ab.png?s=48</url>
    <link>http://www.alonon.net</link>
   </image>
		<item>
		<title>Design Patterns</title>
		<link>http://www.alonon.net/design-patterns/</link>
		<comments>http://www.alonon.net/design-patterns/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 16:10:01 +0000</pubDate>
		<dc:creator>ALonon</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://www.alonon.net/?p=156</guid>
		<description><![CDATA[Design patterns is used in software to solve common problem. They can be grouped into 3 category (Creational patterns, Structural patterns, and Behavioral patterns) You can find some information about design patterns here Creational Patterns Abstract Factory (87) Provide an interface for creating families of related or dependent objects without specifying their concrete classes. Builder &#8230; <a href="http://www.alonon.net/design-patterns/">Read more <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Design patterns is used in software to solve common problem. They can be grouped into 3 category (Creational patterns, Structural patterns, and Behavioral patterns)</p>
<p>You can find some information about design patterns <a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/patcafso.htm">here</a></p>
<blockquote>
<h2><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/chap3fs.htm" target="_mainDisplayFrame">Creational Patterns</a></h2>
<dl><a name="absfact"></a>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat3afs.htm" target="_mainDisplayFrame">Abstract Factory (87)</a></strong> </dt>
<dd>Provide an interface for creating families of related or dependent objects without specifying their concrete classes. </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat3bfs.htm" target="_mainDisplayFrame">Builder (97)</a></strong> </dt>
<dd>Separate the construction of a complex object from its representation so that the same construction process can create different representations.  <a name="cat-factory"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat3cfs.htm" target="_mainDisplayFrame">Factory Method (107)</a></strong> </dt>
<dd>Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.  <a name="cat-proto"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat3dfs.htm" target="_mainDisplayFrame">Prototype (117)</a></strong> </dt>
<dd>Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.  <a name="cat-single"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat3efs.htm" target="_mainDisplayFrame">Singleton (127)</a></strong> </dt>
<dd>Ensure a class only has one instance, and provide a global point of access to it.</p>
<p><a name="disc3"></a></p>
</dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/disc3fs.htm" target="_mainDisplayFrame">Discussion of Creational Patterns</a></strong> </dt>
</dl>
<p><a name="structural"></a></p>
<h2><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/chap4fs.htm" target="_mainDisplayFrame">Structural Patterns</a></h2>
<dl><a name="adapter"></a>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat4afs.htm" target="_mainDisplayFrame">Adapter (139)</a></strong> </dt>
<dd>Convert the interface of a class into another interface clients expect.  Adapter lets classes work together that couldn&#8217;t otherwise because of incompatible interfaces. </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat4bfs.htm" target="_mainDisplayFrame">Bridge (151)</a></strong> </dt>
<dd>Decouple an abstraction from its implementation so that the two can vary independently. </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat4cfs.htm" target="_mainDisplayFrame">Composite (163)</a></strong> </dt>
<dd>Compose objects into tree structures to represent part-whole hierarchies.  Composite lets clients treat individual objects and compositions of objects uniformly.  <a name="cat-dec"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat4dfs.htm" target="_mainDisplayFrame">Decorator (175)</a></strong> </dt>
<dd>Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.  <a name="cat-facade"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat4efs.htm" target="_mainDisplayFrame">Facade (185)</a></strong> </dt>
<dd>Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.  <a name="cat-flywt"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat4ffs.htm" target="_mainDisplayFrame">Flyweight (195)</a></strong> </dt>
<dd>Use sharing to support large numbers of fine-grained objects efficiently.  <a name="cat-proxy"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat4gfs.htm" target="_mainDisplayFrame">Proxy (207)</a></strong> </dt>
<dd>Provide a surrogate or placeholder for another object to control access to it.</p>
<p><a name="disc4"></a></p>
</dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/disc4fs.htm" target="_mainDisplayFrame">Discussion of Structural Patterns</a></strong> </dt>
</dl>
<p><a name="behavioral"></a></p>
<h2><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/chap5fs.htm" target="_mainDisplayFrame">Behavioral Patterns</a></h2>
<dl>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5afs.htm" target="_mainDisplayFrame">Chain of Responsibility (223)</a></strong> </dt>
<dd>Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.  Chain the receiving objects and pass the request along the chain until an object handles it. </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5bfs.htm" target="_mainDisplayFrame">Command (233)</a></strong> </dt>
<dd>Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5cfs.htm" target="_mainDisplayFrame">Interpreter (243)</a></strong> </dt>
<dd>Given a language, define a represention for its grammar along with an interpreter that uses the representation to interpret sentences in the language. </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5dfs.htm" target="_mainDisplayFrame">Iterator (257)</a></strong> </dt>
<dd>Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.  <a name="cat-media"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5efs.htm" target="_mainDisplayFrame">Mediator (273)</a></strong> </dt>
<dd>Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.  <a name="cat-memen"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5ffs.htm" target="_mainDisplayFrame">Memento (283)</a></strong> </dt>
<dd>Without violating encapsulation, capture and externalize an object&#8217;s internal state so that the object can be restored to this state later. </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5gfs.htm" target="_mainDisplayFrame">Observer (293)</a></strong> </dt>
<dd>Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.  <a name="cat-state"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5hfs.htm" target="_mainDisplayFrame">State (305)</a></strong> </dt>
<dd>Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.  <a name="cat-strat"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5ifs.htm" target="_mainDisplayFrame">Strategy (315)</a></strong> </dt>
<dd>Define a family of algorithms, encapsulate each one, and make them interchangeable.  Strategy lets the algorithm vary independently from clients that use it.  <a name="cat-tempmeth"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5jfs.htm" target="_mainDisplayFrame">Template Method (325)</a></strong> </dt>
<dd>Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm&#8217;s structure.  <a name="cat-visit"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5kfs.htm" target="_mainDisplayFrame">Visitor (331)</a></strong> </dt>
</dl>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">
<h2><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/chap3fs.htm" target="_mainDisplayFrame">Creational Patterns</a></h2>
<dl><a name="absfact"></a>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat3afs.htm" target="_mainDisplayFrame">Abstract Factory (87)</a></strong> </dt>
<dd>Provide an interface for creating families of related or dependent objects without specifying their concrete classes. </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat3bfs.htm" target="_mainDisplayFrame">Builder (97)</a></strong> </dt>
<dd>Separate the construction of a complex object from its representation so that the same construction process can create different representations.  <a name="cat-factory"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat3cfs.htm" target="_mainDisplayFrame">Factory Method (107)</a></strong> </dt>
<dd>Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.  <a name="cat-proto"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat3dfs.htm" target="_mainDisplayFrame">Prototype (117)</a></strong> </dt>
<dd>Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.  <a name="cat-single"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat3efs.htm" target="_mainDisplayFrame">Singleton (127)</a></strong> </dt>
<dd>Ensure a class only has one instance, and provide a global point of access to it.</p>
<p><a name="disc3"></a></p>
</dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/disc3fs.htm" target="_mainDisplayFrame">Discussion of Creational Patterns</a></strong> </dt>
</dl>
<p><a name="structural"></a></p>
<h2><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/patcat.htm#behavioral"><img src="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/gifsb/down3.gif" border="0" alt="next:  Behavioral Patterns" width="12" height="18" /></a> <a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/chap4fs.htm" target="_mainDisplayFrame">Structural Patterns</a></h2>
<dl><a name="adapter"></a>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat4afs.htm" target="_mainDisplayFrame">Adapter (139)</a></strong> </dt>
<dd>Convert the interface of a class into another interface clients expect.  Adapter lets classes work together that couldn&#8217;t otherwise because of incompatible interfaces. </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat4bfs.htm" target="_mainDisplayFrame">Bridge (151)</a></strong> </dt>
<dd>Decouple an abstraction from its implementation so that the two can vary independently. </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat4cfs.htm" target="_mainDisplayFrame">Composite (163)</a></strong> </dt>
<dd>Compose objects into tree structures to represent part-whole hierarchies.  Composite lets clients treat individual objects and compositions of objects uniformly.  <a name="cat-dec"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat4dfs.htm" target="_mainDisplayFrame">Decorator (175)</a></strong> </dt>
<dd>Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.  <a name="cat-facade"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat4efs.htm" target="_mainDisplayFrame">Facade (185)</a></strong> </dt>
<dd>Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.  <a name="cat-flywt"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat4ffs.htm" target="_mainDisplayFrame">Flyweight (195)</a></strong> </dt>
<dd>Use sharing to support large numbers of fine-grained objects efficiently.  <a name="cat-proxy"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat4gfs.htm" target="_mainDisplayFrame">Proxy (207)</a></strong> </dt>
<dd>Provide a surrogate or placeholder for another object to control access to it.</p>
<p><a name="disc4"></a></p>
</dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/disc4fs.htm" target="_mainDisplayFrame">Discussion of Structural Patterns</a></strong> </dt>
</dl>
<p><a name="behavioral"></a></p>
<h2><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/patcat.htm#last"><img src="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/gifsb/down3.gif" border="0" alt="next:  navigation" width="12" height="18" /></a> <a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/chap5fs.htm" target="_mainDisplayFrame">Behavioral Patterns</a></h2>
<dl>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5afs.htm" target="_mainDisplayFrame">Chain of Responsibility (223)</a></strong> </dt>
<dd>Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.  Chain the receiving objects and pass the request along the chain until an object handles it. </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5bfs.htm" target="_mainDisplayFrame">Command (233)</a></strong> </dt>
<dd>Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5cfs.htm" target="_mainDisplayFrame">Interpreter (243)</a></strong> </dt>
<dd>Given a language, define a represention for its grammar along with an interpreter that uses the representation to interpret sentences in the language. </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5dfs.htm" target="_mainDisplayFrame">Iterator (257)</a></strong> </dt>
<dd>Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.  <a name="cat-media"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5efs.htm" target="_mainDisplayFrame">Mediator (273)</a></strong> </dt>
<dd>Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.  <a name="cat-memen"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5ffs.htm" target="_mainDisplayFrame">Memento (283)</a></strong> </dt>
<dd>Without violating encapsulation, capture and externalize an object&#8217;s internal state so that the object can be restored to this state later. </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5gfs.htm" target="_mainDisplayFrame">Observer (293)</a></strong> </dt>
<dd>Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.  <a name="cat-state"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5hfs.htm" target="_mainDisplayFrame">State (305)</a></strong> </dt>
<dd>Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.  <a name="cat-strat"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5ifs.htm" target="_mainDisplayFrame">Strategy (315)</a></strong> </dt>
<dd>Define a family of algorithms, encapsulate each one, and make them interchangeable.  Strategy lets the algorithm vary independently from clients that use it.  <a name="cat-tempmeth"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5jfs.htm" target="_mainDisplayFrame">Template Method (325)</a></strong> </dt>
<dd>Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm&#8217;s structure.  <a name="cat-visit"></a> </dd>
<dt><strong><a href="http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/book/hires/pat5kfs.htm" target="_mainDisplayFrame">Visitor (331)</a></strong> </dt>
<dd>Represent an operation to be performed on the elements of an object structure.  Visitor lets you define a new operation without changing the classes of the elements on which it operates. </dd>
</dl>
</div>
<dd>Represent an operation to be performed on the elements of an object structure.  Visitor lets you define a new operation without changing the classes of the elements on which it operates. </dd>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.alonon.net/design-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My C++ Homework</title>
		<link>http://www.alonon.net/my-c-homework/</link>
		<comments>http://www.alonon.net/my-c-homework/#comments</comments>
		<pubDate>Mon, 18 May 2009 08:06:10 +0000</pubDate>
		<dc:creator>ALonon</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[homework]]></category>
		<category><![CDATA[stack]]></category>

		<guid isPermaLink="false">http://www.alonon.net/?p=102</guid>
		<description><![CDATA[Here is the question, homework is containing the stack library ( written by me ), inheritance, nested if, constructor, destructor. You can see the sample. I had 2 hours to finish and send , so it is not a perfect code. (Even i would have time, i don&#8217;t think i can write perfect code ) &#8230; <a href="http://www.alonon.net/my-c-homework/">Read more <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here is the question, homework is containing the stack library ( written by me ), inheritance, nested if, constructor, destructor. You can see the sample. I had 2 hours to finish and send , so it is not a perfect code. (Even i would have time, i don&#8217;t think i can write perfect code <img src='http://www.alonon.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) Anyway, you can download <a href="http://www.alonon.net/download/cpp/hw/hw-2-2.cpp">cpp file from here</a>, and <a href="http://www.alonon.net/download/cpp/hw/oestack.h">here is stack file</a></p>
<blockquote><p>Problem:</p>
<p>You are expected to find an escape route from a maze. The maze is inputted by user with 1&#8242;s and 0&#8242;s, where 1 represents a wall and 0 represents a road. Maze is a grid of cells, which can be considered as a 2-D array having cells. The start point for the maze is always at cell (1, 1) and exit from the maze will be always at cell (3, 3). (Consider a 5&#215;5 matrix with walls in its outer boarders).<br />
For finding the path, move from the starting cell and search for the neighbors of that cell by checking the cells in the directions North, East, South, and West. The search for the available neighbors will be in clockwise direction (so start checking North cell, then East cell,&#8230;)<br />
Assume there is one possible route to exit.<br />
Use class Cell to hold position and information for each cell in the maze grid as:</p>
<p>Classes:<br />
class Cell</p>
<p>{ int row, column, direction;</p>
<p>bool visited;</p>
<p>int wallstatus; //could be 1 or 0</p>
<p>public:</p>
<p>//necessary members for the Cell</p>
<p>};<br />
To play the game, create class Game:<br />
class Game</p>
<p>{<br />
//Matrix to hold the maze of cells</p>
<p>// Cell position of the goal</p>
<p>// Current Position on the Matrix<br />
// Next Position of the Matrix</p>
<p>//Stack to hold the positions in the path</p>
<p>public:</p>
<p>//constructor to read the shape of the maze from user, and store it to the</p>
<p>matrix, and store the position of the goal. Then it will call the function to</p>
<p>traverse the maze</p>
<p>//function to perform the traversal</p>
<p>//function to calculate and return the next position using the table below</p>
<p>//function to set outer cells as wall.<br />
//function to get all user input and generate the maze</p>
<p>//function to check whether you can move from current location or not</p>
<p>(direction&lt;=3?)</p>
<p>//other necessary functions<br />
};<br />
Algorithm:</p>
<p>The maze traversal will be done using a stack. It will be used to store the cells for the route to the exit. The possible traversal algorithm will be as follows:<br />
Start from (1,1) position, and set direction to 0</p>
<p>Push this cell to stack</p>
<p>While (stack is not empty &amp;&amp; the goal is not found)</p>
<p>If you can&#8217;t move from current position and stack is not empty Pop () the stack</p>
<p>to go to the previous location</p>
<p>While (until all the directions are checked &amp;&amp;until the goal is not found)//there are available moves from current position</p>
<p>Find the nextrow and nextcolumn positions from the current direction</p>
<p>If (newrow and newcolumn is the goal)</p>
<p>Push the location and exit from loops</p>
<p>Else if (the new position is not a wall &amp;&amp; it was not visited before)</p>
<p>{ Mark the new position as visited in the matrix</p>
<p>Check the next direction by updating it by 1</p>
<p>Push the new position with its row, column and direction to stack</p>
<p>Update current row&amp; column with the new ones</p>
<p>Update direction as 0 to start searching for the available location</p>
<p>from north</p>
<p>}</p>
<p>Else</p>
<p>Check the next direction by updating the direction by 1</p>
<p>If (the goal is found)</p>
<p>While (stack not empty)</p>
<p>Pop the stack and output</p>
<p>Else</p>
<p>Maze does not have an exit<br />
To calculate new row and column values to move in different directions, use the following table:</p>
<p>Direction</p>
<p>direction value</p>
<p>update for row</p>
<p>update for column</p>
<p>North</p>
<p>0</p>
<p>-1</p>
<p>0</p>
<p>East</p>
<p>1</p>
<p>0</p>
<p>1</p>
<p>South</p>
<p>2</p>
<p>1</p>
<p>0</p>
<p>West</p>
<p>3</p>
<p>0</p>
<p>-1<br />
At the end of the game, the points for the escape route with their row and column values and the hop number required to escape will be displayed.<br />
Sample Run: (For 5&#215;5 mazes)</p>
<p>Enter the maze:<br />
000</p>
<p>101</p>
<p>100<br />
5 hops needed for escape</p>
<p>The cells to follow:</p>
<p>(1, 1)</p>
<p>(1, 2)</p>
<p>(2, 2)</p>
<p>(3, 2)</p>
<p>(3, 3)<br />
The Maze Generated by User Input in the Sample Run:</p>
<p>&lt;!&#8211; 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } 	&#8211;&gt;</p>
<table border="1" cellspacing="0" cellpadding="7" width="248" bordercolor="#000000">
<col width="34"></col>
<col width="35"></col>
<col width="35"></col>
<col width="35"></col>
<col width="35"></col>
<tbody>
<tr>
<td width="34" height="18">
<p lang="en-US" align="center">1</p>
</td>
<td width="35">
<p lang="en-US" align="center">1</p>
</td>
<td width="35">
<p lang="en-US" align="center">1</p>
</td>
<td width="35">
<p lang="en-US" align="center">1</p>
</td>
<td width="35">
<p lang="en-US" align="center">1</p>
</td>
</tr>
<tr>
<td width="34" height="21">
<p lang="en-US" align="center">1</p>
</td>
<td width="35">
<p lang="en-US" align="center">0</p>
</td>
<td width="35">
<p lang="en-US" align="center">0</p>
</td>
<td width="35">
<p lang="en-US" align="center">0</p>
</td>
<td width="35">
<p lang="en-US" align="center">1</p>
</td>
</tr>
<tr>
<td width="34" height="19">
<p lang="en-US" align="center">1</p>
</td>
<td width="35">
<p lang="en-US" align="center">1</p>
</td>
<td width="35">
<p lang="en-US" align="center">0</p>
</td>
<td width="35">
<p lang="en-US" align="center">1</p>
</td>
<td width="35">
<p lang="en-US" align="center">1</p>
</td>
</tr>
<tr>
<td width="34" height="21">
<p lang="en-US" align="center">1</p>
</td>
<td width="35">
<p lang="en-US" align="center">1</p>
</td>
<td width="35">
<p lang="en-US" align="center">0</p>
</td>
<td width="35">
<p lang="en-US" align="center">0</p>
</td>
<td width="35">
<p lang="en-US" align="center">1</p>
</td>
</tr>
<tr>
<td width="34" height="20">
<p lang="en-US" align="center">1</p>
</td>
<td width="35">
<p lang="en-US" align="center">1</p>
</td>
<td width="35">
<p lang="en-US" align="center">1</p>
</td>
<td width="35">
<p lang="en-US" align="center">1</p>
</td>
<td width="35">
<p lang="en-US" align="center">1</p>
</td>
</tr>
</tbody>
</table>
<p>In the Sample run we say it&#8217;s a 5&#215;5 matrix, but we get the input of a 3&#215;3 matrix because the outside of the maze is always a wall which will not be inputted from the user. The Matrix above shows the final maze inputted by the user.</p></blockquote>
<pre lang="cpp">#include "oestack.h"
#include &lt;iostream&gt; // including library
using namespace std;
#include &lt;string&gt;
class cell // class of cell
{
	int row,column;
	int visited;
	int wallstatus;
	public:
		void addcell(int a,int b,int c) // which row, which column and also is it a wall, save this info.
		{
		  row=a;
		  column=b;
		  wallstatus=c;
		  visited=0;
		}
		void editvisit() //for checking.
		{
			visited=1;
		}
		int checkvisit()
		{
			return visited;
		}
		int checkwall()
		{
			return wallstatus;
		}
		int checkrow()
		{
			return row;
		}
		int checkcolumn()
		{
			return column;
		}
};

class game:public cell
{

	public:
		stack&lt;cell&gt; stackcell; //created a stack type of cell
		cell kop[5][5]; // created an array from cell object
	game()
	{

		int l,z,i;

		for(i=0; i&lt;5; i++) // All cell is visited now, all of them is wall.
		{
			for(int k=0;k&lt;5; k++)
			{
				kop[i][k].addcell(1,1,1);
			}
		}
		cout&lt;&lt;"Enter maze from left to right:"&lt;&lt;endl&lt;&lt;"***"&lt;&lt;endl&lt;&lt;"***"&lt;&lt;endl&lt;&lt;"***"&lt;&lt;endl;
		cout&lt;&lt;"Enter 1 for wall , 0 for gate, but like, 0 enter 1 enter 0 enter ... (nine times)"&lt;&lt;endl; //You should write nine times,I didn't use getch or smt like that so you have to write by one by

		for(int j=1; j&lt;4; j++) //Create 9 cell for maze , for each cell, write it is cell or wall. From left to right
		{
			for(l=1;l&lt;4;l++)
			{
				cin&gt;&gt;z;
				kop[j][l].addcell(l,j,z); //create
			}

		}

		for(i=0; i&lt;5; i++) // write our maze to the screen
		{
			for(int k=0;k&lt;5; k++)
			{
				cout&lt;&lt;kop[i][k].checkwall();
			}
			cout&lt;&lt;endl;
		}
	}

	void find_goal()
	{
		int i=1,k=1,found=0; // i and k is 1 because we start from cell (1,1)
		cell start,back,yaz; // i need three object
		stack&lt;cell&gt; terstenyaz(9); // to write from last <img src='http://www.alonon.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
		start = kop[i][k]; // start
		kop[i][k].editvisit(); // you visited where you start.
		stackcell.push(start); // put (1,1) (start place) to in your stack
		while (found == 0) // found 0
		{
			if(kop[i][k].checkrow()==3 &amp;&amp; kop[i][k].checkcolumn()==3) // if end of the maze
			{
				found =1; // find way to escape
			}

			else if(kop[i][k-1].checkwall() == 0 &amp;&amp; kop[i][k-1].checkvisit() != 1) //check left , if not visited then go
			{

				k=k-1;
				kop[i][k].editvisit();
				stackcell.push(kop[i][k]);
			}
			else if(kop[i+1][k].checkwall() == 0 &amp;&amp; kop[i+1][k].checkvisit() != 1) //check below , if not visited then go
			{
				i=i+1;
				kop[i][k].editvisit();
				stackcell.push(kop[i][k]);
			}
			else if(kop[i][k+1].checkwall() == 0 &amp;&amp; kop[i][k+1].checkvisit() != 1) //check right , if not visited then go
			{
				k=k+1;
				kop[i][k].editvisit();
				stackcell.push(kop[i][k]);
			}
			else if (kop[i][k].checkrow() == 1 &amp;&amp; kop[i][k].checkcolumn()== 1) // if you go back to start then there is no escape from maze
				{
				cout&lt;&lt;"No escape from there"&lt;&lt;endl;
				found = 1;
			}
			else if(kop[i-1][k].checkwall() == 0 and kop[i-1][k].checkvisit() == 0) //check up , if not visited then go
			{
				i=i-1;
				kop[i][k].editvisit();
				stackcell.push(kop[i][k]);
			}
			else //if you can not go anywhere , go 1 cell back and check there is another way or not.
			{
				back = stackcell.pop();
				i = back.checkrow();
				k = back.checkcolumn();
			}

		}

		if(found == 1) // escaped
		{

			while(stackcell.isEmpty() != 0) //to write from last to first, maybe recursive functions can be used,but i had no time to use it.
			{
				yaz = stackcell.pop();
				terstenyaz.push(yaz);
			}

			while(terstenyaz.isEmpty() != 0) //write on screen
			{
				yaz=terstenyaz.pop();
				cout&lt;&lt;"("&lt;&lt;yaz.checkcolumn()&lt;&lt;","&lt;&lt;yaz.checkrow()&lt;&lt;")"&lt;&lt;endl;
			}

		}

	}

};
	int main ()
	{
		game a; //call
		a.find_goal();
		getchar();
		getchar();
	}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.alonon.net/my-c-homework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Friend Functions</title>
		<link>http://www.alonon.net/c-friend-functions/</link>
		<comments>http://www.alonon.net/c-friend-functions/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 21:02:46 +0000</pubDate>
		<dc:creator>ALonon</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[c++ example]]></category>
		<category><![CDATA[friend functions]]></category>
		<category><![CDATA[friends]]></category>

		<guid isPermaLink="false">http://www.alonon.net/?p=20</guid>
		<description><![CDATA[A class can allow non-member functions and other classes to access its own private data, by making them as friends. This part of C++ tutorial essentially gives two important points. Once a non-member function is declared as a friend, it can access the private data of the class similarly when a class is declared as &#8230; <a href="http://www.alonon.net/c-friend-functions/">Read more <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A class can allow non-member functions and other classes to access its own private data, by making them as  <strong>friends</strong>. This part of C++ tutorial essentially gives two important points.</p>
<ul>
<li>Once a non-member function is declared as a friend, it can access the private data of the class</li>
<li>similarly when a class is declared as a friend, the friend class can have access to the private data of the class which made this a friend</li>
</ul>
<p>Here is an example</p>
<pre lang="cpp">/* Onur AKTAS - alonon.net
 * 15/12/2008
 * Friend Functions
 */
#include <iostream>
using namespace std;
class INTEGER
{
	int num; // private variable
public:
	INTEGER(int n=0) {num = n;} // constructor to assign n to num
	friend void add(INTEGER &#038;x,INTEGER &#038;y); // this is friend function, it is not a member function, and can not write in class
};
void add (INTEGER &#038;x,INTEGER &#038;y) // do not write friend at the begining
{
  cout<<"Addition is: "<<x.num+y.num<<endl; // plus x's num with y's num
}
int main ()
{
	INTEGER x(5);
	INTEGER y(6);
	add(x,y);
	return 0;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.alonon.net/c-friend-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compile C C++ in linux</title>
		<link>http://www.alonon.net/compile_c_cplus_in_linux/</link>
		<comments>http://www.alonon.net/compile_c_cplus_in_linux/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 22:32:15 +0000</pubDate>
		<dc:creator>ALonon</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[CDT]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[pardus]]></category>

		<guid isPermaLink="false">http://www.alonon.net/?p=14</guid>
		<description><![CDATA[i have studied c++ for my exam today and i will explain how can you compile c/c++ in linux also there were some error that i want mention. 1.install eclipse (not necessary for compiling) probably you can find it from your package manager if there isn&#8217;t use this link: http://www.eclipse.org for pardus open pisi search &#8230; <a href="http://www.alonon.net/compile_c_cplus_in_linux/">Read more <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>i have studied c++ for my exam today and i will explain how can you compile c/c++ in linux also there were some error that i want mention.</p>
<p>1.install eclipse (not necessary for compiling)<br />
probably you can find it from your package manager if there isn&#8217;t<br />
use this link: http://www.eclipse.org<br />
for pardus open pisi search for eclipse and install it ( 3.3)</p>
<p>2. install CDT plugin for eclipse<br />
open eclipse help -&gt; software updates -&gt; avilable softwares -&gt; add site<br />
for eclipse 3.4 add this:</p>
<p>http://download.eclipse.org/tools/cdt/releases/ganymede</p>
<p>for eclipse 3.3 add this:</p>
<p>http://download.eclipse.org/tools/cdt/releases/europa</p>
<p>check it and click install</p>
<p>you have eclipse CDT to write your c and c++ codes<br />
now you need gcc to compile it</p>
<p>3. install gcc<br />
find gcc from your package manager.<br />
for pardus write this to console<br />
sudo pisi it gcc</p>
<p>4. first simple<br />
i opened a new c++ project from eclipse, created new source file, writed my code and saved. when i am trying to make file,<br />
I received this message &#8220;(Exec error:Cannot run make)&#8221; .</p>
<p><strong>(solution: install make from your package manager.For pardus write this sudo pisi it make.)</strong></p>
<p>after that i tried it on console with giving this command</p>
<p>(for c++ codes)</p>
<blockquote><p>g++ example.cpp</p></blockquote>
<p>(for c codes)</p>
<blockquote><p>gcc example.c</p></blockquote>
<p>however, i received &#8220;iostream.h: No such file or directory gcc&#8221;<br />
<strong>solution: delete .h just write &lt;iostream&gt; also write g++ for *.cpp files<br />
</strong></p>
<p>after i installed make, i was able to compile it from console and eclipse.</p>
<p>if you want to see your code&#8217;s output:</p>
<blockquote><p>g++ example.cpp</p></blockquote>
<p>it makes a compiled file named example in your folder</p>
<p>to run it just write</p>
<blockquote><p>./example</p></blockquote>
<p>i hope , help you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alonon.net/compile_c_cplus_in_linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

