Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 16th, 2012, 09:36 AM
Registered User
 
Join Date: Aug 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default plz help me to solve it

develop class polynomial.The internal representation of a polynomia is an array of terms.each term contains a co-efficient and an exponet.The term 2x ki power 4 has the coefficient 2 and the exponent 4. Develop a complete that class containing proper constructor and destructorfunctions as well as set and get functions.The class should also provide the following overloaded operator capabilities:
1- overloaded the addition operator(+) to addtwo polynomials.
2-overloaded the subtraction operator(-) to subtract two polynomials.
3- overloaded the multiplication operator(*) to multiply two polynomials.
i'm waiting 4 ur response....???????
Reply With Quote
  #2 (permalink)  
Old September 27th, 2012, 05:55 AM
Registered User
 
Join Date: Sep 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default re

check this
# //-----------------------------------------------------------------------------
# //
# // A Polynomial Class
# //
# // Author: Iamthwee 2008 (c)
# //
# // Improvements:
# // Could use a dynamic array as opposed to a static one.
# // Could improve the print function to tidy up the output.
# // Suffers from a space complexity issue but achieves lexicographic sorting
# // very easily. I.e. prints terms in order of powers highest to lowest
# // Could use operator overloading for code syntax candy lovers.
# //
# // Notes:
# // Bugs may exist, not thorougly tested.
# //
# //------------------------------------------------------------------------------
#
# #include <iostream>
#
# using namespace std;
#
# class Polynomial
# {
# //define private member functions
# private:
# int coef[100]; // array of coefficients
# // coef[0] would hold all coefficients of x^0
# // coef[1] would hold all x^1
# // coef[n] = x^n ...
#
# int deg; // degree of polynomial (0 for the zero polynomial)
#
# //define public member functions
# public:
# Polynomial::Polynomial() //default constructor
# {
# for ( int i = 0; i < 100; i++ )
# {
# coef[i] = 0;
# }
# }
# void set ( int a , int b ) //setter function
# {
# //coef = new Polynomial[b+1];
# coef[b] = a;
# deg = degree();
# }
#
# int degree()
# {
# int d = 0;
# for ( int i = 0; i < 100; i++ )
# if ( coef[i] != 0 ) d = i;
# return d;
# }
#
# void print()
# {
# for ( int i = 99; i >= 0; i-- ) {
# if ( coef[i] != 0 ) {
# cout << coef[i] << "x^" << i << " ";
# }
# }
# }
#
# // use Horner's method to compute and return the polynomial evaluated at x
# int evaluate ( int x )
# {
# int p = 0;
# for ( int i = deg; i >= 0; i-- )
# p = coef[i] + ( x * p );
# return p;
# }
#
# // differentiate this polynomial and return it
# Polynomial differentiate()
# {
# if ( deg == 0 ) {
# Polynomial t;
# t.set ( 0, 0 );
# return t;
# }
# Polynomial deriv;// = new Polynomial ( 0, deg - 1 );
# deriv.deg = deg - 1;
# for ( int i = 0; i < deg; i++ )
# deriv.coef[i] = ( i + 1 ) * coef[i + 1];
# return deriv;
# }
#
# Polynomial plus ( Polynomial b )
# {
# Polynomial a = *this; //a is the poly on the L.H.S
# Polynomial c;
#
# for ( int i = 0; i <= a.deg; i++ ) c.coef[i] += a.coef[i];
# for ( int i = 0; i <= b.deg; i++ ) c.coef[i] += b.coef[i];
# c.deg = c.degree();
#
# return c;
# }
#
# Polynomial minus ( Polynomial b )
# {
# Polynomial a = *this; //a is the poly on the L.H.S
# Polynomial c;
#
# for ( int i = 0; i <= a.deg; i++ ) c.coef[i] += a.coef[i];
# for ( int i = 0; i <= b.deg; i++ ) c.coef[i] -= b.coef[i];
# c.deg = c.degree();
#
# return c;
# }
#
# Polynomial times ( Polynomial b )
# {
# Polynomial a = *this; //a is the poly on the L.H.S
# Polynomial c;
#
# for ( int i = 0; i <= a.deg; i++ )
# for ( int j = 0; j <= b.deg; j++ )
# c.coef[i+j] += ( a.coef[i] * b.coef[j] );
# c.deg = c.degree();
# return c;
# }
# };
#
# int main()
# {
# Polynomial a, b, c, d;
# a.set ( 7, 4 ); //7x^4
# a.set ( 1, 2 ); //x^2
#
# b.set ( 6, 3 ); //6x^3
# b.set ( -3, 2 ); //-3x^2
#
# c = a.minus ( b ); // (7x^4 + x^2) - (6x^3 - 3x^2)
#
# c.print();
#
# cout << "\n";
#
# c = a.times ( b ); // (7x^4 + x^2) * (6x^3 - 3x^2)
# c.print();
#
# cout << "\n";
#
# d = c.differentiate().differentiate();
# d.print();
#
# cout << "\n";
#
# cout << c.evaluate ( 2 ); //substitue x with 2
#
# cin.get();
# }
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
plz.....plz solve out my problem.... kethireddy435 ASP.NET 1.x and 2.0 Application Design 1 October 4th, 2007 12:56 PM
plz solve my problem mkazim85 SQL Language 2 May 14th, 2007 05:31 AM
Hi,plz solve my problem SachinMalge ASP.NET 1.0 and 1.1 Professional 1 December 26th, 2006 06:39 AM
Solve my prob? plz.......... mkmaurya_it General .NET 0 February 12th, 2005 03:50 AM
plz help me solve this error moushumi Classic ASP Databases 1 March 31st, 2004 10:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.