<?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>electrofriends.com &#187; Algorithms</title>
	<atom:link href="http://electrofriends.com/tag/algorithms/feed/" rel="self" type="application/rss+xml" />
	<link>http://electrofriends.com</link>
	<description>...bringing innovative minds together</description>
	<lastBuildDate>Fri, 11 May 2012 08:44:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>C++ program to implement three classes using multiple inheritance</title>
		<link>http://electrofriends.com/source-codes/software-programs/cpp-programs/cpp-advanced-programs/c-program-to-implement-three-classes-using-multiple-inheritance/</link>
		<comments>http://electrofriends.com/source-codes/software-programs/cpp-programs/cpp-advanced-programs/c-program-to-implement-three-classes-using-multiple-inheritance/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 15:11:45 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[Advanced programs]]></category>
		<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[codes]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[implement three class]]></category>
		<category><![CDATA[multiple inheritance]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=1060</guid>
		<description><![CDATA[MULTIPLE INHERITANCES AIM: Write a program to illustrating how all the three classes are implemented in multiple inheritance mode ALGORITHM • Start the process • Invoke the class M • Invoke the another class N • Invoke one more class,ie class P,which is inherited by both M and N • Create an object for class [...]]]></description>
			<content:encoded><![CDATA[<p><strong>MULTIPLE INHERITANCES</strong></p>
<p><strong>AIM:</strong><br />
Write a program to illustrating how all the three classes are implemented in multiple inheritance mode</p>
<p><strong>ALGORITHM</strong><br />
•	Start the process<br />
•	Invoke the class M<br />
•	Invoke the another class N<br />
•	Invoke one more class,ie class P,which is inherited by both M and N<br />
•	Create an object for class p,ie P p<br />
•	Call p.get_m(),assign the value in to ‘m’<br />
•	Call p.get_n(),assign the value in to ‘n’<br />
•	Call display(), for dispay the result<br />
•	Stop the result </p>
<p><strong>PROGRAM:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">	<span style="color: #339900;">#include&lt;iosteram.h&gt;</span>
	<span style="color: #339900;">#include&lt;conio.h&gt;</span>
&nbsp;
	Class M
        <span style="color: #008000;">&#123;</span>
		Protected<span style="color: #008080;">:</span>
		Int m<span style="color: #008080;">;</span>
		Public <span style="color: #008080;">:</span>
		Void get_M<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
	Class N
        <span style="color: #008000;">&#123;</span>		
		Protected<span style="color: #008080;">:</span>
		Int n<span style="color: #008080;">;</span>
		Public<span style="color: #008080;">:</span>
		Void get_N<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
	Class p<span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> M, <span style="color: #0000ff;">public</span> N 		
	<span style="color: #008000;">&#123;</span>
		Public<span style="color: #008080;">:</span>
		Void disply<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
	Void M <span style="color: #008080;">::</span><span style="color: #007788;">get_m</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> x<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		m<span style="color: #000080;">=</span>x<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	Void N<span style="color: #008080;">::</span><span style="color: #007788;">get_n</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> y<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		n<span style="color: #000080;">=</span>y<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	Void P<span style="color: #008080;">::</span> <span style="color: #007788;">disply</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
	Cout<span style="color: #000080;">&lt;&lt;</span>”m<span style="color: #000080;">=</span>”<span style="color: #000080;">&lt;&lt;</span>m<span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	Cout<span style="color: #000080;">&lt;&lt;</span>”n<span style="color: #000080;">=</span>”<span style="color: #000080;">&lt;&lt;</span>n<span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	Cout<span style="color: #000080;">&lt;&lt;</span>”m<span style="color: #000040;">*</span>n<span style="color: #000080;">=</span>”<span style="color: #000080;">&lt;&lt;</span>m<span style="color: #000040;">*</span>n<span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<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>
		P p<span style="color: #008080;">;</span>
		p.<span style="color: #007788;">get_m</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">10</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		p.<span style="color: #007788;">get_n</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">20</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		p.<span style="color: #007788;">display</span><span style="color: #008000;">&#40;</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>

<p><strong>OUTPUT</strong></p>
<p>	m=10<br />
	n=20<br />
	m*n=200</p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/source-codes/software-programs/cpp-programs/cpp-advanced-programs/c-program-to-implement-three-classes-using-multiple-inheritance/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>C++ program to print student details using constructor and destructor</title>
		<link>http://electrofriends.com/source-codes/software-programs/cpp-programs/cpp-advanced-programs/c-program-to-print-student-details-using-constructor-and-destructor/</link>
		<comments>http://electrofriends.com/source-codes/software-programs/cpp-programs/cpp-advanced-programs/c-program-to-print-student-details-using-constructor-and-destructor/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 18:22:49 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[Advanced programs]]></category>
		<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[c programs]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[cpp class]]></category>
		<category><![CDATA[destructor]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=1046</guid>
		<description><![CDATA[CONSTRUCTOR AND DESTRUCTOR AIM: A program to print student details using constructor and destructor ALGORITHAM: 1. Start the process 2. Invoke the classes 3. Call the read() function a. Get the inputs name ,roll number and address 4. Call the display() function a. Display the name,roll number,and address of the student 5. Stop the process [...]]]></description>
			<content:encoded><![CDATA[<p>CONSTRUCTOR AND DESTRUCTOR<br />
<strong>AIM: </strong><br />
	A program to print student details using constructor and destructor</p>
<p><strong>ALGORITHAM:</strong> </p>
<p>1.	Start the process<br />
2.	Invoke the classes<br />
3.	Call the read() function<br />
a.	Get the inputs name ,roll number and address<br />
4.	Call the display() function<br />
a.	Display the name,roll number,and address of the student<br />
5.	Stop the process</p>
<p><strong>PROGRAM</strong></p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include&lt;iostream.h&gt;</span>
<span style="color: #339900;">#include&lt;conio.h&gt;</span>
<span style="color: #0000ff;">class</span> stu
<span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span> <span style="color: #0000ff;">char</span> name<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">20</span><span style="color: #008000;">&#93;</span>,add<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">20</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
		  	<span style="color: #0000ff;">int</span> roll,zip<span style="color: #008080;">;</span>
		<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span> stu <span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #666666;">//Constructor</span>
			~stu<span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span><span style="color: #666666;">//Destructor</span>
			<span style="color: #0000ff;">void</span> read<span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">void</span> disp<span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>			
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
stu <span style="color: #008080;">::</span> <span style="color: #007788;">stu</span><span style="color: #008000;">&#40;</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>”This is Student Details”<span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">void</span> stu <span style="color: #008080;">::</span> <span style="color: #007788;">read</span><span style="color: #008000;">&#40;</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>”Enter the student Name”<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cin</span><span style="color: #000080;">&gt;&gt;</span>name<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>”Enter the student roll no “<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cin</span><span style="color: #000080;">&gt;&gt;</span>roll<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>”Enter the student address”<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cin</span><span style="color: #000080;">&gt;&gt;</span>add<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>”Enter the Zipcode”<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cin</span><span style="color: #000080;">&gt;&gt;</span>zip<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">void</span> stu <span style="color: #008080;">::</span> <span style="color: #007788;">disp</span><span style="color: #008000;">&#40;</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>”Student Name <span style="color: #008080;">:</span>”<span style="color: #000080;">&lt;&lt;</span>name<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>”Roll no   is       <span style="color: #008080;">:</span>”<span style="color: #000080;">&lt;&lt;</span>roll<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>”Address is       <span style="color: #008080;">:</span>”<span style="color: #000080;">&lt;&lt;</span>add<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>”Zipcode is       <span style="color: #008080;">:</span>”<span style="color: #000080;">&lt;&lt;</span>zip<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
stu <span style="color: #008080;">:</span> <span style="color: #008080;">:</span> ~stu<span style="color: #008000;">&#40;</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>”Student Detail is Closed”<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> main<span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	stu s<span style="color: #008080;">;</span>
	clrscr<span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
s.<span style="color: #007788;">read</span> <span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
s.<span style="color: #007788;">disp</span> <span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
getch<span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><strong>Output:</strong></p>
<p>Enter the student Name<br />
James<br />
Enter the student roll no<br />
01<br />
Enter the student address<br />
Newyork<br />
Enter the Zipcode<br />
919108</p>
<p>Student Name : James<br />
Roll no   is       : 01<br />
Address is       : Newyork<br />
Zipcode is       :919108</p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/source-codes/software-programs/cpp-programs/cpp-advanced-programs/c-program-to-print-student-details-using-constructor-and-destructor/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>C++ program for implementation of class</title>
		<link>http://electrofriends.com/source-codes/software-programs/cpp-programs/cpp-advanced-programs/c-program-for-implementation-of-class/</link>
		<comments>http://electrofriends.com/source-codes/software-programs/cpp-programs/cpp-advanced-programs/c-program-for-implementation-of-class/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 09:45:07 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[Advanced programs]]></category>
		<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[c++ class]]></category>
		<category><![CDATA[C++ Programs]]></category>
		<category><![CDATA[class implementations]]></category>
		<category><![CDATA[Source Codes]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=1044</guid>
		<description><![CDATA[AIM: A program to solve a quadratic equation, using OOP techniques. ALGORITHM: 1) Start the process 2) Invoke the classes 3) Get the input for a,b,c; 4) Call the function getinfo() and display() 5) Check if a=0 a) True : compute c/b; i) Print the value of a/c; b) False: compute b*b-4*a*c; i) If ( [...]]]></description>
			<content:encoded><![CDATA[<p><strong>AIM: 	</strong><br />
	A program to solve a quadratic equation, using OOP techniques.</p>
<p><strong>ALGORITHM: </strong></p>
<p>1)	Start the process<br />
2)	Invoke the classes<br />
3)	Get the input for a,b,c;<br />
4)	Call the function getinfo() and display()<br />
5)	Check if a=0<br />
a)	True : compute c/b;<br />
i)	Print the value of a/c;<br />
b)	False: compute b*b-4*a*c;<br />
i)	If ( b*b-4*a*c)=0<br />
ii)	Call img();<br />
iii)	Otherwise : call real(a,b,c);<br />
6)	Stop the process</p>
<p><strong>PROGRAM:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">	<span style="color: #339900;">#include&lt;iostream.h&gt;</span>
	<span style="color: #339900;">#include&lt;conio.h&gt;</span>
		<span style="color: #0000ff;">class</span> equation
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span><span style="color: #0000ff;">float</span> a,b,c<span style="color: #008080;">;</span>
			<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span> <span style="color: #0000ff;">void</span> getinfo<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span>  a, <span style="color: #0000ff;">float</span> b,<span style="color: #0000ff;">float</span> c <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
				<span style="color: #0000ff;">void</span> display<span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
				<span style="color: #0000ff;">void</span> equal<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span>  a, <span style="color: #0000ff;">float</span> b<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
				<span style="color: #0000ff;">void</span> imag<span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
				<span style="color: #0000ff;">void</span> real<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span> a,<span style="color: #0000ff;">float</span> b,<span style="color: #0000ff;">float</span> c<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
		<span style="color: #0000ff;">void</span>  equation <span style="color: #008080;">::</span> <span style="color: #007788;">getinfo</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span> aa,<span style="color: #0000ff;">float</span> bb,<span style="color: #0000ff;">float</span> cc<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
	                a<span style="color: #000080;">=</span>aa<span style="color: #008080;">;</span>
			b<span style="color: #000080;">=</span>bb<span style="color: #008080;">;</span>
		        c<span style="color: #000080;">=</span>cc<span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0000ff;">void</span> equation<span style="color: #008080;">::</span><span style="color: #007788;">display</span><span style="color: #008000;">&#40;</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>endl<span style="color: #008080;">;</span>
			<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>”a<span style="color: #000080;">=</span>”<span style="color: #000080;">&lt;&lt;</span>a<span style="color: #000080;">&lt;&lt;</span>’\t’<span style="color: #008080;">;</span>
			<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>”b<span style="color: #000080;">=</span>”<span style="color: #000080;">&lt;&lt;</span>b<span style="color: #000080;">&lt;&lt;</span>’\t’<span style="color: #008080;">;</span>
			<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>”c<span style="color: #000080;">=</span>”<span style="color: #000080;">&lt;&lt;</span>c<span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>		
