Program.exe

The input numbers I put in does not work with instead it shows " the pointed number?(I think that's what it is called) versus my actual input. and I also get program.exe stopped working popupp window


Here are my codes
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138


#include <iostream>
using namespace std;
#include<cstring>

#include "Polynomial.h"

Polynomial:: Polynomial()
{
    degree=0;
	coefficients=NULL;
}


Polynomial::Polynomial(int degree, const double* coefficients)
{
	degree = degree;
	coefficients=coefficients;
}

Polynomial::Polynomial( const Polynomial& another)
 {
	degree=another.getDegree();
	 for(int i=degree;i>=0;i--)
	 {
		 coefficients[i]=another.coefficients[i];
	 }
}

Polynomial::~Polynomial()
{
	delete coefficients;
}

void Polynomial::setDegree(int d)
{
	if(d>=0)
	{
	degree = d;
	}
	else
	degree=0;
}
int Polynomial::getDegree(void) const
{
	return degree;
}

void Polynomial::setCoeff(int order)
{ 
	//double *coefficients;
	coefficients=new double[order];

	double temp;
	for(int i=order;i>=0;i--)
	{
		cin>>temp;
		coefficients[i]=temp;

	}
}



/*void Polynomial::setCoefficients(const double *coef)
{
	if(coef!=NULL)
		coefficients=NULL;
  else 
    coefficients=NULL;
  return;
}
const double* Polynomial::getCoefficients(void) const
{
	return coefficients;
}*/


 ostream& operator<<( ostream& out , const Polynomial& poly)
 {
	 int temp;
	 temp=poly.getDegree();
	 if(poly.coefficients==NULL)
	 {
		 cout<<"empty";
	 }
	 else{
	 for(int i=temp;temp>=0;temp--)
	 {
		 cout<<poly.coefficients[i]<<'x^('<<temp<<') ';
	 }
	 }
	 return out;
 }

istream& operator>>( istream& in,Polynomial& caught)
 {   
	 int temp;
	 cin>>temp;
	 caught.setDegree(temp);
	 caught.setCoeff(temp);
	 return in;
 }

const Polynomial& Polynomial:: operator=( const Polynomial& equate)
 {
	 degree=equate.getDegree();
	  for(int i=degree;i>=0;i--)
	 {
		 coefficients[i]=equate.coefficients[i];
	 }
	  return *this;
 }

bool Polynomial::operator==( const Polynomial& boolequate) const
 {
	 bool check=true;
	 if(degree==boolequate.getDegree())
	 {
		 for(int i=degree;i>=0;i--)
		 {
			 if(coefficients[i]==boolequate.coefficients[i])
			 {

			 }
			 else
				 check=false;
		 }
	 }
	 else return false;

	 if(check==false)
	 {
		 return false;
	 }
	 else return true;
 }




Here is the output i received
1
2
3
4
5
6
7
(1) Testing `cout << A':  empty
(2) Testing `cin >> A':
Enter the polynomial (integer order then double coefficients):
         2 2  0 2

(3) Second look at A:  278884242105282788842411052827888424010528
Press any key to continue . . .



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
// Polynomial.h

#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H
//class ostream;
//class istream;


class Polynomial
{
    friend ostream& operator<<( ostream& , const Polynomial& );
    friend istream& operator>>( istream& , Polynomial& );

  public:
    Polynomial();
    Polynomial( int degree, const double* coefficients );
    Polynomial( const Polynomial& );
    ~Polynomial();



    const Polynomial& operator=( const Polynomial& );
    bool operator==( const Polynomial& ) const;


	void setDegree (int degree);
    int getDegree() const;
	void setCoeff(int order);

	//void setCoefficients(const double* coef);
	//const double* getCoefficients(void) const;
	


  private:
	  int degree;
	  double *coefficients;

    
}
// Beware! Very, very incomplete!
; 
#endif 



Testerr 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
// TestThePoly.cpp


#include <iostream>
using std::cout;
using std::endl;
using std::cin;
using namespace std; 

#include "Polynomial.h"

int main()
{
  Polynomial A;
  cout << "(1) Testing `cout << A':  " << A << endl;

  cout << "(2) Testing `cin >> A':\n";
  cout << "Enter the polynomial (integer order then double coefficients):\n\t ";
  cin>>A;
cout << endl;
  cout << "(3) Second look at A:  " << A << endl;

  Polynomial B(A);
  cout << "(4) Testing `Polynomial B(A)':  " << B << endl;

  double clist[]={8, 4.5, 1};
  Polynomial C(2, clist);
  cout << "(5) Testing `Polynomial C(2, clist)':  " << C << endl;

  Polynomial D=C;
  cout << "(6) Testing D = C):  " << D << endl;

  cout << "(7) Testing A == B :  " << (A==B ? "TRUE" : "FALSE") << endl;
  cout << "(8) Testing A == D :  " << (A==D ? "TRUE" : "FALSE") << endl;  

  return 0;
}











HERe's directions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
I have provided a basic testing program, TestThePoly.cpp, and a header le,
Polynomial.h, for a polynomial class called Polynomial. Your job is relatively easy:
complete the class declaration in the header and then implement the functions that are in
the header le and test them to to ensure they work as advertised.
The testing program supplied is very basic. You will be expected to modify it and add
some (two or three) more tests to ensure that all aspects of the new class are exercised.
For those who may be confused, the \degree" of a polynomial is the highest degree of its
terms. For instance
4x3 + 3x2 + 0:3x 􀀀 1:54
is a polynomial of degree 3. Note: In this example there is one more term than the degree
of the polynomial.
1. The declaration should match the interface shown in the provided incomplete header
file Polynomial.h. Please understand that the actual structure of the private mem-
bers and functions of this class are up to you to design. Also, the degree of the
polynomial can be any nonnegative integer value (from 0 up to the sky is the limit).
2. The behavior of the class and its methods should duplicate that shown by the example
test application TestThePoly.cpp. Its associated program output is at the end of
this file. 



Here's the desired outcome
1
2
3
4
5
6
7
8
9
10
(1) Testing `cout << A': empty
(2) Testing `cin >> A':
Enter the polynomial (integer degree then double coefficients):
3 -1 2.09 -5.3 -0.98
(3) Second look at A: -1x^(3) +2.09x^(2) -5.3x^(1) -0.98
(4) Testing `Polynomial B(A)': -1x^(3) +2.09x^(2) -5.3x^(1) -0.98
(5) Testing `Polynomial C(2, clist)': +1x^(2) +4.5x^(1) +8
(6) Testing D = C: +1x^(2) +4.5x^(1) +8
(7) Testing A == B : TRUE
(8) Testing A == D : FALSE
Topic archived. No new replies allowed.