C ++中的OOP多项式编程 [英] OOP polynomial programming in C++

查看:88
本文介绍了C ++中的OOP多项式编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要提交有关C ++多项式的作业(截止日期为2011年9月26日),并包含所有标头(hpp),cpp.我已经给出了主文件,并且可以在下面找到它

hi i need to submit my assignment(due 9/26/2011) on polynomial in C++ with all header(hpp),cpp.I have already given main file and u can find it below

/*
  Polynomial_s.cpp
 
  Syntax checking of the interface of a Polynomial class

  
*/

#include "Polynomial.hpp"
#include <iostream>
#include <cassert>
#include <vector>

int main() {

  Polynomial q;
  Polynomial q2 = q;
  Polynomial q3(q);

  q2 = q;

  // constant constructor
  Polynomial c(5);

  // output
  std::cout << c << '\n';

  // equality
  c == c;

  // inequality
  c != c;

  // addition
  Polynomial a1(2);
  Polynomial a2(3);
  Polynomial a3(5);

  a1 += a2;

  assert(a1 == a3);
  assert(a1 == 5);

  // access coefficients based on degree of term
  a3.coefficient(0);

  // linear constructor
  Polynomial l(2, -3);
  assert(l.coefficient(0) == 2);
  assert(l.coefficient(1) == -3);

  // quadratic constructor
  Polynomial quad(1, 0, -1);
  assert(quad.coefficient(0) == 1);
  assert(quad.coefficient(1) == 0);
  assert(quad.coefficient(2) == -1);

  // vector constructor
  std::vector<double> coeffs(4);
  coeffs[0] = 1; coeffs[1] = 0; coeffs[2] = -1;
  Polynomial poly(coeffs);

  // c-array constructor
  double acoeffs[] = { 1, 0, -1 };
  Polynomial polya(acoeffs, 3);

  // factoring
  std::vector<polynomial> factors = polya.factor();

  return 0;
}

推荐答案

在反思中,猜想是您期望有人为您编写此类的实现,因此您可以将其交给您明天教授,声称这是你自己的工作.对不起,但是那不会发生.您需要问问自己自己是如何情况的,只剩下一个周末来完成这项任务.可能是因为您在上花费了太多时间 [
On reflection, and at a guess, you are expecting someone to write the implementation of this class for you so you can hand it to your professor tomorrow, claiming it is all your own work. Sorry, but that just will not happen. You need to ask yourself how you got to a situation to only leave yourself a single weekend to complete this assignment. Maybe because you spent too much time on this[^].


这篇关于C ++中的OOP多项式编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