&nbsp;
<span style="color: #0000ff;">void</span> equation <span style="color: #008080;">::</span><span style="color: #007788;">equal</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span> a,<span style="color: #0000ff;">float</span> b<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">float</span> x<span style="color: #008080;">;</span>
			x <span style="color: #000080;">=</span> <span style="color: #000040;">-</span>b<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>
			<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>”Roots are equal “<span style="color: #000080;">&lt;&lt;</span>x<span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0000ff;">void</span> equation <span style="color: #008080;">::</span> <span style="color: #007788;">imag</span><span style="color: #008000;">&#40;</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>”Roots are imaginary”<span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0000ff;">void</span> equation <span style="color: #008080;">::</span> <span style="color: #007788;">real</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">float</span> a,<span style="color: #0000ff;">float</span> b,<span style="color: #0000ff;">float</span> det<span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">float</span> x1,x2,temp<span style="color: #008080;">;</span>
			temp <span style="color: #000080;">=</span> <span style="color: #0000dd;">sqrt</span><span style="color: #008000;">&#40;</span>det<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			x1<span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">-</span>b <span style="color: #000040;">+</span> temp<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 –temp<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>
			<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>”Roots are real”<span style="color: #008080;">;</span>
			<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>”x1<span style="color: #000080;">=</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>”x2 <span style="color: #000080;">=</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;">void</span> main<span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">&#123;</span>
			<span style="color: #0000ff;">class</span> equation e<span style="color: #008080;">;</span>
			<span style="color: #0000ff;">float</span> aa,bb,cc<span style="color: #008080;">;</span>
			clrscr<span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>”Enter the three numbers”<span style="color: #008080;">;</span>
			<span style="color: #0000dd;">cin</span><span style="color: #000080;">&gt;&gt;</span>aa<span style="color: #000080;">&gt;&gt;</span>bb<span style="color: #000080;">&gt;&gt;</span>cc<span style="color: #008080;">;</span>
			e.<span style="color: #007788;">getinfo</span><span style="color: #008000;">&#40;</span>aa,bb,cc<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			e.<span style="color: #007788;">display</span><span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>aa <span style="color: #000080;">=</span> <span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				<span style="color: #0000ff;">float</span> temp<span style="color: #008080;">;</span>
				temp <span style="color: #000080;">=</span> cc<span style="color: #000040;">/</span>bb<span style="color: #008080;">;</span>
				<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>” Linear Roots”<span style="color: #000080;">&lt;&lt;</span>temp<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: #0000ff;">float</span> det<span style="color: #008080;">;</span>
				det <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>bb<span style="color: #000040;">*</span>bb – <span style="color: #0000dd;">4</span><span style="color: #000040;">*</span>aa<span style="color: #000040;">*</span>cc<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
				<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>det <span style="color: #000080;">=</span> <span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
				e.<span style="color: #007788;">equal</span><span style="color: #008000;">&#40;</span>aa,bb<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
				<span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>det<span style="color: #000080;">&lt;</span><span style="color: #0000dd;">0</span> <span style="color: #008000;">&#41;</span>
				          e.<span style="color: #007788;">imag</span><span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
				<span style="color: #0000ff;">else</span> 
				          e.<span style="color: #007788;">real</span><span style="color: #008000;">&#40;</span>aa,bb,cc <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
			<span style="color: #008000;">&#125;</span>
			getch<span style="color: #008000;">&#40;</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span></pre></div></div>

