Binomials

Mar 11, 2018 at 4:54am
Stuck on how to do this.
My class product.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef _PRODUCT_H
#define _PRODUCT_H
#include <iostream>
#include <cstdlib>
#include <vector>

using namespace std;

class Product {
  public:
    void multiplyNumber(int p);
    void divideNumber(int p);
    void multiplyFactorial(int p);
    void divideFactorial(int p);
    void multiplyBinomial(int p, int r);
    void divideBinomial(int p, int r);
    void clear();
    void print();
    double calculateProduct();
  protected:
    vector <int> numerator;
    vector <int> denominator;
};

#endif


The entries in the vector represent how many times that factor shows up in the product.

Ex. 1 * 1 * 3 * 5 * 6 * 6
will be shown as the vector {0, 2, 0, 1, 0, 1, 2}

multiplyFactorial(p) and divideFactorial(p) multiply and divide by p!.

multiplyBinomial(p,r) and divideBinomial(p,r) multiply and divide by binomial(p,r).

print() prints what the product is by printing the numerator and denominator. It should cancel numbers that are in both the numerator and denominator.


Product n;
n.print();
n.multiplyBinomial(6,3);
n.print();
n.multiplyNumber(5);
n.divideNumber(4);

will print
1
4 * 5 * 6 / 2 / 3
5 * 5 * 6 / 2 / 3

calulateProduct() will return the product, if the terms cancel then those terms will not be used in the calculation.
Last edited on Mar 13, 2018 at 2:27am
Topic archived. No new replies allowed.