-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path48-polynomial_evaluate.cpp
More file actions
94 lines (90 loc) · 1.9 KB
/
Copy path48-polynomial_evaluate.cpp
File metadata and controls
94 lines (90 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include<iostream>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
struct node
{
float cf,px,py;
struct node *link;
};
class poly
{
public:
node* insertrear(float cf,float x,float y,node *first)
{
node *cur=new node;
node *temp=new node;
temp->cf=cf;
temp->px=x;
temp->py=y;
temp->link=NULL;
if(first==NULL)
{
first=temp;
return first;
}
cur=first;
while(cur->link!=NULL)
{
cur=cur->link;
}
cur->link=temp;
return first;
}
node* read_poly(node *head)
{
int i;
float px,py,cf;
cout<<"Enter the poly"<<endl;
for(i=1;;i++)
{
cout<<"coeff=";
cin>>cf;
if(cf==-999)
break;
cout<<"power of x=";
cin>>px;
cout<<"power of y=";
cin>>py;
head=insertrear(cf,px,py,head);
}
return head;
}
float evaluate(node *head)
{
float x,y,sum=0;
node *poly=new node;
poly=head;
cout<<"enter value of x and y\n";
cin>>x>>y;
for(poly=head;poly!=NULL;poly=poly->link)
sum+=poly->cf*pow(x,poly->px)*pow(y,poly->py);
return sum;
}
void display(node *head)
{
node *temp=new node;
if(head==NULL)
{
cout<<"empty";
return;
}
cout<<"coefficients and powers of all terms are:-"<<endl;
for(temp=head;temp!=NULL;temp=temp->link)
cout<<temp->cf<<temp->px<<temp->py<<endl;
}
};
int main()
{
node *head=NULL;
poly obj;
float res;
cout<<"enter the polynomial";
head=obj.read_poly(head);
res=obj.evaluate(head);
obj.display(head);
cout<<"result of polynomial="<<res;
return 0;
}