Student is Desperate

B

beachlounger

What the heck is wrong with this:

#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H


class Polynomial {
public:
Polynomial();
Polynomial operator+( const Polynomial& ) const; // addition
Polynomial operator-( const Polynomial& ) const; // subtraction
Polynomial operator*( const Polynomial& ); // multiplication
const Polynomial operator=( const Polynomial&);// assignment
Polynomial& operator+=( const Polynomial& );
Polynomial& operator-=( const Polynomial& );
Polynomial& operator*=( const Polynomial& );
void enterTerms();
void printPolynomial() const;
private:
int exponents[ 100 ]; // exponent array
int coefficients[ 100 ]; // coefficients array
void polynomialCombine( Polynomial& ); // combine common terms
}; // end class Polynomial


#endif


#include <iostream>

using std::cout;
using std::endl;

#include "Polynomial.h"


int main()
{
Polynomial a, b, c, t;

a.enterTerms();
b.enterTerms();
t = a; // save the value of a
cout << "First polynomial is:\n";
a.printPolynomial();
cout << "Second polynomial is:\n";
b.printPolynomial();
cout << "\nAdding the polynomials yields:\n";
c = a + b;
c.printPolynomial();
cout << "\n+= the polynomials yields:\n";
a += b;
a.printPolynomial();
cout << "\nSubtracting the polynomials yields:\n";
a = t; // reset a to original value
c = a - b;
c.printPolynomial();
cout << "\n-= the polynomials yields:\n";
a -= b;
a.printPolynomial();
cout << "\nMultiplying the polynomials yields:\n";
a = t; // reset a to original value
c = a * b;
c.printPolynomial();
cout << "\n*= the polynomials yields:\n";
a *= b;
a.printPolynomial();
cout << endl;
return 0;
} // end main


C:\Documents and Settings\Owner\connie marshall's week 7
homework.cpp(32) : fatal error C1083: Cannot open include file:
'Polynomial.h': No such file or directory

The question is:

Using C++ language to complete this homework

1. Develop class Polynomial. The internal representation of a
Polynomial is an array of terms. Each term contains a coefficient and
an exponent. The term

2x4
has the coefficient 2 and the exponent 4. Develop a complete class
containing proper constructor functions as well as set and get
functions. The class should also provide the following overloaded
operator capabilities:

(a) Overload the addition operator (+) to add two Polynomials.
(b) Overload the multiplication operator (*) to multiply two
Polynomials.
(c) Overload the subtraction assignment operator (-) to process two
Polynomials
(d) Overlaod the assignment operator to assign one polynomial to
another
(e) Overload the addition assignment operator (+=), subtraction
assignment operator (-=), and multiplication assignment operator(*=).

I'm going crazy here. Please help.
 
P

Phlip

beachlounger said:
What the heck is wrong with this:

C:\Documents and Settings\Owner\connie marshall's week 7
homework.cpp(32) : fatal error C1083: Cannot open include file:
'Polynomial.h': No such file or directory

Do you have a file called C:\Documents and Settings\Owner\Polynomial.h ?

If not, put the stuff between #ifdef and #endif into it, inclusive.
I'm going crazy here. Please help.

Your next tip is to form a study group with your classmates.
 
A

Alf P. Steinbach

* (e-mail address removed):
What the heck is wrong with this:

#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H


class Polynomial {
public:
Polynomial();
Polynomial operator+( const Polynomial& ) const; // addition
Polynomial operator-( const Polynomial& ) const; // subtraction
Polynomial operator*( const Polynomial& ); // multiplication
const Polynomial operator=( const Polynomial&);// assignment
Polynomial& operator+=( const Polynomial& );
Polynomial& operator-=( const Polynomial& );
Polynomial& operator*=( const Polynomial& );
void enterTerms();
void printPolynomial() const;
private:
int exponents[ 100 ]; // exponent array
int coefficients[ 100 ]; // coefficients array
void polynomialCombine( Polynomial& ); // combine common terms
}; // end class Polynomial


#endif


#include <iostream>

using std::cout;
using std::endl;

#include "Polynomial.h"


