Please help me to fix this code. (Do not use from another answer) this is C++ #include using namespace std; /

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Please help me to fix this code. (Do not use from another answer) this is C++ #include using namespace std; /

Post by answerhappygod »

Please help me to fix this code. (Do not use from
another answer) this is C++
#include <iostream>
using namespace std;
// Class
class poly
{
private:
struct node{
float coef;
int exp;
struct node *next;
} * start;
public:
void Menu();
poly(){
start = NULL;
}
void insert(float c, int e){
node* temp = start;
if(temp == NULL){
temp = new node;
start = temp;
}else {
while(temp->next != NULL)
temp = temp->next;
temp->next = new node;
temp = temp->next;
}
temp->coef = c;
temp->exp = e;
temp->next = NULL;
}
void show(){
node* temp = start;
int f = 0;
cout << endl;
while (temp != NULL) { if (f != 0) { if (temp->coef >
0)
cout << " + ";
else
cout << " "; } if (temp->exp != 0)
cout << temp->coef << "x^" <<
temp->exp;
else
cout << temp->coef;
temp = temp->next;
f = 1;
}
}
void add(poly& n1, poly& n2){
struct node* z;
if(n1.start == NULL && n2.start == NULL){
return;
}
struct node *temp1, *temp2;
temp1 = n1.start;
temp2 = n2.start;
while(temp1 != NULL && temp2 != NULL){
if(start == NULL){
start = new node;
z = start;
}else {
z->next = new node;
z = z->next;
}
if(temp1->exp < temp2->exp){
z->coef = temp2->coef;
z->exp = temp2->exp;
temp2 = temp2->next;
}else {
if(temp1->exp == temp2->exp){
z->coef = temp1->coef + temp2->coef;
z->exp = temp1->exp;
temp1 = temp1->next;
temp2 = temp2->next;
}
}
}
while(temp1 != NULL){
if(start == NULL){
start = new node;
z = start;
}else {
z->next = new node;
z = z->next;
}
z->coef = temp1->coef;
z->exp = temp1->exp;
temp1 = temp1->next;
}
while(temp2 != NULL){
if(start == NULL){
start = new node;
z = start;
}else {
z->next = new node;
z = z->next;
}
z->coef = temp2->coef;
z->exp = temp2->exp;
temp2 = temp2->next;
}
z->next = NULL;
}
};
int main(){
poly p1;
p1.insert(2.5, 8);
p1.insert(-3.2, 5);
p1.insert(6.7, 0);
p1.insert(2.5, 3);
p1.show();
}
Please Help Me To Fix This Code Do Not Use From Another Answer This Is C Include Iostream Using Namespace Std 1
Please Help Me To Fix This Code Do Not Use From Another Answer This Is C Include Iostream Using Namespace Std 1 (203.57 KiB) Viewed 59 times
Please Help Me To Fix This Code Do Not Use From Another Answer This Is C Include Iostream Using Namespace Std 2
Please Help Me To Fix This Code Do Not Use From Another Answer This Is C Include Iostream Using Namespace Std 2 (88.72 KiB) Viewed 59 times
Please Help Me To Fix This Code Do Not Use From Another Answer This Is C Include Iostream Using Namespace Std 3
Please Help Me To Fix This Code Do Not Use From Another Answer This Is C Include Iostream Using Namespace Std 3 (20 KiB) Viewed 59 times
Please Help Me To Fix This Code Do Not Use From Another Answer This Is C Include Iostream Using Namespace Std 4
Please Help Me To Fix This Code Do Not Use From Another Answer This Is C Include Iostream Using Namespace Std 4 (78.07 KiB) Viewed 59 times
Please fix this code. I just need only the code. ( if
not the code do not do it)
TITLE REPRESENTING POLYNOMIAL FUNCTIONS WITH LINKED LISTS INTRODUCTION A keyed list is an ordered list in which each item consists of two parts: a key value that determines the item's position in the list, and other data associated with and identified by the key. A polynomial function f(x) is a function of one variable x of the form f(x) = Czien + Cr-1xºn–1 + Cr-2.7°n=2 + ... +,xe, where the ci(the coefficients) are real numbers and the e; (the exponents) are distinct non-negative integers. Multiplying a polynomial by a constant multiplies all the polynomial's coefficients by the constant. Adding two polynomials adds terms with identical exponents. Consider one term cr® of a polynomial function. The derivative of this term is cexe-1, if e> 0; and 0, ife= 0 (that is, if the term is constant). The derivative f'(x) of a polynomial function f (x) is the sum of the derivatives of its terms. Note that the derivative of a polynomial function is itself a polynomial function. A polynomial function can be represented by an ordered linked list each of whose nodes represents one term of the function. Each node holds two data items: a real number (a coefficient) and an integer (an exponent). The exponents act as keys in such a list; the nodes representing terms are maintained in order of increasing exponents. For example, the following linked list represents the polynomial f(x) = 5.5 + 2.7*- 6.2*x3. +3.5*76 first 5.50 - 2.7) 2 - -6.2 3 3.56 DESCRIPTION Design, implement, document, and test a polynomial function class that represents a polynomial as a keyed linked list and an interactive, menu-driven program that exercises and tests this class, in the style of the previous project. The class must provide the following operations. • A default constructor. The default value of a polynomial is 0.0. • A copy constructor. • A destructor, since the lists that represent polynomials are dynamic objects. • A function that inserts a new term into a polynomial. If the polynomial already contains a term with the same exponent, the new term is added to the existing one. • A function that assigns one polynomial to another. Overload the assignment operator '='to name this function. • A function that returns the sum of two polynomials. Overload the '+' operator to name this function. The sum is returned as the function's value. • Functions that return the product of a polynomial and a real constant. Overload the '*' operator to name these functions, and note that there must be two of them: one in which the constant is the first parameter of the multiplication---- * f(x)---and a second in which the polynomial is the first parameter---f(x) * c. (HINT: One of these will not be a member function of the class.) • A function that returns the derivative of the polynomial that invokes it. Note that this function creates and returns a new polynomial. • A function that prints a polynomial to an output stream. The program that exercises this class is menu-driven and interactive. It must manipulate at least three polynomials and provide commands that invoke all the operations listed above. It reads in sequences of real and integer pairs that specify the terms of polynomials. The program calls the insert() function to build a polynomial corresponding to such input.
This program responds to commands the user enters to manipulate 3 polynomial functions. The functions are all initially 0.0. In the following commands, v is a double value, and n, ni, n2, and n3 indicate polynomials; they may only be integers from 0 to 2. rn Read in the terms of polynomial n. in Reinitialize polynomial n to o. c n1 n2 -- Assign polynomial ni to polynomial n2. gn Report the degree of polynomial n. a ni n2 n3 -- Add polynomials ni and n2 and put their sum in polynomial n3. m v n1 n2 - (polynomial n2) <- v * (polynomial n1) p nl v n2 (polynomial n2) <- (polynomial n1) * v d ni n2 -- Put the derivative of polynomial ni in polynomial n2 Write out polynomial n. h See this menu. q Quit the program. wn -- --> r 0 Enter pairs of coefficients and exponents. ==> 2.5 8 -3.2 5 6.70 2.5 3 -->WO Polynomial 0: 6.7 + 2.5*x^3 3.2*x^5 + 2.5*x^8 -->go Polynomial o has degree 8 --> r 1 Enter pairs of coefficients and exponents. ==> -5.1 34.0 18 2.4 8 --> W 1 Polynomial 1: -5.1*x^3 + 2.4*x^8 + 4*x^18 --> g 1 Polynomial 1 has degree 18 --> a 0 1 2 --> W 2 Polynomial 2: 6.7 2.6*x^3 3.2*x^5 + 4.9*x^8 + 4*x^18 --> m -2.0 1 0 --> WO -
Polynomial 0: 10.2*x^3 4.8*x^8 - 8*x^18 --> p 2 1.5 2 --> W 2 Polynomial 2: 10.05 - 3.9*x^3 - 4.8*x^5 + 7.35*x^8 + 6*x^18 --> d 2 1 --> W 1 Polynomial 1: -11.7*x^2 - 24*x^4 + 58.8*x^7 + 108*x^17 --> C 1 0 --> WO Polynomial 0: -11.7*x^2 - 24*x^4 + 58.8*x^7 + 108*x^17 --> 9
OTHER REQUIREMENTS Implement a polynomial function abstract data type in a class. This class will implement the ADT as a keyed, ordered linked list as described above. Functions that require repetition may be iterative or recursive, as you choose. The main program will use this class and the functions that it provides. In the main program, write a menu function that displays instructions and lists the program's commands. HINTS The key values in lists that represent polynomials are the exponents of the polynomial's terms, and here they ascend from the first node to the last in the list that represents a polynomial. A polynomial may consist of one or more terms, so an input line of coefficients and exponents may contain any number (greater than zero) of such pairs. You can use the iostream function peek() to stop reading at the end of such a line, in this way: do { cin >> coefficient >> exponent; < Do something with the coefficient and exponent here. > } while ( cin.peek() != '\n'); Consider using an array of functions/lists. Be sure to test inputs in which the exponents of a polynomial's terms are not in ascending order, and in which the same exponent appears more than once.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply