PDA

مشاهده نسخه کامل : برنامه ضرب چند جمله ای در چند جمله ای



mostafa4875
16-12-14, 01:54
عرض سلام به مدیر و کاربران محترم و عزیز

نیاز فوری و شدید به پروژه ضرب چند جمله ای در چند جمله ای بصورت لیست پیوندی یکرطفه در سی پلاس پلاس داشتم

خیلی ممنون میشم راهنمایی و کمکم کنید

نیاز شدید به این پروژه دارم

keyone72
16-12-14, 17:18
عرض سلام به مدیر و کاربران محترم و عزیز

نیاز فوری و شدید به پروژه ضرب چند جمله ای در چند جمله ای بصورت لیست پیوندی یکرطفه در سی پلاس پلاس داشتم

خیلی ممنون میشم راهنمایی و کمکم کنید

نیاز شدید به این پروژه دارم

برا کی میخوای

ravegoat
16-12-14, 21:44
عرض سلام به مدیر و کاربران محترم و عزیز

نیاز فوری و شدید به پروژه ضرب چند جمله ای در چند جمله ای بصورت لیست پیوندی یکرطفه در سی پلاس پلاس داشتم

خیلی ممنون میشم راهنمایی و کمکم کنید

نیاز شدید به این پروژه دارم
با سلام!

دوست گرامی به شهر سخت افزار خوش آمدید.

می تونید به سورس های زیر مراجعه بفرمایید:
C++ Program to Multiply two polynomials using linked list | bugs of a debugger (Only the registered members can see the link)
C++ program to multiply two polynomials maintained as linked lists | electrofriends.com (Only the registered members can see the link)
Program to multiply 2 polynomial functions - C++ Programming Examples and Tutorials (Only the registered members can see the link)

موفق باشید
آرمین

mostafa4875
17-12-14, 14:08
ممنون از دوستان عزیز برای راهنمایی

تا پایان امروز وقت دارم چون فردا صبح استاد ایمیل ها و نگاه میکنه و اگر نفرستم ...

مدیر عزیز ravegoat (Only the registered members can see the link) لینک هایی که گذاشتین رو دیدم برای سی هستن و من به سی پلاس پلاس نیاز دام و حتی اجرا هم نمیشن

ممنون میشم کمک و راهنمایی ام کنید :11():

mostafa4875
17-12-14, 14:19
البته یه نمونه دارم که برای زبان سی هستش ولی نتونستم به c++ تبدیلش کنم دوستان آیا راهی هستش بشه تبدیلش کرد


#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct node
{
float coef;
int expo;
struct node *next;
};

struct node *create(struct node *);
struct node *insert_s(struct node *,float,int);
struct node *insert(struct node *,float,int);
void display(struct node *ptr);
void poly_add(struct node *,struct node *);
void poly_mult(struct node *,struct node *);
int main( )
{
struct node *start1=NULL,*start2=NULL;

printf("Enter polynomial 1 :\n");
start1=create(start1);

printf("Enter polynomial 2 :\n");
start2=create(start2);

printf("\nPolynomial 1 is : ");
display(start1);
printf("\nPolynomial 2 is : ");
display(start2);

poly_add(start1, start2);
poly_mult(start1, start2);
getch();
return 0;
}

struct node *create(struct node *start)
{
int i,n,exp;
float coeff;
printf("Enter the number of terms : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter coeficient for term %d : ",i);
scanf("%f",&coeff);
printf("Enter exponent for term %d : ",i);
scanf("%d",&exp);
start=insert_s(start,coeff,exp);
}
return start;
}
struct node *insert_s(struct node *start,float co,int ex)
{
struct node *ptr,*tmp;
tmp=(struct node *)malloc(sizeof(struct node));
tmp->coef=co;
tmp->expo=ex;
/*list empty or exp greater than first one */
if(start==NULL || ex > start->expo)
{
tmp->next=start;
start=tmp;
}
else
{
ptr=start;
while(ptr->next!=NULL && ptr->next->expo >= ex)
ptr=ptr->next;
tmp->next=ptr->next;
ptr->next=tmp;
}
return start;
}

struct node *insert(struct node *start,float co,int ex)
{
struct node *ptr,*tmp;
tmp=(struct node *)malloc(sizeof(struct node));
tmp->coef=co;
tmp->expo=ex;
/*If list is empty*/
if(start==NULL)
{
tmp->next=start;
start=tmp;
}
else /*Insert at the end of the list*/
{
ptr=start;
while(ptr->next!=NULL)
ptr=ptr->next;
tmp->next=ptr->next;
ptr->next=tmp;
}
return start;
}

void display(struct node *ptr)
{
if(ptr==NULL)
{
printf("\nZero polynomial\n");
return;
}
printf("\n");
while(ptr!=NULL)
{
printf("(%.1fx^%d)", ptr->coef,ptr->expo);
ptr=ptr->next;
if(ptr!=NULL)
printf(" + ");
else
printf("\n");
}
}
void poly_add(struct node *p1,struct node *p2)
{
struct node *start3;
start3=NULL;

while(p1!=NULL && p2!=NULL)
{
if(p1->expo > p2->expo)
{
start3=insert(start3,p1->coef,p1->expo);
p1=p1->next;
}
else if(p2->expo > p1->expo)
{
start3=insert(start3,p2->coef,p2->expo);
p2=p2->next;
}
else if(p1->expo==p2->expo)
{
start3=insert(start3,p1->coef+p2->coef,p1->expo);
p1=p1->next;
p2=p2->next;
}
}
/*if poly2 has finished and elements left in poly1*/
while(p1!=NULL)
{
start3=insert(start3,p1->coef,p1->expo);
p1=p1->next;
}
/*if poly1 has finished and elements left in poly2*/
while(p2!=NULL)
{
start3=insert(start3,p2->coef,p2->expo);
p2=p2->next;
}
printf("\nAdded polynomial is : ");
display(start3);
}

void poly_mult(struct node *p1, struct node *p2)
{
struct node *start3;
struct node *p2_beg = p2;
start3=NULL;
if(p1==NULL || p2==NULL)
{
printf("\nMultiplied polynomial is zero polynomial\n");
return;
}


while(p1!=NULL)
{
p2=p2_beg;
while(p2!=NULL)
{
start3=insert_s(start3,p1->coef*p2->coef,p1->expo+p2->expo);
p2=p2->next;
}
p1=p1->next;
}
printf("\nMultiplied polynomial is : ");
display(start3);
}