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


C++ Factor::bFactor方法代码示例

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


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

示例1: main

int main()
{
    Factor myFactor; //initialization of constructor
wrong:
    // ask the user to input the correct coefficients for the current problem they are working on
    cout << "Please enter the coefficient for x^2: ";
        int terms;
        cin >> terms;
        myFactor.setA(terms);
        cout << endl;

        cout << "Please enter the coefficient for x: ";
        cin >> terms;
        myFactor.setB(terms);
        cout << endl;

        cout << "Please enter the constant term (c): ";
        cin >> terms;
        myFactor.setC(terms);
        cout << endl;

    // tell user what the current setting initialized by the constructor are
    cout << "The polynomial you entered has coefficients:\n" << "A: " << myFactor.getA()
     << "\nB: " << myFactor.getB() << "\nC: " << myFactor.getC() << endl;

    // ask if they would like to change the default choice
     int choice;
     do
     {
         cout << "Does this look correct?\n"
            << "1. Yes\n2. No" << endl;
            cin >> choice;
     } while(choice != 1 && choice != 2);

    // if the coefficients entered are correct then go to the start of the algorithm section of the progrma
     if (choice == 1)
    {
        goto start;
    }

    // to enter your own number choose 2
    if (choice == 2)
    {
        goto wrong;

    }

start:

        if(myFactor.getA() > 1 || myFactor.getA() < 0)
    {
        cout << "\nFactoring A (" << myFactor.getA() << ").......\n" << endl;
        myFactor.aFactor(myFactor.getA());

        cout << "\nFactoring B (" << myFactor.getB() << ")........\n" << endl;
        myFactor.bFactor(myFactor.getB());

        cout << "\nFactoring C (" << myFactor.getC() << ")........\n" << endl;
        myFactor.cFactor(myFactor.getC());

        myFactor.testFactorsOfA();
    }

    if(myFactor.getA() == 1)
    {
        cout << "\nFactoring C (" << myFactor.getC() <<")......\n" << endl;

        myFactor.cFactor(myFactor.getC());
        // run the test factors program to determine what the proper factors are to use
        myFactor.testFactorsOfC();

        // this line just tells you what a and b are
        cout << "in (x+a)(x+b)\n" << "\na is " << myFactor.getFactoredaOfC()
        << "\nand\nb is " << myFactor.getFactoredbOfC() << endl;

        // this block of if statements will spit out the correct syntax of (x+a)(x+b) depending
        // on whether one or both factors are positive or negative respectively.
        if (myFactor.getFactoredaOfC() < 0 && myFactor.getFactoredbOfC() > 0)
        {
            cout << "\nSo your final form is (x" << myFactor.getFactoredaOfC() << ")(x+" << myFactor.getFactoredbOfC() << ") " << endl;
        }

        if (myFactor.getFactoredaOfC() > 0 && myFactor.getFactoredbOfC() < 0)
        {
            cout << "\nSo your final form is (x+" << myFactor.getFactoredaOfC() << ")(x" << myFactor.getFactoredbOfC() << ") " << endl;
        }

        if (myFactor.getFactoredaOfC() < 0 && myFactor.getFactoredbOfC() < 0)
        {
            cout << "\nSo your final form is (x" << myFactor.getFactoredaOfC() << ")(x" << myFactor.getFactoredbOfC() << ") " << endl;
        }

        if (myFactor.getFactoredaOfC() > 0 && myFactor.getFactoredbOfC() > 0)
        {
            cout << "\nSo your final form is (x+" << myFactor.getFactoredaOfC() << ")(x+" << myFactor.getFactoredbOfC() << ") " << endl;
        }

        // delete dynamically allocated memory when program ends.
        myFactor.deleteArrayOfC();
    }
//.........这里部分代码省略.........
开发者ID:Asphxiated,项目名称:FactoringTool,代码行数:101,代码来源:main.cpp


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