pushpa pushpa

pushpa pushpa

  • NA
  • 2
  • 494

hi...anyone can send the perfect algorith for this program

Nov 16 2016 6:10 AM

1. Polynomial Differentiation

#include”iostream.h”
#include”conio.h”
struct node
{
int coeff;
int pow;
struct node *next;
};

class polydiff
{
struct node *head;
struct node *i;
public:
void creation();
void display();
void differen();
polydiff();
};
polydiff::polydiff()
{
head=NULL;
}

void polydiff::creation()
{
char res;
struct node *temp;
head=new struct node();
cout<<"Enter the 1st term in the polynomial with coeff & Power";
cin>>head->coeff;
cin>>head->pow;
head->next=NULL;
cout<<"do u want to add another node\n";
cin>>res;
while(res=='y'res=='Y')
{
temp=new struct node();
cout<<"Enter coeff & power\n";
cin>>temp->coeff;
cin>>temp->pow;
temp->next=NULL;
for(i=head;i->next!=NULL;i=i->next);
i->next=temp;
cout<<"Interested in adding another node\n";
cin>>res;
}
}

void polydiff::display()
{
for(i=head;i!=NULL;i=i->next)
{
if(i->pow!=0)
{
cout<
coeff<<"X^";
cout<pow<<"+";
}
else
cout<coeff;
}
}

void polydiff::differen()
{
for(i=head;i!=NULL;i=i->next)
{
if(i->pow!=0)
{
i->coeff=i->coeff*i->pow;
i->pow--;
}
else
{
i->coeff=0;
i->pow=0;
}
}
}

void main()
{
clrscr();
polydiff p;
printf(“POLYNOMIAL DIFFERENTIATION\n”);
p.creation();
p.display();
cout<<"\n\nDifferentiation is\n";
p.differen();
p.display();
getch();
}



OUTPUT:


POLYNOMIAL DIFFERENTIATION

Enter the 1st term in the polynomial with coeff & Power
25 4
do u want to add another node
y
Enter coeff & power
12 3
Interested in adding another node
y
Enter coeff & power
1 1
Interested in adding another node
y
Enter coeff & power
10
0
Interested in adding another node
n
25X^4+12X^3+1X^1+10

Differentiation is
100X^3+36X^2+10


Answers (1)