Professional Documents
Culture Documents
Assignment
Assignment
h>
#include<stdlib.h>
#include<math.h>
/// Calculate ploynomial Equation with One variable
///Using Doubly linked List
class list
{
protected:
struct node
{
int co;
int pow;
node *next;
node *prev;
};
public:
list();
~list();
bool emptylist();
void push(int co, int pow);
double add();
double multiply();
void display();
};
list::list()
{ listptr=NULL;
lastptr=NULL;
}
list::~list()
{
nodeptr p,q;
if(emptylist())
exit(0);
if(q->prev!=NULL)
cout<<" + ";
}
/// Add All
for(p=listptr; p!=NULL; p=p->next)
{
ans=ans+p->co*pow(x,p->pow);
}
return ans;
}
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
double list:: multiply()
{
int x;
double ans=1;
nodeptr p,q;
if(q->prev!=NULL)
cout<<" * ";
}
///////////////////////////////////////////////////////////////////
/// Multiply all
for(p=listptr; p!=NULL; p=p->next)
{
ans=ans*p->co*pow(x,p->pow);
}
return ans;
}
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
void list :: display()
{
int i=1;
nodeptr p;
}
}
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
void main()
{
list l;
char ch='0';
while(ch!='5')
{
cout<<"\n1 :: Enter a Value :: ";
cout<<"\n2 :: Add Entered Ploynomials:: ";
cout<<"\n3 :: Muiltply Entered Ploynomials :: ";
cout<<"\n4 :: Display Entered Ploynomials";
cout<<"\n5 :: Exit";
cout<<"\n\nEnter Your choice:: ";
cin>>ch;
switch(ch)
{
case '1':
{
int x,y;
cout<<"\n\nEnter Co-officient :: ";
cin>>x;
cout<<"\n Enter it's power :: ";
cin>>y;
l.push(x,y);
break;
}
case '2':
{
cout<<"\nAnswer :: "<<l.add()<<endl<<endl;
break;
}
case '3':
{
cout<<"\nAnswer :: "<< l.multiply()<<endl<<endl;
break;
}
case'4':
{
l.display(); break;
}
case'5':
{
ch='5';
break;
}
default:
{
cout<<"\n!!! Wrong choice !!!\n\n\n";
}
}}
}