当前位置: 首页>>代码示例>>C++>>正文


C++ Poly::remainder方法代码示例

本文整理汇总了C++中Poly::remainder方法的典型用法代码示例。如果您正苦于以下问题:C++ Poly::remainder方法的具体用法?C++ Poly::remainder怎么用?C++ Poly::remainder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Poly的用法示例。


在下文中一共展示了Poly::remainder方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char * argv[])
{
	try							//If the argument count is not 3, then the command line usage was incorrect. A message is displayed
	{
		if (argc != 3)
		{
			throw 1;
		}

	}
	catch(int e)
	{
		if (e == 1)
		{
			cout<< "Usage Incorrect. Correct Usage: ProgramName.exe InputFile OutPutfile" << endl;
		}
	}
	if( argc == 3)														//Otherwise, stream in the input file
	{
		ifstream in(argv[1]);

		if (!in.is_open())											//if the file did not open, display a message
		{
			cout << "The input file could not be opened." <<endl;
		}
		else
		{
			ofstream out;								//output file is specified and/or created
			out.open(argv[2]);

			expotype tempexpo;							//used to hold exponents that are streamed in
			coeftype tempcoef;							//used to hold coefficients that are streamed in
			Poly n;										//n is the first input polynomial
			Poly n2;									//n2 is the second input polynomials
			Poly nadd;									//the result of n + n2
			Poly nmult;									//the result of n * n2
			Poly ndiv;									//the result of n / n2
			Poly q;										// the quotient
			Poly r;										//the remainder
			bool isnegative;							//value to check for a negative exponent
			bool iszero;								//value to check for a zero coefficient
			string xstring;								//string to store "XXX" divider

			while(in >> tempcoef >> tempexpo)			//The first polynomial is streamed in
			{
				n.newterm(tempexpo, tempcoef);
			}
			in.clear();									//The file cannot proceed because "XXX" was encountered and must be cleared
			getline(in, xstring, '\n');					//the "XXX" line is placed into xstring
			iszero = n.zero();							//n is checked for zero coefficients and negative exponents
			isnegative = n.negative();

			if(xstring != "XXX")						//If there is no "XXX" then there is a bad input file and a message is displayed
			{
				cout<< "Bad Input File." << endl;
			}
			else if (iszero)							//If there is a zero coefficient, a message is displayed
			{
				cout<< "Bad Input File. There is a coefficient of Zero" << endl;	
			}
			else if (isnegative)						//If there is a negative exponent, a message is displayed
			{
				cout << "Bad Input File. There is a negative exponent." << endl;
			}
			else
			{
				while(in >> tempcoef >> tempexpo)			//The second polynomial is streamed in and placed into n2
				{
					n2.newterm(tempexpo, tempcoef);
				}
		
				n.sort();									//both n and n2 are sorted and simplified
				n.simplify();
				n2.sort();
				n2.simplify();

				nadd = n + n2;							//The operations are done and quotients and remainders separated
				nmult = n * n2;
				ndiv = n / n2;
				q.quotient(ndiv);
				r.remainder(ndiv);
			
				nadd.sort();							//All resulting polynomials are sorted and simplified
				nadd.simplify();
				nmult.sort();
				nmult.simplify();
				ndiv.sort();
				ndiv.simplify();

				out << nadd;							//All polynomials are displayed.
				out << "YYY" <<endl;
				out << nmult;
				out << "ZZZ" <<endl;
				out << q;
				out << "RRR" <<endl;
				out << r;
				cout << "Finished." << endl;			//finished is displayed to signify completion
			}
		}
	}
开发者ID:chunkyboy068,项目名称:archive,代码行数:100,代码来源:computepoly.cpp


注:本文中的Poly::remainder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。