int main()
{
Polynomial a, b, c, t;

a.enterTerms();
b.enterTerms();
t = a; // save the value of a
cout << "First polynomial is:\n";
a.printPolynomial();
cout << "Second polynomial is:\n";
b.printPolynomial();
cout << "\nAdding the polynomials yields:\n";
c = a + b;
c.printPolynomial();
cout << "\n+= the polynomials yields:\n";
a += b;
a.printPolynomial();
cout << "\nSubtracting the polynomials yields:\n";
a = t; // reset a to original value
c = a - b;
c.printPolynomial();
cout << "\n-= the polynomials yields:\n";
a -= b;
a.printPolynomial();
cout << "\nMultiplying the polynomials yields:\n";
a = t; // reset a to original value
c = a * b;
c.printPolynomial();
cout << "\n*= the polynomials yields:\n";
a *= b;
a.printPolynomial();
cout << endl;
return 0;
} // end main


C:\Documents and Settings\Owner\connie marshall's week 7
homework.cpp(32) : fatal error C1083: Cannot open include file:
'Polynomial.h': No such file or directory

The question is:

Using C++ language to complete this homework

1. Develop class Polynomial. The internal representation of a
Polynomial is an array of terms. Each term contains a coefficient and
an exponent. The term

You're missing the file [Polynomial.h].

The assignment seems to be to create that file.

And possibly also an implementation file [Polynomial.cpp].
 
H

Howard

C:\Documents and Settings\Owner\connie marshall's week 7
homework.cpp(32) : fatal error C1083: Cannot open include file:
'Polynomial.h': No such file or directory

The question is:

Using C++ language to complete this homework

Your assignment really has nothing to do with the error message. Read it.
It says it can't find the file "Polynomial.h". If that file exists, is it
in the correct directory? Is it spelled correctly? Does your compiler know
where to look for it? You may need to add it to your project, or add the
directory where it is stored to some kind of search path in your compiler or
project settings.

Answers to problems like that are best gotten from a newsgroup devoted to
your compiler, not from this language newsgroup.

-Howard
 
T

Thomas Matthews

What the heck is wrong with this:

#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H


class Polynomial {
public:
Polynomial();
Polynomial operator+( const Polynomial& ) const; // addition
Polynomial operator-( const Polynomial& ) const; // subtraction
Polynomial operator*( const Polynomial& ); // multiplication
const Polynomial operator=( const Polynomial&);// assignment
Polynomial& operator+=( const Polynomial& );
Polynomial& operator-=( const Polynomial& );
Polynomial& operator*=( const Polynomial& );
void enterTerms();
void printPolynomial() const;
private:
int exponents[ 100 ]; // exponent array
int coefficients[ 100 ]; // coefficients array
void polynomialCombine( Polynomial& ); // combine common terms
}; // end class Polynomial


#endif

Cut here and paste the above text into Polynomial.h.
#include <iostream>

using std::cout;
using std::endl;

#include "Polynomial.h"


int main()
{
Polynomial a, b, c, t;

a.enterTerms();
b.enterTerms();
t = a; // save the value of a
cout << "First polynomial is:\n";
a.printPolynomial();
cout << "Second polynomial is:\n";
b.printPolynomial();
cout << "\nAdding the polynomials yields:\n";
c = a + b;
c.printPolynomial();
cout << "\n+= the polynomials yields:\n";
a += b;
a.printPolynomial();
cout << "\nSubtracting the polynomials yields:\n";
a = t; // reset a to original value
c = a - b;
c.printPolynomial();
cout << "\n-= the polynomials yields:\n";
a -= b;
a.printPolynomial();
cout << "\nMultiplying the polynomials yields:\n";
a = t; // reset a to original value
c = a * b;
c.printPolynomial();
cout << "\n*= the polynomials yields:\n";
a *= b;
a.printPolynomial();
cout << endl;
return 0;
} // end main


C:\Documents and Settings\Owner\connie marshall's week 7
homework.cpp(32) : fatal error C1083: Cannot open include file:
'Polynomial.h': No such file or directory

The question is:

Using C++ language to complete this homework

1. Develop class Polynomial. The internal representation of a
Polynomial is an array of terms. Each term contains a coefficient and
an exponent. The term

2x4
has the coefficient 2 and the exponent 4. Develop a complete class
containing proper constructor functions as well as set and get
functions. The class should also provide the following overloaded
operator capabilities:

(a) Overload the addition operator (+) to add two Polynomials.
(b) Overload the multiplication operator (*) to multiply two
Polynomials.
(c) Overload the subtraction assignment operator (-) to process two
Polynomials
(d) Overlaod the assignment operator to assign one polynomial to
another
(e) Overload the addition assignment operator (+=), subtraction
assignment operator (-=), and multiplication assignment operator(*=).

I'm going crazy here. Please help.


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top