本文整理汇总了C++中Poly::push_term方法的典型用法代码示例。如果您正苦于以下问题:C++ Poly::push_term方法的具体用法?C++ Poly::push_term怎么用?C++ Poly::push_term使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poly
的用法示例。
在下文中一共展示了Poly::push_term方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: controller
/* Function: controller
-----------------------------------------
usage: controller(<input-file-stream>);
Accepts an input filestream as only argument. Creates a vector of
Poly(polynomial class) pointers. Also creates an iterator of the
same type and proceeds to parse the input filestream based on
relavent functionality. Controller will accept input of
polynomials, as direct polynomial terms or as a mulitiple of 2 Polys.
Controller will also act upon the appropriate polynomail with 2 commands
show : displays the polynomial ex. 2x^2+5x+1
eval : evaluates the polynomail with the supplied argument
*/
void controller (std::ifstream& input){
std::vector<Poly*> polys(100);
std::vector<Poly*>::iterator polyIt;
/*set default value for each Poly* in polys to NULL */
for ( polyIt=polys.begin(); polyIt!=polys.end();polyIt++){
(*polyIt)=NULL;
}
/****************************************
* Build the full vector of Polynomials from the file
***********************************************/
try {
std::string str;
std::vector<std::string>data;
while(std::getline(input, str, '\n')) {
const char *cStr = str.c_str();
/* check for command or not */
if(isdigit(cStr[0])){
polyIt= polys.begin();
int polyPos=-1;
try{
data = split(str, ' '); // splitting on whitespace
std::cout << "length of data= " << data.size()<< std::endl;
}catch(...){
std::cout << "\nExeption thrown splitting string";
std::cout<< "\nError Occured IN: "+str;
}
polyPos= atoi(data[0].c_str());
std::string op_string = data[1];
std::cout<< op_string << std::endl;
char oper= data[1][0];
int count=0,coeff=0,exp=-1;
Poly *add = new Poly();
/* Regular Polynomial building below.
*/
if (oper==':'){
for (unsigned i =2; i < data.size(); i++){
if (count==0){
coeff= atoi(data[i].c_str());
} else if( count==1){
exp= atoi(data[i].c_str());
}
std::cout << "coeff =" << coeff << "expo= " << exp << std::endl;
count++;
if (count>=2){
add->push_term(coeff,exp);
count=0;
}
}
}
/* Multiplication for 2 polynomials Below. */
else if (oper=='='){
int poly1= atoi(data[2].c_str());
int poly2= atoi(data[4].c_str());
if (polys[poly1]==NULL || polys[poly2]==NULL)
throw "ERROR: INVALID POLY VECTOR INDEX";
add = ((*(polys[poly1]))) * (*(polys[poly2]));
polys[polyPos]=add;
}
/*USE INDEX TO PLACE POLY INTO POSITION */
polys[polyPos]=add;
} else {
/* Command Section: Split strings then execute operations
based on 2 possibilities:
show and eval
*/
try{
data = split(str, ' '); // splitting on whitespace
}catch(...){
std::cout << "\nExeption thrown splitting string";
std::cout << "\nError Occured IN: "+str;
}
/*variables for switching behavior */
std::string command= data[0];
/* */
enum com_Choice{show, eval} commands;
int operand= atoi(data[1].c_str());
int value= atoi(data[2].c_str());
//.........这里部分代码省略.........