📄 poly.cpp
字号:
#include "linkStack.h"
#include "Polynomial.h"
void main( )
/* Post: The program has executed simple polynomial
arithmetic commands entered by the user.
Uses: The classes Stack and Polynomial and the functions
introduction , instructions,do command , and get
command. */
{ typedef Polynomial Node_entry;
Stack stored_polynomials;
introduction( );
instructions( );
while(do_command(get_command( ), stored_polynomials));
}
bool do_command(char command, Stack &stored_polynomials)
/* Pre: The rst parameter species a valid calculator command.
Post: The command specied by the rst parameter has been
applied to the Stack of Polynomial objects given by
the second parameter. A result of true is returned
unless command == ‘q’ .
Uses: The classes Stack and Polynomial . */
{ Polynomial p, q, r;
switch (command)
{ case '?':
p.read( );
if(stored_polynomials.push(p) == overflow)
cout<<"Warning: Stack full, lost polynomial" << endl;
break;
case '=':
if(stored_polynomials.empty( )) cout << "Stack empty" << endl;
else { stored_polynomials.top(p); p.print( ); }
break;
case ‘+':
if(stored_polynomials.empty( )) cout<< "Stack empty" << endl;
else { stored_polynomials.top(p);
stored_polynomials.pop(p);
if(stored_polynomials.empty( ))
{ cout << "Stack has just one polynomial" << endl;
stored polynomials.push(p);
}
else
{ stored polynomials.top(q);
stored polynomials.pop( );
r.equals_sum(q, p);
if (stored_polynomials.push(r) == overflow)
cout << "Warning: Stack full, lost polynomial\n";
}
}
break;
// Add options for further user commands.
case ‘q':
cout << "Calculation finished." << endl;
return false;
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -