Please check if Classes Constructors and Functions are good

Last time i needed help this was the best way i got help from, there is so many smart guys in here, so i need some help now.

Write a program using classes that will add and subtract polynomials of degree 3 (only). The program will have the following features:
(a) A class called Polynomial with 2 constructors (The default and another one)
(b) Member functions to add and subtract two polynomials.
(c) A member function to print a polynomial.

Note: 1. All the functions must be member functions, except: menu and input functions
2. The menu will allow the user to select either to add or to subtract two polynomials.
3. After the menu allow the user to enter the coefficients of both polynomials.
4. All the variables needed for the student class must be declared private.
5. The print function should display all the information about the polynomial.
6. The Polynomial Class will be in a header file (You need to use ifndef, define directives)
7. Recall that a polynomial of degree 3 has form: p(x) =  ax^3 + bx^2 cx + d

Test your program with the following sets of values and another set of your own:
P1: 2, -3, 5, 8
P2: -3, 6, -6, -7 (Add)
P1: 8, 0, 0, -5
P2: 1, 1, -4, 0 (Subtract)
P1: -2, -7, 7, -2
P2: -1, -1, -6, -2 (Subtract)
P1: 2, 0, 0, -4
P2: 1, -1, 3, 3 (Add)

so this is my header file
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef Polynomial_H
#define Polynomial_H

#include <iostream>
#include <math.h>
using namespace std;

class Polynomial
{
	private:
		int a, b, c, d;
		
	public:
		Polynomial();
		Polynomial(int, int, int, int);
		int add(int, int, int, int);
		int substract(int, int, int, int);
		void print();
};
Polynomial::Polynomial()
{
	a = 0;
	b = 0;
	c = 0;
	d = 0;
}
Polynomial::Polynomial(int a1, int b1, int c1, int d1)
{
	a = a1;
	b = b1;
	c = c1;
	d = d1;
}
int Polynomial::add(int a1, int b1, int c1, int d1)
{
	return a1*pow(a1, 3) + b1*pow(b1, 2)+ c1*pow(c1, 1) +d1;
}
int Polynomial::substract(int a1, int b1, int c1, int d1)
{
	return a1*pow(a1, 3) - b1*pow(b1, 2)- c1*pow(c1, 1) -d1;
}

void Polynomial::print()
{
	cout << a << "x^3 " << b << "x^2 " << c << "x " << d << endl;
}
#endif 


And this is my main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "Polynomial.h"

int main()
{
	Polynomial P1(a, b, c, d);
	Polynomial P2(e, f, g, h);
	
	P1.add(a, b, c, d);
	P2.substract(e, f, g, h);
	
	return 0;
}
int Selectionmenu()
{
	cout << "Enter 1 for Addition and 2 for Susbtraction";
	cin >> n;
	if(1 || 2)
	cout << "Now Enter 4 coefficients: \n";
	if (1)
	cin >> a>>b>>c>>d;
	if (2)
	cin >>e>>f>> g>>h;
}


What am i doing wrong? (im not supposed to use signed or unsigned yet)
Last edited on
Topic archived. No new replies allowed.