#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    132
    Rep Power
    2

    Help obtaining input.


    Hi guys.
    I need some advice.

    I want to be able to obtain a polynom.
    a polynom has several monoms.

    Here's the Monom class:

    Code:
    #define VARIABLE 'x'
    
    
    class Monom
    {
    private:
    	Fraction coefficient;
    	long int exponent;
    public:
    	Monom();
    	Monom(const Fraction &coef, long int exp=0);
    	friend Monom operator+(const Monom &mon1, const Monom &mon2);
    	friend Monom operator-(const Monom &mon1, const Monom &mon2);
    	friend Monom operator*(const Monom &mon1, const Monom &mon2);
    	Monom& operator++();
    	const Monom operator++(int);
    	Monom& operator--();
    	const Monom operator--(int);
    	Monom& operator=(const Monom &mon);
    	bool operator==(const Monom &mon)const;
    	friend ostream& operator<<(ostream& os, const Monom &mon);
    	friend istream& operator>>(istream& is, Monom &mon);
    	friend class Polynom;
    };
    here's the input operator overload for Monom:

    Code:
    istream& operator>>(istream& is, Monom &mon)
    {
    	char variable, expoSign;
    	return is>>mon.coefficient>>variable>>expoSign>>mon.exponent;
    }
    polynom is a linked list of monoms.
    and I want to overload the input operator for it.
    so, I was thinking of doing something like:

    Code:
    istream& operator>>(istream& is, Poly& poly)
    {
    	string temp;
    	cin>>temp;
    	for (int i=0; /*some condition*/ ; i++)
    	{
    		/*breaking the temp string here to monoms somehow
    		 * and insert each one of them with poly.Insert() method
    		 */
    	}
    }
    but I'm not sure exactly how to do it.
    I can really use some guidance here.
    Thanks in advanced!

    edit**

    another important thing:
    a monom has the following format: nom/denom x ^ exponent
    Last edited by so.very.tired; April 15th, 2013 at 05:54 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    132
    Rep Power
    2
    OK, some other idea:

    Code:
    istream& operator>>(istream& is, Polynom& poly)
    {
    	do
    	{
    		Monom aMonom;
    		cin>>aMonom;
    		poly.Insert(aMonom);
    	}while (/*what should be here?*/);
    }
    ?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    132
    Rep Power
    2
    or better yet:
    Code:
    istream& operator>>(istream& is, Poly& poly)
    {
    	Monom aMonom;
    	while (cin>>aMonom)
    	{
    		poly.Insert(aMonom);
    	}
    	return is;
    }
    but how do I make it stop at ENTER?

IMN logo majestic logo threadwatch logo seochat tools logo