<p><strong>OUTPUT:</strong><br />
	Enter the three numbers 2 4 1<br />
	Roots are imaginary<br />
	X1= &#8211; 0.292893<br />
	X2= &#8211; 1.707107</p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/source-codes/software-programs/cpp-programs/cpp-advanced-programs/c-program-for-implementation-of-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lexical Analyzer</title>
		<link>http://electrofriends.com/projects/computer-programming/lexical-analyzer/</link>
		<comments>http://electrofriends.com/projects/computer-programming/lexical-analyzer/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 07:37:32 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[Computer Programming]]></category>
		<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[C codes]]></category>
		<category><![CDATA[characters to tokens]]></category>
		<category><![CDATA[Lexical Analyzer]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=223</guid>
		<description><![CDATA[Lexical analyzer converts stream of input characters into a stream of tokens. The different tokens that our lexical analyzer identifies are as follows: KEYWORDS: int, char, float, double, if, for, while, else, switch, struct, printf, scanf, case, break, return, typedef, void IDENTIFIERS: main, fopen, getch etc NUMBERS: positive and negative integers, positive and negative floating [...]]]></description>
			<content:encoded><![CDATA[<p>Lexical analyzer converts stream of input characters into a stream of tokens. The different tokens that our lexical analyzer identifies are as follows:</p>
<p>KEYWORDS: int, char, float, double, if, for, while, else, switch, struct, printf, scanf, case, break, return, typedef, void</p>
<p>IDENTIFIERS: main, fopen, getch etc</p>
<p>NUMBERS: positive and negative integers, positive and negative floating point numbers.</p>
<p>OPERATORS: +, ++, -, &#8211;, ||, *, ?, /, &gt;, &gt;=, &lt;, &lt;=, =, ==, &amp;, &amp;&amp;.</p>
<p>BRACKETS: [ ], { }, ( ).</p>
<p>STRINGS : Set of characters enclosed within the quotes</p>
<p>COMMENT LINES: Ignores single  line, multi line comments</p>
<p>For tokenizing into identifiers and keywords we incorporate a symbol table which initially consists of predefined keywords. The tokens are read from an input file. If the encountered token is an identifier or a keyword the lexical analyzer will look up in the symbol table to check  the existence  of the respective token. If an entry does exist then we proceed to the next  token. If not then that particular  token along with the token value is written into the symbol table. The rest of the tokens are directly displayed by writing into an output file.</p>
<p>The output file will consist of all the tokens present in our input file along with their respective token values.</p>
<p><strong>INTRODUCTION:</strong></p>
<p>Lexical analysis involves scanning the program to be compiled and recognizing the tokens that make up the source statements Scanners or lexical analyzers are usually designed to recognize keywords , operators , and identifiers , as well as integers, floating point numbers , character strings , and other  similar items that are written as part of the source program . The exact set of  tokens to be recognized of course, depends upon the programming language being used to describe it.</p>
<p>A sequence of input characters that comprises a single token is called a lexeme. A lexical analyzer can insulate a parser from the lexeme representation of tokens. Following are the list of functions that lexical analyzers perform.</p>
<p><strong>Removal of white space and  comment :</strong></p>
<p>Many languages allow “white space” to appear between tokens. Comments can likewise be ignored by the parser and translator , so they may also be treated as white space. If white space is eliminated by the lexical analyzer, the parser will never have to consider it.</p>
<p><strong>Constants :</strong></p>
<p>An integer constant is a sequence of digits, integer constants can be allowed by adding productions to the grammar for expressions, or by creating a token for such constants . The job of collecting digits into integers is generally given to a lexical analyzer because numbers can be treated as single units during translation. The lexical analyzer passes both the token and attribute to the parser.<br />
<strong><br />
Recognizing identifiers and keywords :</strong></p>
<p>Languages use identifiers as names of variables, arrays and functions. A grammar for a language often treats an identifier as a token. Many languages use fixed character strings such as begin, end , if, and so on, as punctuation marks or to identify certain constructs. These character strings, called keywords, generally satisfy the rules for forming identifiers.</p>
<p><strong>SYSTEM ANALYSIS:</strong></p>
<p>The operating  system used is MS-DOS.</p>
<p><strong>MS-DOS : </strong>The MS-DOS is a single user, single process, single processor operating system. Due to the confinement of the device dependent code into one layer, the porting of MS-DOS has theoretically been reduced to writing  of the BIOS code for the new hardware. At the command level it provides a hierarchical file system, input output redirection, pipes and filters. User written commands can be invoked in the same way as the standard system commands, giving the appearance as if the basic system functionality has been extended.</p>
<p>Being a single user system, it provides only file protection and access control. The disk space is allocated in terms of a cluster of consecutive sectors. The command language of MS-DOS has been designed to allow the user to interact directly with the operating system using a CRT terminal. The principal use of the command language is to initiate the execution of commands and programs. A user program can be executed under MS-DOS by simply typing the name of the executable file of the user program at the DOS command prompt.</p>
<p>The programming language used here is C programming</p>
<p><strong>SYSTEM DESIGN:</strong></p>
<p><strong>Process:</strong></p>
<p>The lexical analyzer is the first phase of  a compiler. Its main task is to read the input characters and produce as output a sequence of tokens that the parser uses for syntax analysis. This interaction, summarized schematically in fig. a.</p>
<div id="attachment_224" class="wp-caption aligncenter" style="width: 496px"><img class="size-full wp-image-224" title="fig a. Process of lexical analyzer " src="http://electrofriends.com/wp-content/uploads/2008/11/block_1.gif" alt="fig a. Process of lexical analyzer " width="486" height="179" /><p class="wp-caption-text">fig a. Process of lexical analyzer </p></div>
<p>Upon receiving a “get next token “command from the parser, the lexical analyzer reads the input characters until it can identify next token.</p>
<p>Sometimes , lexical analyzers are divided into a cascade of two phases, the first called “scanning”, and the second “lexical analysis”.</p>
<p>The scanner is responsible for doing simple tasks, while the lexical analyzer proper does the more complex operations.</p>
<p>The lexical analyzer which we have designed takes the input  from a input file. It reads one character at a time from the input file, and continues to read until end of the file is reached. It recognizes the valid identifiers, keywords and specifies the token values of the keywords.</p>
<p>It also identifies the header files, #define statements, numbers, special characters, various relational and logical operators, ignores the white spaces and comments. It prints the output in a separate file specifying the line number .</p>
<p><strong>BLOCK DIAGRAM:</strong></p>
<div id="attachment_225" class="wp-caption aligncenter" style="width: 460px"><img class="size-full wp-image-225" title="fig b. Block diagram of the project" src="http://electrofriends.com/wp-content/uploads/2008/11/block_2.gif" alt="fig b. Block diagram of the project" width="450" height="198" /><p class="wp-caption-text">fig b. Block diagram of the project</p></div>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/projects/computer-programming/lexical-analyzer/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

