473,799 Members | 3,080 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help-New Student Trying Hard

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.

This is what I have so far
#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 polynomialCombi ne( 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.printPolynomi al();
cout << "Second polynomial is:\n";
b.printPolynomi al();
cout << "\nAdding the polynomials yields:\n";
c = a + b;
c.printPolynomi al();
cout << "\n+= the polynomials yields:\n";
a += b;
a.printPolynomi al();
cout << "\nSubtract ing the polynomials yields:\n";
a = t; // reset a to original value
c = a - b;
c.printPolynomi al();
cout << "\n-= the polynomials yields:\n";
a -= b;
a.printPolynomi al();
cout << "\nMultiply ing the polynomials yields:\n";
a = t; // reset a to original value
c = a * b;
c.printPolynomi al();
cout << "\n*= the polynomials yields:\n";
a *= b;
a.printPolynomi al();
cout << endl;
return 0;
} // end main

My error is 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
Please help!!!!!!

Aug 11 '06 #1
3 3224
posted:
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.

Well here's one way of going about it. Perhaps firstly set the maximum
exponent:

enum { EXPONENT_MAX = 100 };

Then maybe create a simple structure like this:

struct CoAndExp {
unsigned co_max;
unsigned exp_max;
};

Then maybe place such an array inside your class:

class Polynomial {
private:

struct CoAndExp {
unsigned co_max;
unsigned exp_max;
};

CoAndExp terms[EXPONENT_MAX];

Polynomial() : terms() {}
};

class Polynomial {
public:
Polynomial();
Polynomial operator+( const Polynomial& ) const; // addition
Polynomial operator-( const Polynomial& ) const; // subtraction
Polynomial operator*( const Polynomial& ); // multiplication

Depending on whether you want the built-in types to be able to implicitly
convert to a Polynomial, I would take these outside the class:

Polynomial operator+(Polyn omial lhs, Polynomial const &rhs)
{
return lhs += rhs;
}

My error is 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

Nothing magical here -- the file doesn't exist.

Try saving the file as "polynomial .h" and try again.

(One thing, I would advocate that you use ".hpp" rather than ".h" -- we're
dealing with C++, not C.)

--

Frederick Gotham
Aug 11 '06 #2
be**********@ao l.com wrote:
My error is 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
Please help!!!!!!
Does this h file exist? Is it in the same directory as the cpp file that
does the #include ?

--
Scott McPhillips [VC++ MVP]

Aug 11 '06 #3
Hello,

be**********@ao l.com wrote:
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.
Think about the mathematical structure. A univariate polynomial p looks
like p(x)=sum c_i x^i. Basically the sequence of the c_i is enough to
characterize it. Let there be a maximal i for every polynomial with
non-zero c_i. Now there are two observations possible.

The first is that polynomials form a module, or a vector space if the
coefficients are from a field. The vectors have a maximal index with
the corresponding entry non-zero. All coefficients up to this index are
stored, all others not.

The second observation is, that a sequence is a mapping from the natural
numbers to the coefficients, and zero coefficients are the default, so
you need to map only those finitely many exponents with non-zero
coefficient.

If you look through the tools the C++ standard library offers to you,
you will find vector and map. If you employ vector in the most direct
way, you will get something called dense polynomials, in the other case
with map you will get sparse polynomials. When dealing with polynomials
the selection between those two has to be done carefully to get
efficient solutions to the problem in question.

Now, for addition of polynomials, you have to add the corresponding
coefficients. You will have to create the result polynomial, traverse
both data structures of the corresponding polynomials and collect the
result. Subtraction is not much different. Multiplication is only a
little bit more involved. Look for formal definitions of the product of
polynomials or folding of sequences.

In the sparse case you will find a close similarity of addition and
subtraction of polynomials to the problem of merging two sorted
seqences. Look for mergesort to get the idea.
>
This is what I have so far
#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H
Everything within this #ifndef ... #endif should be in 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
Those arrays might be usable as dense and as sparse polynomials. What
special restrictions would the 100 imply, if you use them with dense
and with sparse in mind? If you use them as dense, what would the
content of exponents be in every case.
void polynomialCombi ne( Polynomial& ); // combine common terms
}; // end class Polynomial
And the bodies of those member functions of Polynomial are defined
where? polynomial.cc?

You could write all the code into a single file without including other
code you wrote, but this is bad style and prevents reuse. It should be
explained in textbooks where to put what, and there or in
compiler/linker manuals how to compile and link the parts together. You
could perhaps look for the C++ FAQ.

Bernd Strieder

Aug 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
6563
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to reformatting my system. Prior to the reformatting, I copied the help.rtf file onto a CD and checked the box to...
10
2281
by: Jacek Generowicz | last post by:
Where can I find concise, clear documentation describing what one has to do in order to enable Python's internal help to be able to provide descriptions of Python keywords ? I am in a situation where I have to give Python novices the ability to fix this for themselves easily. Failing "concise" and "clear", how about "complete and correct" ?
9
4417
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with the microsoft HTML workshop utility, lets call it c:\path\help.chm. My question is how do you launch it from the GUI? What logic do I put behind the "help" button, in other words. I thought it would be os.spawnv(os.P_DETACH,...
4
3358
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to cmd.Cmd but I would also like to get the man-page-like help for classes and functions. Does anyone know how to do that? Thanks. Sarir
6
4356
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
4
2639
by: dixie | last post by:
Help, I'm really out of my depth here (not unusual I hear you say :-). I have just installed HTML Help in an application. I told it in the Project Properties the path to the help file. I then type in a command line that runs the help in the correct Context from a button on each form. It all worked fine - HERE. The problem is that when I sent it out to a site, the help file was not able to be accessed because it was my path in the...
5
3288
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time using "F1" help within the VB IDE. Is this expectation achievable In trying to test my help file in the IDE, I have a solution with 2 projects: the DLL and a tester. VB does not look for my help file; instead, it looks for path to my source code...
8
3238
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both including search the internet for help, but the help is worthless. Any ideas?
10
3369
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably the worst I ever seen. I almost cannot find anything I need, including things I
0
2896
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application calls MS Excel, so the scenario is that I am supposed to see the Excel Menu bar, FILE EDIT VIEW INSERT ... HELP. I am able to see the menu bar, but in case of Help, I see the Help of Excel and help of my application, both as a submenu of help. ...
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10484
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.