【发布时间】:2018-10-06 14:09:17
【问题描述】:
所以我创建了一个方法来启动添加、乘法等多项式的过程,但是,当尝试运行 start() 时,编译器会运行,但该框仍然是空白的,即使它不应该如此。不完全确定我做错了什么。
有什么想法吗?
这是我的代码。
这是我的标题
#ifndef _POLY_GUARD
#define _POLY_GUARD
#include <iostream>
using namespace std;
class Polynomial
{
public:
Polynomial(int coef, int exp);
void start();
friend ostream & operator << (ostream &out, const vector<int> &c);
friend istream & operator >> (istream &in, const Polynomial &c);
void addPolynomials();
void multiplyPolynomials();
void evaluatePolynomial();
int findCoefficient();
int findLeadingExponent();
};
#endif
这是源代码。
#include "Polynomial.h"
#include <utility>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void Polynomial::start()
{
int choice;
std::cout << "What do you wish to do?" << std::endl;
std::cout << "1. Add two polynomials" << std::endl;
std::cout << "2. Multiply two polynomials" << std::endl;
std::cout << "3. Evaluate one polynomial at a given value" << std::endl;
std::cout << "4. Find Coefficent for a given polynomial and given exponent" << std::endl;
std::cout << "5. Find the leading exponent for a given polynomial" << std::endl;
std::cout << "6. Exit " << std::endl;
std::cin >> choice;
if (choice < 1 || choice > 6)
{
do
{
std::cout << "Invalid entry: please reenter choice" << std::endl;
std::cin >> choice;
} while (choice < 1 || choice > 6);
}
if (choice == 1)
{
}
}
最后,这是我的主要内容
#include "Polynomial.h"
#include <string>
#include <vector>
#include <utility>
int main()
{
Polynomial start();
system("pause");
}
【问题讨论】:
-
我的第一个想法是让您使用调试器并使用调试会话的结果编辑您的帖子。
-
@ThomasMatthews 我已经调试了几次。没有骰子。
-
Polynomial start()声明了一个函数。除了您对system()的调用之外,没有任何东西被调用。 -
@1201ProgramAlarm 那么我该如何调用 start()?
-
Polynomial p; p.start();
标签: c++ function methods header main