class polynomial
{
public:
// CONSTANT
static const int CAPACITY = 15;
// CONSTRUCTOR
polynomial(double c = 0.0, int degree = 0);
// MEMBER FUNCTIONS
void add_to_coef(double amount, int degree);
void assign_coef(double c, int degree);
void clear();
double coefficient(int degree) const;
void print();
int degree() const;
private:
// DATA MEMBERS
double coef[CAPACITY];
int largest_degree;
};
#include "poly.h"
#include <cmath>
using namespace std;
static const int CAPACITY = 15;
// Start implementing your functions here
1
Expert's answer
2012-05-24T09:14:58-0400
#pragma once #include <iostream> class polynomial { public: & //CONSTANT & static const int CAPACITY = 15; & // CONSTRUCTOR & polynomial(double c = 0.0, int degree = 0); & // MEMBER FUNCTIONS & void add_to_coef(double amount, int degree); & void assign_coef(double c, int degree); & void clear(); & double coefficient(int degree) const; & void print(); & int degree() const; private: & // DATA MEMBERS & double coef[CAPACITY]; & int largest_degree; };
#include "poly.h" #include <cmath> #include<process.h> using namespace std; polynomial::polynomial(double c , int degree ) { if (degree<CAPACITY){ largest_degree=degree; for(int i=0;i<=degree;i++) coef[i]=c; } else cout<<"Bad degree";exit(0);//because it is very important to know & //did we create element or not.
Comments
Leave a comment