Using dynamic arrays, implement a polynomial class with polynomial addition, subtraction, and multiplication. Implement addition and subtraction functions first.
it should have three files and two txt file One is the main.cpp file One is the Polynomial.cpp file it's in the first picture One is the Polynomial.h file
One is A.txt One is B.txt
The contents of A and B.txt are in the picture.
I need h file and modify main file.
Here is the main.cpp code
#include <iostream> #include <fstream> #include "polynomial.h" using namespace std; int main() { ifstream infile; infile.open("A.txt"); if (infile.fail()) { cout << "Input file opening failed." << endl; exit(1); } int degree_A; infile >> degree_A; int* coef_A = new int[degree_A+1]; for (int i = 0; i < degree_A + 1; i++) coef_A[i] = 0; int coef, exp; while (!infile.eof()) { infile >> coef >> exp; coef_A[exp] = coef; } infile.close(); // read data from B.txt infile.open("B.txt"); if (infile.fail()) { cout << "Input file opening failed." << endl; exit(1); } int degree_B; infile >> degree_B; int* coef_B = new int[degree_B + 1]; for (int i = 0; i < degree_B + 1; i++) coef_B[i] = 0; while (!infile.eof()) { infile >> coef >> exp; coef_B[exp] = coef; } infile.close(); Polynomial p1(coef_A, degree_A); Polynomial p2(coef_B, degree_B); Polynomial p3 = add(p1, p2); Polynomial p4 = subtract(p1, p2); return 0; }
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.