Title:
Home
|
edited by
Youngrok Pak
at
6 years, 7 months ago.
<h1>
Project Rosalynde for KAIST student</h1>
<p>
</p>
<p class="p1">
</p>
<p class="p1">
#include <span class="s1"><stdio.h></span></p>
<p class="p2">
<span class="s2">#include </span><stdlib.h></p>
<p class="p2">
<span class="s2">#include </span><iostream></p>
<p class="p3">
</p>
<p class="p4">
<span class="s2">#define EXP_BOUND </span><span class="s3">10</span><span class="s2"> </span>// ¡ˆºˆ¥¬ 0~EXP_BOUND</p>
<p class="p4">
<span class="s2">#define COEF_BOUND </span><span class="s3">20</span><span class="s2"> </span>// ∞˺ˆ¥¬ -COEF_BOUND/2 ~ +COEF_BOUND/2</p>
<p class="p4">
<span class="s2">#define TERMS_NUM </span><span class="s3">40</span><span class="s2"> </span>// terms Array index ∞πºˆ¥¬ TERMS_NUM∞≥</p>
<p class="p4">
<span class="s2">#define SUB_TERMS_NUM </span><span class="s3">10</span><span class="s2"> </span>// Polynomial B¿« ª©±‚ ≈◊Ω∫∆Æø°º≠¿« ∞πºˆ</p>
<p class="p4">
<span class="s2">#define ADD_TERMS_NUM </span><span class="s3">10</span><span class="s2"> </span>// Polynomial B¿« ¥ı«œ±‚ ≈◊Ω∫∆Æø°º≠¿« ∞πºˆ</p>
<p class="p1">
#define INTEG_CONST <span class="s3">20</span> <span class="s4">// ¿˚∫– ªÛºˆ</span></p>
<p class="p3">
</p>
<p class="p5">
using<span class="s5"> </span>namespace<span class="s5"> </span><span class="s6">std</span><span class="s5">;</span></p>
<p class="p6">
<span class="s7">class</span> Term</p>
<p class="p6">
{</p>
<p class="p5">
private<span class="s5">:</span></p>
<p class="p6">
<span class="s7">double</span> coef; <span class="s4">// ∞˺ˆ</span></p>
<p class="p6">
<span class="s7">int</span> exp; <span class="s4">// ¬˜ºˆ</span></p>
<p class="p4">
// you can add your own private member here</p>
<p class="p3">
</p>
<p class="p5">
public<span class="s5">:</span></p>
<p class="p4">
// constructor</p>
<p class="p4">
<span class="s5">Term(); </span>// default constructor. ∞˺ˆøÕ ¬˜ºˆ ∏<span class="s8"></span>µŒ 0¿∏∑Œ √ ±‚»≠</p>
<p class="p4">
<span class="s5">Term(</span><span class="s7">double</span><span class="s5"> c, </span><span class="s7">int</span><span class="s5"> e); </span>// ∞˺ˆ∏¶ c∑Œ, ¬˜ºˆ∏¶ e∑Œ √ ±‚»≠</p>
<p class="p4">
// setter, getter</p>
<p class="p4">
<span class="s7">double</span><span class="s5"> GetCoef(); </span>// coef ∞™¿ª ∏Æ≈œ</p>
<p class="p4">
<span class="s7">int</span><span class="s5"> GetExp(); </span>// exp ∞™¿ª ∏Æ≈œ</p>
<p class="p4">
<span class="s7">void</span><span class="s5"> SetCoef(</span><span class="s7">double</span><span class="s5"> c); </span>// coef∞™¿ª c∑Œ º≥¡§</p>
<p class="p4">
<span class="s7">void</span><span class="s5"> SetExp(</span><span class="s7">int</span><span class="s5"> e); </span>// exp∞™¿ª e∑Œ º≥¡§</p>
<p class="p4">
//print term. (coef)x^(exp) e.g 3x^2</p>
<p class="p6">
<span class="s7">void</span> Print();</p>
<p class="p6">
};</p>
<p class="p3">
</p>
<p class="p7">
Term<span class="s5">::</span>Term<span class="s5">()</span></p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">coef</span> = <span class="s3">0</span>;</p>
<p class="p6">
<span class="s9">exp</span> = <span class="s3">0</span>;</p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p6">
<span class="s9">Term</span>::<span class="s9">Term</span>(<span class="s7">double</span> c, <span class="s7">int</span> e)</p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">coef</span> = c;</p>
<p class="p6">
<span class="s9">exp</span> = e;</p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p6">
<span class="s7">double</span> <span class="s9">Term</span>::GetCoef()</p>
<p class="p6">
{</p>
<p class="p5">
return<span class="s5"> </span><span class="s9">coef</span><span class="s5">;</span></p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p6">
<span class="s7">int</span> <span class="s9">Term</span>::GetExp()</p>
<p class="p6">
{</p>
<p class="p5">
return<span class="s5"> </span><span class="s9">exp</span><span class="s5">;</span></p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p6">
<span class="s7">void</span> <span class="s9">Term</span>::SetCoef(<span class="s7">double</span> c)</p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">coef</span> = c;</p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p6">
<span class="s7">void</span> <span class="s9">Term</span>::SetExp(<span class="s7">int</span> e)</p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">exp</span> = e;</p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p6">
<span class="s7">void</span> <span class="s9">Term</span>::Print()</p>
<p class="p6">
{</p>
<p class="p6">
<span class="s7">if</span>(<span class="s9">coef</span> == <span class="s3">0</span>)</p>
<p class="p5">
return<span class="s5">;</span></p>
<p class="p6">
<span class="s7">else</span> <span class="s7">if</span>(<span class="s9">exp</span> == <span class="s3">0</span>)</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s9">coef</span>;</p>
<p class="p6">
<span class="s7">else</span> <span class="s7">if</span>(<span class="s9">exp</span> == <span class="s3">1</span>)</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s9">coef</span><<<span class="s1">"x"</span>;</p>
<p class="p5">
else</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s9">coef</span><<<span class="s1">"x^"</span><<<span class="s9">exp</span>;</p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p4">
// Node class. linked list¿« node</p>
<p class="p4">
// Term ∞¥√º «œ≥™øÕ linked list∏¶ ¿ß«— ∆˜¿Œ≈Õ next, prev ∏¶ ∞°¡¯¥Ÿ.</p>
<p class="p6">
<span class="s7">class</span> Node</p>
<p class="p6">
{</p>
<p class="p4">
// Node class º≥∞Ë«—¥Ÿ. </p>
<p class="p4">
// ∞£∆Ì«— ±∏«ˆ¿ª ¿ß«ÿ member ∏<span class="s8"></span>µŒ public øµø™ø° ¡§¿««ÿµµ ªÛ∞¸æ¯¿Ω.</p>
<p class="p5">
public<span class="s5">:</span></p>
<p class="p6">
<span class="s9">Term</span> t;</p>
<p class="p6">
<span class="s9">Node</span>* prev;</p>
<p class="p6">
<span class="s9">Node</span>* next;</p>
<p class="p6">
};</p>
<p class="p3">
</p>
<p class="p3">
</p>
<p class="p3">
</p>
<p class="p6">
<span class="s7">class</span> Polynomial</p>
<p class="p6">
{</p>
<p class="p5">
private<span class="s5">:</span></p>
<p class="p4">
<span class="s9">Node</span><span class="s5">* head; </span>// dummy Node head</p>
<p class="p4">
<span class="s9">Node</span><span class="s5">* tail; </span>// dummy Node tail </p>
<p class="p4">
<span class="s5"> </span>// you can add your own private member here.</p>
<p class="p3">
</p>
<p class="p5">
public<span class="s5">:</span></p>
<p class="p4">
<span class="s5">Polynomial(); </span>// default constructor. head, tail node∏∏ ∞°¡¯ Polynomial ª˝º∫</p>
<p class="p4">
// copy constructor. Polynomial pøÕ µø¿œ«— «◊µÈ¿ª ∞°¡¯ Polynomial ª˝º∫</p>
<p class="p6">
Polynomial(<span class="s9">Polynomial</span>& p); </p>
<p class="p6">
~Polynomial();<span class="Apple-tab-span"> </span><span class="s4">// destructor</span></p>
<p class="p4">
<span class="s7">void</span><span class="s5"> Add(</span><span class="s9">Term</span><span class="s5"> t); </span>// Polynomialø° Term t∏¶ ¥ı«‘</p>
<p class="p4">
<span class="s7">void</span><span class="s5"> Sub(</span><span class="s9">Term</span><span class="s5"> t); </span>// Polynomialø° Term t∏¶ ª≠</p>
<p class="p4">
// Polynomial¿« size(«◊¿«∞≥ºˆ) ∏Æ≈œ.</p>
<p class="p4">
// ∞˺ˆ∞° 0¿Œ «◊(ªÛºˆ«◊0µµ∆˜«‘)µÈ¿∫ «◊¿«∞≥ºˆø° ∆˜«‘滵 .</p>
<p class="p6">
<span class="s7">int</span> Size(); </p>
<p class="p4">
// Polynomial¿ª default ªÛ≈¬∑Œ √ ±‚»≠.</p>
<p class="p4">
// ¡Ô Polynomial¥¬ head, tail node∏∏ ∞°¡¯¥Ÿ</p>
<p class="p6">
<span class="s7">void</span> Reset();</p>
<p class="p4">
// "this"øÕ "p" µ°º¿∞·∞˙∏¶ ¿˙¿Â«— Polynomial return</p>
<p class="p7">
Polynomial<span class="s5"> Add(</span>Polynomial<span class="s5"> p);</span></p>
<p class="p4">
// "this"øÕ "p" ª¨º¿ ∞·∞˙∏¶ ¿˙¿Â«— Polynomial return</p>
<p class="p7">
Polynomial<span class="s5"> Sub(</span>Polynomial<span class="s5"> p);</span></p>
<p class="p4">
// "this"øÕ "p" ∞ˆº¿ ∞·∞˙∏¶ ¿˙¿Â«— Polynomial return</p>
<p class="p7">
Polynomial<span class="s5"> Mul(</span>Polynomial<span class="s5"> p);</span></p>
<p class="p4">
// "this"¿« πÃ∫– ∞·∞˙∏¶ ¿˙¿Â«— Polynomial return</p>
<p class="p7">
Polynomial<span class="s5"> Diff();</span></p>
<p class="p4">
// "this"¿« ¿˚∫– ∞·∞˙∏¶ ¿˙¿Â«— Polynomial return</p>
<p class="p6">
<span class="s9">Polynomial</span> Integ(<span class="s7">double</span> integ_const);</p>
<p class="p4">
// Polynomial¿ª xø° ∞¸«— ≥ª∏≤¬˜º¯¿∏∑Œ√‚∑¬</p>
<p class="p6">
<span class="s7">void</span> Print();</p>
<p class="p6">
};</p>
<p class="p3">
</p>
<p class="p7">
Polynomial<span class="s5">::</span>Polynomial<span class="s5">()</span></p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">head</span> = <span class="s7">new</span> <span class="s9">Node</span>();</p>
<p class="p6">
<span class="s9">tail</span> = <span class="s7">new</span> <span class="s9">Node</span>();</p>
<p class="p3">
</p>
<p class="p7">
head<span class="s5">-></span>next<span class="s5"> = </span>tail<span class="s5">;</span></p>
<p class="p7">
head<span class="s5">-></span>prev<span class="s5"> = </span><span class="s7">NULL</span><span class="s5">;</span></p>
<p class="p7">
tail<span class="s5">-></span>prev<span class="s5"> = </span>head<span class="s5">;</span></p>
<p class="p7">
tail<span class="s5">-></span>next<span class="s5"> = </span><span class="s7">NULL</span><span class="s5">;</span></p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p7">
Polynomial<span class="s5">::</span>Polynomial<span class="s5">(</span>Polynomial<span class="s5"> &p)</span></p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">head</span> = <span class="s7">new</span> <span class="s9">Node</span>();</p>
<p class="p6">
<span class="s9">tail</span> = <span class="s7">new</span> <span class="s9">Node</span>();</p>
<p class="p3">
</p>
<p class="p7">
head<span class="s5">-></span>next<span class="s5"> = </span>tail<span class="s5">;</span></p>
<p class="p7">
head<span class="s5">-></span>prev<span class="s5"> = </span><span class="s7">NULL</span><span class="s5">;</span></p>
<p class="p7">
tail<span class="s5">-></span>prev<span class="s5"> = </span>head<span class="s5">;</span></p>
<p class="p7">
tail<span class="s5">-></span>next<span class="s5"> = </span><span class="s7">NULL</span><span class="s5">;</span></p>
<p class="p3">
</p>
<p class="p6">
<span class="s9">Node</span>* cursor = p.<span class="s9">head</span>-><span class="s9">next</span>;</p>
<p class="p3">
</p>
<p class="p6">
<span class="s7">while</span>(cursor != p.<span class="s9">tail</span>)</p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">Add</span>(cursor-><span class="s9">t</span>);</p>
<p class="p6">
cursor = cursor-><span class="s9">next</span>;</p>
<p class="p6">
}</p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p6">
<span class="s9">Polynomial</span>::~Polynomial()</p>
<p class="p6">
{</p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p7">
<span class="s7">void</span><span class="s5"> </span>Polynomial<span class="s5">::Add(</span>Term<span class="s5"> t)</span></p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">Node</span>* cursor=<span class="s9">head</span>-><span class="s9">next</span>;</p>
<p class="p6">
<span class="s7">while</span>(cursor!=<span class="s9">tail</span>)</p>
<p class="p6">
{</p>
<p class="p6">
<span class="s7">if</span>(cursor-><span class="s9">t</span>.<span class="s9">GetExp</span>()==t.<span class="s9">GetExp</span>())</p>
<p class="p6">
{</p>
<p class="p6">
cursor-><span class="s9">t</span>.<span class="s9">SetCoef</span>(cursor-><span class="s9">t</span>.<span class="s9">GetCoef</span>()+t.<span class="s9">GetCoef</span>());</p>
<p class="p6">
<span class="s7">if</span>(cursor-><span class="s9">t</span>.<span class="s9">GetCoef</span>()==<span class="s3">0</span>)</p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">Node</span>* del=cursor;</p>
<p class="p6">
cursor-><span class="s9">prev</span>-><span class="s9">next</span>=cursor-><span class="s9">next</span>;</p>
<p class="p6">
cursor-><span class="s9">next</span>-><span class="s9">prev</span>=cursor-><span class="s9">prev</span>;</p>
<p class="p6">
<span class="s7">delete</span> del;</p>
<p class="p6">
}</p>
<p class="p6">
<span class="s7">return</span>;</p>
<p class="p6">
}</p>
<p class="p6">
<span class="s7">if</span>(cursor-><span class="s9">t</span>.<span class="s9">GetExp</span>() < t.<span class="s9">GetExp</span>()) <span class="s7">break</span>;</p>
<p class="p6">
cursor=cursor-><span class="s9">next</span>;</p>
<p class="p6">
}</p>
<p class="p6">
<span class="s9">Node</span>* tmp=<span class="s7">new</span> <span class="s9">Node</span>();</p>
<p class="p6">
tmp-><span class="s9">t</span>=t;</p>
<p class="p6">
tmp-><span class="s9">prev</span>=cursor-><span class="s9">prev</span>;</p>
<p class="p6">
tmp-><span class="s9">next</span>=cursor;</p>
<p class="p6">
cursor-><span class="s9">prev</span>-><span class="s9">next</span>=tmp;</p>
<p class="p6">
cursor-><span class="s9">prev</span>=tmp;</p>
<p class="p5">
<span class="s5"> </span>return<span class="s5">;</span></p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p7">
<span class="s7">void</span><span class="s5"> </span>Polynomial<span class="s5">::Sub(</span>Term<span class="s5"> t)</span></p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">Node</span>* cursor=<span class="s9">head</span>-><span class="s9">next</span>;</p>
<p class="p6">
<span class="s7">while</span>(cursor!=<span class="s9">tail</span>)</p>
<p class="p6">
{</p>
<p class="p6">
<span class="s7">if</span>(cursor-><span class="s9">t</span>.<span class="s9">GetExp</span>()==t.<span class="s9">GetExp</span>())</p>
<p class="p6">
{</p>
<p class="p6">
cursor-><span class="s9">t</span>.<span class="s9">SetCoef</span>(cursor-><span class="s9">t</span>.<span class="s9">GetCoef</span>()-t.<span class="s9">GetCoef</span>());</p>
<p class="p6">
<span class="s7">if</span>(cursor-><span class="s9">t</span>.<span class="s9">GetCoef</span>()==<span class="s3">0</span>)</p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">Node</span>* del=cursor;</p>
<p class="p6">
cursor-><span class="s9">prev</span>-><span class="s9">next</span>=cursor-><span class="s9">next</span>;</p>
<p class="p6">
cursor-><span class="s9">next</span>-><span class="s9">prev</span>=cursor-><span class="s9">prev</span>;</p>
<p class="p6">
<span class="s7">delete</span> del;</p>
<p class="p6">
}</p>
<p class="p6">
<span class="s7">return</span>;</p>
<p class="p6">
}</p>
<p class="p6">
<span class="s7">if</span>(cursor-><span class="s9">t</span>.<span class="s9">GetExp</span>() < t.<span class="s9">GetExp</span>()) <span class="s7">break</span>;</p>
<p class="p6">
cursor=cursor-><span class="s9">next</span>;</p>
<p class="p6">
}</p>
<p class="p6">
<span class="s9">Node</span>* tmp=<span class="s7">new</span> <span class="s9">Node</span>();</p>
<p class="p6">
<span class="s9">Term</span>* newt=<span class="s7">new</span> <span class="s9">Term</span>(t.<span class="s9">GetCoef</span>()*(-<span class="s3">1</span>),t.<span class="s9">GetExp</span>());</p>
<p class="p6">
tmp-><span class="s9">t</span>=*newt;</p>
<p class="p6">
tmp-><span class="s9">prev</span>=cursor-><span class="s9">prev</span>;</p>
<p class="p6">
tmp-><span class="s9">next</span>=cursor;</p>
<p class="p6">
cursor-><span class="s9">prev</span>-><span class="s9">next</span>=tmp;</p>
<p class="p6">
cursor-><span class="s9">prev</span>=tmp;</p>
<p class="p5">
<span class="s5"> </span>return<span class="s5">;</span></p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p7">
<span class="s7">int</span><span class="s5"> </span>Polynomial<span class="s5">::Size()</span></p>
<p class="p6">
{</p>
<p class="p6">
<span class="s7">int</span> size = <span class="s3">0</span>;</p>
<p class="p6">
<span class="s9">Node</span>* tmp=<span class="s9">head</span>-><span class="s9">next</span>;</p>
<p class="p6">
<span class="s7">while</span>(tmp!=<span class="s9">tail</span>)</p>
<p class="p6">
{</p>
<p class="p6">
size++;</p>
<p class="p6">
tmp=tmp-><span class="s9">next</span>;</p>
<p class="p6">
}</p>
<p class="p6">
<span class="s7">return</span> size;</p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p6">
<span class="s7">void</span> <span class="s9">Polynomial</span>::Reset()</p>
<p class="p6">
{</p>
<p class="p6">
<span class="s7">if</span>(<span class="s9">Size</span>()!=<span class="s3">0</span>)</p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">Node</span>* tmp= <span class="s9">head</span>-><span class="s9">next</span>;</p>
<p class="p6">
<span class="s7">while</span>(tmp!=<span class="s9">tail</span>)</p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">Node</span>* del=tmp;</p>
<p class="p6">
tmp=tmp-><span class="s9">next</span>;</p>
<p class="p6">
<span class="s7">delete</span> del;</p>
<p class="p6">
}</p>
<p class="p6">
}</p>
<p class="p7">
<span class="s5"> </span>head<span class="s5">-></span>next<span class="s5">=</span>tail<span class="s5">;</span></p>
<p class="p7">
<span class="s5"> </span>tail<span class="s5">-></span>next<span class="s5">=</span>head<span class="s5">;</span></p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p7">
Polynomial<span class="s5"> </span>Polynomial<span class="s5">::Add(</span>Polynomial<span class="s5"> p)</span></p>
<p class="p6">
{</p>
<p class="p7">
Polynomial<span class="s5"> result;</span></p>
<p class="p6">
<span class="s9">Node</span>* cursor=p.<span class="s9">head</span>-><span class="s9">next</span>;</p>
<p class="p6">
<span class="s7">while</span>(cursor!=p.<span class="s9">tail</span>)</p>
<p class="p6">
{</p>
<p class="p6">
result.<span class="s9">Add</span>(cursor-><span class="s9">t</span>);</p>
<p class="p6">
cursor=cursor-><span class="s9">next</span>;</p>
<p class="p6">
}</p>
<p class="p6">
cursor=<span class="s9">head</span>-><span class="s9">next</span>;</p>
<p class="p6">
<span class="s7">while</span>(cursor!=<span class="s9">tail</span>)</p>
<p class="p6">
{</p>
<p class="p6">
result.<span class="s9">Add</span>(cursor-><span class="s9">t</span>);</p>
<p class="p6">
cursor=cursor-><span class="s9">next</span>;</p>
<p class="p6">
}</p>
<p class="p6">
<span class="s7">return</span> result;</p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p7">
Polynomial<span class="s5"> </span>Polynomial<span class="s5">::Sub(</span>Polynomial<span class="s5"> p)</span></p>
<p class="p6">
{</p>
<p class="p7">
Polynomial<span class="s5"> result;</span></p>
<p class="p6">
<span class="s9">Node</span>* cursor=p.<span class="s9">head</span>-><span class="s9">next</span>;</p>
<p class="p6">
<span class="s7">while</span>(cursor!=p.<span class="s9">tail</span>)</p>
<p class="p6">
{</p>
<p class="p6">
result.<span class="s9">Sub</span>(cursor-><span class="s9">t</span>);</p>
<p class="p6">
cursor=cursor-><span class="s9">next</span>;</p>
<p class="p6">
}</p>
<p class="p6">
cursor=<span class="s9">head</span>-><span class="s9">next</span>;</p>
<p class="p6">
<span class="s7">while</span>(cursor!=<span class="s9">tail</span>)</p>
<p class="p6">
{</p>
<p class="p6">
result.<span class="s9">Add</span>(cursor-><span class="s9">t</span>);</p>
<p class="p6">
cursor=cursor-><span class="s9">next</span>;</p>
<p class="p6">
}</p>
<p class="p6">
<span class="s7">return</span> result;</p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p7">
Polynomial<span class="s5"> </span>Polynomial<span class="s5">::Mul(</span>Polynomial<span class="s5"> p)</span></p>
<p class="p6">
{</p>
<p class="p7">
Polynomial<span class="s5"> result;</span></p>
<p class="p6">
<span class="s7">return</span> result;</p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p7">
Polynomial<span class="s5"> </span>Polynomial<span class="s5">::Diff()</span></p>
<p class="p6">
{</p>
<p class="p7">
Polynomial<span class="s5"> result;</span></p>
<p class="p6">
<span class="s7">return</span> result;</p>
<p class="p3">
</p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p6">
<span class="s9">Polynomial</span> <span class="s9">Polynomial</span>::Integ(<span class="s7">double</span> integ_const)</p>
<p class="p6">
{</p>
<p class="p7">
Polynomial<span class="s5"> result;</span></p>
<p class="p6">
<span class="s7">return</span> result;</p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p6">
<span class="s7">void</span> <span class="s9">Polynomial</span>::Print()</p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">Node</span>* cursor = <span class="s9">head</span>-><span class="s9">next</span>;</p>
<p class="p3">
</p>
<p class="p6">
<span class="s7">if</span>(<span class="s9">Size</span>() == <span class="s3">0</span>)</p>
<p class="p6">
{</p>
<p class="p8">
cout<span class="s5"><<</span><span class="s1">"0"</span><span class="s5"><<</span>endl<span class="s5">;</span></p>
<p class="p5">
return<span class="s5">;</span></p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p6">
<span class="s7">while</span>(cursor != <span class="s9">tail</span>-><span class="s9">prev</span>)</p>
<p class="p6">
{</p>
<p class="p6">
cursor-><span class="s9">t</span>.<span class="s9">Print</span>();</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">" + "</span>;</p>
<p class="p6">
cursor = cursor-><span class="s9">next</span>;</p>
<p class="p6">
}</p>
<p class="p6">
cursor-><span class="s9">t</span>.<span class="s9">Print</span>();</p>
<p class="p8">
cout<span class="s5"><<</span>endl<span class="s5">;</span></p>
<p class="p3">
</p>
<p class="p6">
}</p>
<p class="p3">
</p>
<p class="p6">
<span class="s7">int</span> main()</p>
<p class="p6">
{</p>
<p class="p6">
<span class="s9">Term</span> terms[<span class="s3">20</span>] = {<span class="s9">Term</span>(-<span class="s3">5</span>, <span class="s3">2</span>), <span class="s9">Term</span>(-<span class="s3">3</span>, <span class="s3">1</span>), <span class="s9">Term</span>(<span class="s3">2</span>, <span class="s3">5</span>), <span class="s9">Term</span>(<span class="s3">0</span>, <span class="s3">3</span>), <span class="s9">Term</span>(<span class="s3">3</span>, <span class="s3">0</span>), <span class="s9">Term</span>(-<span class="s3">74</span>, <span class="s3">4</span>), <span class="s9">Term</span>(<span class="s3">17</span>, <span class="s3">3</span>), <span class="s9">Term</span>(<span class="s3">31</span>, <span class="s3">2</span>), <span class="s9">Term</span>(-<span class="s3">184</span>, <span class="s3">3</span>), <span class="s9">Term</span>(<span class="s3">9</span>, <span class="s3">1</span>), <span class="s9">Term</span>(<span class="s3">15</span>, <span class="s3">1</span>), <span class="s9">Term</span>(-<span class="s3">11</span>, <span class="s3">2</span>), <span class="s9">Term</span>(<span class="s3">21</span>, <span class="s3">5</span>), <span class="s9">Term</span>(<span class="s3">51</span>, <span class="s3">3</span>), <span class="s9">Term</span>(<span class="s3">19</span>, <span class="s3">4</span>), <span class="s9">Term</span>(<span class="s3">15</span>, <span class="s3">1</span>), <span class="s9">Term</span>(), <span class="s9">Term</span>(-<span class="s3">31</span>, <span class="s3">2</span>), <span class="s9">Term</span>(-<span class="s3">19</span>, <span class="s3">0</span>), <span class="s9">Term</span>(<span class="s3">0</span>, <span class="s3">4</span>)};</p>
<p class="p3">
</p>
<p class="p7">
Polynomial<span class="s5"> A;</span></p>
<p class="p3">
</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"A: "</span>; A.<span class="s9">Print</span>(); <span class="s4">// A= 0</span></p>
<p class="p4">
<span class="s6">cout</span><span class="s5"><<</span><span class="s1">"Size of A : "</span><span class="s5"><<A.</span><span class="s9">Size</span><span class="s5">()<<</span><span class="s6">endl</span><span class="s5">; </span>// Size of A : 0</p>
<p class="p6">
<span class="s7">for</span>(<span class="s7">int</span> i=<span class="s3">0</span>; i<<span class="s3">20</span>; i++){A.<span class="s9">Add</span>(terms[i]);}</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"A: "</span>; A.<span class="s9">Print</span>(); <span class="s4">// A= </span></p>
<p class="p4">
<span class="s6">cout</span><span class="s5"><<</span><span class="s1">"Size of A : "</span><span class="s5"><<A.</span><span class="s9">Size</span><span class="s5">()<<</span><span class="s6">endl</span><span class="s5">; </span>// Size of A : </p>
<p class="p7">
Polynomial<span class="s5"> _A(A); </span></p>
<p class="p6">
<span class="s7">for</span>(<span class="s7">int</span> i=<span class="s3">0</span>; i<<span class="s3">20</span>; i++){_A.<span class="s9">Sub</span>(terms[i]);}</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"_A: "</span>; _A.<span class="s9">Print</span>(); <span class="s4">// _A= 0</span></p>
<p class="p4">
<span class="s6">cout</span><span class="s5"><<</span><span class="s1">"Size of _A: "</span><span class="s5"><<_A.</span><span class="s9">Size</span><span class="s5">()<<</span><span class="s6">endl</span><span class="s5">;</span>// Size of A : 0</p>
<p class="p3">
</p>
<p class="p6">
<span class="s9">Polynomial</span> A_(A); A_.<span class="s9">Reset</span>();</p>
<p class="p6">
<span class="s9">Polynomial</span> B(A); B.<span class="s9">Sub</span>(terms[<span class="s3">3</span>]); B.<span class="s9">Sub</span>(terms[<span class="s3">5</span>]); B.<span class="s9">Sub</span>(terms[<span class="s3">7</span>]); B.<span class="s9">Sub</span>(terms[<span class="s3">9</span>]); B.<span class="s9">Sub</span>(terms[<span class="s3">11</span>]);</p>
<p class="p6">
<span class="s9">Polynomial</span> C(A); C.<span class="s9">Add</span>(terms[<span class="s3">12</span>]); C.<span class="s9">Add</span>(terms[<span class="s3">14</span>]); C.<span class="s9">Add</span>(terms[<span class="s3">16</span>]); C.<span class="s9">Add</span>(terms[<span class="s3">18</span>]); C.<span class="s9">Add</span>(terms[<span class="s3">19</span>]);</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"A: "</span>; A.<span class="s9">Print</span>(); <span class="s4">// A= </span></p>
<p class="p4">
<span class="s6">cout</span><span class="s5"><<</span><span class="s1">"Size of A: "</span><span class="s5"><<A.</span><span class="s9">Size</span><span class="s5">()<<</span><span class="s6">endl</span><span class="s5">; </span>// Size of A :</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"A_: "</span>; A_.<span class="s9">Print</span>(); <span class="s4">// A_=</span></p>
<p class="p4">
<span class="s6">cout</span><span class="s5"><<</span><span class="s1">"Size of A_: "</span><span class="s5"><<A_.</span><span class="s9">Size</span><span class="s5">()<<</span><span class="s6">endl</span><span class="s5">; </span>// Size of A_ :</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"B: "</span>; B.<span class="s9">Print</span>(); <span class="s4">// B= </span></p>
<p class="p4">
<span class="s6">cout</span><span class="s5"><<</span><span class="s1">"Size of B: "</span><span class="s5"><<B.</span><span class="s9">Size</span><span class="s5">()<<</span><span class="s6">endl</span><span class="s5">; </span>// Size of B :</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"C: "</span>; C.<span class="s9">Print</span>(); <span class="s4">// C= </span></p>
<p class="p4">
<span class="s6">cout</span><span class="s5"><<</span><span class="s1">"Size of C: "</span><span class="s5"><<C.</span><span class="s9">Size</span><span class="s5">()<<</span><span class="s6">endl</span><span class="s5">; </span>// Size of C :</p>
<p class="p7">
Polynomial<span class="s5"> AB;</span></p>
<p class="p6">
AB = A.<span class="s9">Add</span>(B);</p>
<p class="p7">
Polynomial<span class="s5"> AA_;</span></p>
<p class="p6">
AA_= A.<span class="s9">Add</span>(A_);</p>
<p class="p7">
Polynomial<span class="s5"> A_C;</span></p>
<p class="p6">
A_C= A.<span class="s9">Sub</span>(C);</p>
<p class="p7">
Polynomial<span class="s5"> A_A_;</span></p>
<p class="p6">
A_A_= A.<span class="s9">Sub</span>(A_);</p>
<p class="p7">
Polynomial<span class="s5"> AxB;</span></p>
<p class="p6">
AxB= A.<span class="s9">Mul</span>(B);</p>
<p class="p7">
Polynomial<span class="s5"> AxC;</span></p>
<p class="p6">
AxC= A.<span class="s9">Mul</span>(C);</p>
<p class="p7">
Polynomial<span class="s5"> AxA_;</span></p>
<p class="p6">
AxA_= A.<span class="s9">Mul</span>(A_);</p>
<p class="p7">
Polynomial<span class="s5"> BxC;</span></p>
<p class="p6">
BxC= B.<span class="s9">Mul</span>(C);</p>
<p class="p7">
Polynomial<span class="s5"> Diff_A;</span></p>
<p class="p6">
Diff_A= A.<span class="s9">Diff</span>();</p>
<p class="p6">
<span class="s9">Polynomial</span> Diff_A_;</p>
<p class="p6">
Diff_A_= A_.<span class="s9">Diff</span>();</p>
<p class="p3">
</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"A+B: "</span>; AB.<span class="s9">Print</span>();</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"A+A_: "</span>; AA_.<span class="s9">Print</span>();</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"A-C: "</span>; A_C.<span class="s9">Print</span>();</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"A-A_: "</span>; A_A_.<span class="s9">Print</span>();</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"AxB: "</span>; AxB.<span class="s9">Print</span>();</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"AxC: "</span>; AxC.<span class="s9">Print</span>();</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"AxA_: "</span>; AxA_.<span class="s9">Print</span>();</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"BxC: "</span>; BxC.<span class="s9">Print</span>();</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"Diff_A: "</span>; Diff_A.<span class="s9">Print</span>();</p>
<p class="p6">
<span class="s6">cout</span><<<span class="s1">"Diff_A_: "</span>; Diff_A_.<span class="s9">Print</span>();</p>
<p class="p3">
</p>
<p class="p6">
<span class="s7">return</span> <span class="s3">0</span>;</p>
<p class="p6">
}</p>