برنامه عملیات ریاضی رو چند جمله ای ها Polynomial
دوشنبه, ۱ دی ۱۳۹۹، ۰۱:۰۵ ق.ظ
شرح:
این برنامه شامل تابع سازنده و سربارگذاری عملگر های >> ، << ، + ، - ، * ، =، () و [] روی کلاس polynomial است. به علاوه یک تابع (analys) برای خواندن string و تبدیل آن به term ها دارد. هر چند جمله ای از چند شی از کلاس term تشکیل می شود.
کلاس polynomial:
شامل یک آرایه به طول 20 از کلاس term است. متغییر count شمارنده سلول های پرشده است(با پر شدن هر خانه(سلول) یک واحد به مقدار آن اضافه می شود)
class polynomial
{
private:
term cell[20];
int count;
//add similar value to each other
void clear();
//this function convert string math expersion to numbercial cell's value
void analys(string exp);
void insert(int fact,int pow);
protected:
int power(int num,int pow);
public:
//contractors
polynomial(){count=0;}; //Null
polynomial(string exp){count=0;analys(exp);}; //by Value
polynomial (polynomial &A){count=0;for(int i=0;i<20;i++){cell[i].fact=A.cell[i].fact;cell[i].pow=A.cell[i].pow;}} //by Copy
//function
void show();
void set(string exp);
//operator overloading
polynomial operator *(polynomial temp);
polynomial operator -(polynomial temp);
polynomial operator =(polynomial temp);
int operator ()(int input);
term operator [](int input);
friend ostream& operator << (ostream &out, polynomial temp);
friend istream& operator >> (istream &in, polynomial &temp);
};
کلاس term:
در یک چند جمله ای هر جمله مثلا به صورت 3x^2 یک term می باشد. در این مثال fact=3 و pow=2 است.
class term
{
friend class polynomial;
private:
int fact;
int pow;
public:
term(){ fact = 0; pow = 0; } //contractor (null)
term(int x,int y){fact = x; pow = y;} //contractor (value)
term (term &A){fact = A.fact; pow = A.pow;} //contractor (copy)
//function
void show();
//operator overloading
friend ostream& operator << (ostream &out, term t);
};
برای مشاهده برنامه کلیک کنید.
- ۰ نظر
- ۰۱ دی ۹۹ ، ۰۱:۰۵