Question

In: Computer Science

provide a C code (only C please) that gives the output below: ************************************ *         Menu HW...

provide a C code (only C please) that gives the output below:

************************************
*         Menu HW #4 *
* POLYNOMIAL OPERATIONS *
* 1. Creating polynomials *
* 2. Adding polynomials *
* 3. Multiplying polynomials. *
* 4. Displaying polynomials *
* 5. Clearing polynomials. *
* 6. Quit. *

***********************************

Select the option (1 through 6): 7

You should not be in this class!

*************************************
*         Menu HW #4 *
* POLYNOMIAL OPERATIONS *
* 1. Creating polynomials *
* 2. Adding polynomials *
* 3. Multiplying polynomials *
* 4. Displaying polynomials.   *
* 5. Clearing polynomials *
* 6. Quit *

***********************************

Select the option (1 through 6): 4

Left Poly Pointer: 0

Right Poly Pointer: 0

Resulting Poly Pointer: 0

*************************************
*         Menu HW #4 *
* POLYNOMIAL OPERATIONS *
* 1. Creating polynomials *
* 2. Adding polynomials *
* 3. Multiplying polynomials *
* 4. Displaying polynomials. *
* 5. Clearing polynomials *
* 6. Quit *

***********************************

Select the option (1 through 6): 1

/* Performing the required task(s) and your code must ALSO print

1. Description/explanation of the method or approach that you

use to create 2 polynomials; and
2. The listing of all functions involved in the process.

*/

*************************************
*         Menu HW #4 *
* POLYNOMIAL OPERATIONS *
* 1. Creating polynomials *
* 2. Adding polynomials *
* 3. Multiplying polynomials *
* 4. Displaying polynomials. *
* 5. Clearing polynomials *
* 6. Quit *

***********************************

Select the option (1 through 6): 4

Left Poly Pointer: SOME NONE ZERO ADDRESS and DISPLAYING Poly 1/1x2 + 3/4x + 5/12

Right Poly Pointer: SOME NONE ZERO ADDRESS and DISPLAYING Poly 1/1x4 – 3/7x2 + 4/9x + 2/11

Resulting Poly Pointer: 0

*************************************
*         Menu HW #4 *
* POLYNOMIAL OPERATIONS *
* 1. Creating polynomials *
* 2. Adding polynomials *
* 3. Multiplying polynomials *
* 4. Displaying polynomials. *
* 5. Clearing polynomials *
* 6. Quit *

***********************************

Select the option (1 through 6): 2

/* Performing the required task(s) and your code must ALSO print

1. Description/explanation of the method or approach that you

use to add 2 polynomials; and
2. The listing of all functions involved in the process.

*/

*************************************
*         Menu HW #4 *
* POLYNOMIAL OPERATIONS *
* 1. Creating polynomials *
* 2. Adding polynomials *
* 3. Multiplying polynomials *
* 4. Displaying polynomials. *
* 5. Clearing polynomials *
* 6. Quit *

***********************************

***********************************

Select the option (1 through 6): 4

Left Poly Pointer: SOME NONE ZERO ADDRESS and DISPLAYING Poly 1/1x2 + 3/4x + 5/12

Right Poly Pointer: SOME NONE ZERO ADDRESS and DISPLAYING Poly 1/1x4 – 3/7x2 + 4/9x + 2/11

Resulting Poly Pointer: SOME NONE ZERO ADDRESS and DISPLAYING Poly 1/1x4 – 3/7x2 + 43/36x + 79/132

*************************************
*         Menu HW #4 *
* POLYNOMIAL OPERATIONS *
* 1. Creating polynomials *
* 2. Adding polynomials *
* 3. Multiplying polynomials *
* 4. Displaying polynomials. *
* 5. Clearing polynomials *
* 6. Quit *

***********************************

Select the option (1 through 6): 3

/* Performing the required task(s) and your code must ALSO print

1. Description/explanation of the method or approach that you

use to multiply 2 polynomials; and
2. The listing of all functions involved in the process.

*/

*************************************
*         Menu HW #4 *
* POLYNOMIAL OPERATIONS *
* 1. Creating polynomials *
* 2. Adding polynomials *
* 3. Multiplying polynomials *
* 4. Displaying polynomials. *
* 5. Clearing polynomials *
* 6. Quit *

***********************************

Select the option (1 through 6): 4

Left Poly Pointer: SOME NONE ZERO ADDRESS and DISPLAYING Poly 1/1x2 + 3/4x + 5/12

Right Poly Pointer: SOME NONE ZERO ADDRESS and DISPLAYING Poly 1/1x4 – 3/7x2 + 4/9x + 2/11

Resulting Poly Pointer: SOME NONE ZERO ADDRESS and DISPLAYING Poly 1/1x6 + 3/4x5 – 1/84x4 + 31/252x3 + 871/924x2 + 191/594x + 5/66

*************************************
*         Menu HW #4 *
* POLYNOMIAL OPERATIONS *
* 1. Creating polynomials *
* 2. Adding polynomials *
* 3. Multiplying polynomials *
* 4. Displaying polynomials. *
* 5. Clearing polynomials *
* 6. Quit *

***********************************

Select the option (1 through 6): 5

/* Releasing selected polynomial(s)
For example, clearing and releasing left polynomial

*/

*************************************
*         Menu HW #4 *
* POLYNOMIAL OPERATIONS *
* 1. Creating polynomials *
* 2. Adding polynomials *
* 3. Multiplying polynomials *
* 4. Displaying polynomials. *
* 5. Clearing polynomials *
* 6. Quit *

***********************************

Select the option (1 through 6): 4

Left Poly Pointer: 0
Right Poly Pointer: SOME NONE ZERO ADDRESS and DISPLAYING Poly

1/1x4 – 3/7x2 + 4/9x + 2/11

Resulting Poly Pointer: 0

*************************************
*         Menu HW #4 *
* POLYNOMIAL OPERATIONS *
* 1. Creating polynomials *
* 2. Adding polynomials *
* 3. Multiplying polynomials *
* 4. Displaying polynomials. *
* 5. Clearing polynomials *
* 6. Quit *

***********************************

Select the option (1 through 6): 5

/* Releasing selected polynomial(s)
For example, clearing and releasing right polynomial

*/

*************************************
*         Menu HW #4 *
* POLYNOMIAL OPERATIONS *
* 1. Creating polynomials *
* 2. Adding polynomials *
* 3. Multiplying polynomials *
* 4. Displaying polynomials. *
* 5. Clearing polynomials *
* 6. Quit *

***********************************

Select the option (1 through 6): 4

Left Poly Pointer: 0

Right Poly Pointer: 0

Resulting Poly Pointer: 0

*************************************
*         Menu HW #4 *
* POLYNOMIAL OPERATIONS *
* 1. Creating polynomials *
* 2. Adding polynomials *
* 3. Multiplying polynomials *
* 4. Displaying polynomials. *
* 5. Clearing polynomials *
* 6. Quit *

***********************************

Select the option (1 through 6): 6

Polynomials -- Having Fun!

Solutions

Expert Solution

#include <alloc.h>

struct polynode
{

float coeff ;
int exp ;
struct polynode *link ;

} ;

void poly_add ( struct polynode **, float, int ) ;
void display_poly ( struct polynode * ) ;
void multiply ( struct polynode *, struct polynode *, struct polynode ** ) ;
void padd ( float, int, struct polynode ** ) ;

void main( )
{
struct polynode *first, *second, *mult ;
int i = 1 ;

char ch;
scanf("%c",ch)

   switch(ch) {
      case 'A' :
         poly_add ( &first, 3, 5 ) ;
         poly_add ( &first, 2, 4 ) ;
         poly_add ( &first, 1, 2 ) ;
         printf("creating and adding polynomials" );
         break;
      case 'B' : //adding
           poly_add ( &second, 1, 6 ) ;
           poly_add ( &second, 2, 5 ) ;
           poly_add ( &second, 3, 4 ) ;
           break;
      case 'C' : //multiplying
         multiply ( first, second, &mult ) ;
         break;
      case 'D' : //display
            

display_poly ( first ) ;

display_poly ( second ) ;

         
         break;
     
      default :
         printf("wrong" );
   }
   

first = second = mult = NULL ; /* empty linked lists */

poly_add ( &first, 3, 5 ) ;
poly_add ( &first, 2, 4 ) ;
poly_add ( &first, 1, 2 ) ;

clrscr( ) ;
display_poly ( first ) ;

poly_add ( &second, 1, 6 ) ;
poly_add ( &second, 2, 5 ) ;
poly_add ( &second, 3, 4 ) ;

printf ( "\n\n" ) ;
display_poly ( second ) ;

printf ( "\n" );
while ( i++ < 79 )
printf ( "-" ) ;

multiply ( first, second, &mult ) ;

printf ( "\n\n" ) ;
display_poly ( mult ) ;
}

/* adding a term to a polynomial */
void poly_add ( struct polynode **q, float x, int y )
{
struct polynode *temp ;
temp = *q ;

/* create a new node if the list is empty */
if ( *q == NULL )
{
*q = malloc ( sizeof ( struct polynode ) ) ;
temp = *q ;
}
else
{
/* traverse the entire linked list */
while ( temp -> link != NULL )
temp = temp -> link ;

/* create new nodes at intermediate stages */

temp -> link = malloc ( sizeof ( struct polynode ) ) ;
temp = temp -> link ;
}

/* assign coefficient and exponent */

temp -> coeff = x ;
temp -> exp = y ;
temp -> link = NULL ;
}

/* displays the contents of linked list representing a polynomial */
void display_poly ( struct polynode *q )
{
/* traverse till the end of the linked list */
while ( q != NULL )
{
printf ( "%.1f x^%d : ", q -> coeff, q -> exp ) ;
q = q -> link ;
}

printf ( "\b\b\b " ) ; /* erases the last colon(:) */

}

/* multiplies the two polynomials */
void multiply ( struct polynode *x, struct polynode *y,
struct polynode **m )
{
struct polynode *y1 ;
float coeff1, exp1 ;

y1 = y ; /* point to the starting of the second linked list */
if ( x == NULL && y == NULL )
return ;

/* if one of the list is empty */
if ( x == NULL )
*m = y ;
else
{
if ( y == NULL )
*m = x ;
else/* if both linked lists exist */

{
/* for each term of the first list */
while ( x != NULL )
{
/* multiply each term of the second linked list with a
term of the first linked list */
while ( y != NULL )
{
coeff1 = x -> coeff * y -> coeff ;
exp1 = x -> exp + y -> exp ;
y = y -> link ;

/* add the new term to the resultant polynomial */

padd ( coeff1, exp1, m ) ;
}

y = y1 ; /* reposition the pointer to the starting of
the second linked list */

x = x -> link ; /* go to the next node */

}
}
}
}

/* adding a term to the polynomial in the descending order of the exponent */
void padd ( float c, int e, struct polynode **s )
{
struct polynode *r, *temp = *s ;

/* if list is empty or if the node is to be inserted before the first node */
if ( *s == NULL || e > ( *s ) -> exp )
{
*s = r = malloc ( sizeof ( struct polynode ) ) ;
( *s ) -> coeff = c ;
( *s ) -> exp = e ;
( *s ) -> link = temp ;
}
else
{
while ( temp != NULL )
{
if ( temp -> exp == e )
{
temp -> coeff += c ;
return ;
}

if ( temp -> exp > e && ( temp -> link -> exp < e || temp -> link == NULL ) )
{
r = malloc ( sizeof ( struct polynode ) ) ;
r -> coeff = c;
r -> exp = e ;
r -> link = temp -> link ;
temp -> link = r ;
return ;
}

temp = temp -> link ; /* go to next node */

}

r -> link = NULL ;
temp -> link = r ;
}
}


Related Solutions

LANGUAGE: C Only using <stdio.h> & <stdlib.h> Write a program that gives the user a menu...
LANGUAGE: C Only using <stdio.h> & <stdlib.h> Write a program that gives the user a menu to choose from – 1. Convert temperature input from the user in degrees Fahrenheit to degrees Celsius 2. Convert temperature input from the user in degrees Celsius to degrees Fahrenheit 3. Quit. Formulae you will need: C = (5 / 9) * (F-32) and F = (9/5) * C + 32 1. Use functions to accomplish 1 and 2 above. 2. Use at least...
C++ program. Please explain how the code resulted in the output. The code and output is...
C++ program. Please explain how the code resulted in the output. The code and output is listed below. Code: #include <iostream> #include <string> using namespace std; int f(int& a, int b) {    int tmp = a;    a = b;    if (tmp == 0) { cout << tmp << ' ' << a << ' ' << b << endl; }    b = tmp;    return b;    return a; } int main() {    int a...
Please do this in C++ only. Please Show your code and your output too. Would you...
Please do this in C++ only. Please Show your code and your output too. Would you focus on number 2 in the Required functions:? Please use all the variables in the program. The assignment problem: You are asked to develop an application that prints a bank’s customers' names, IDs, and accounts balances in different ways. In this program, you need to read a file of customer’s data into different arrays, pass these arrays to functions as (array parameter), calculate the...
please submit the C code( no third party library). the C code will create output to...
please submit the C code( no third party library). the C code will create output to a file, and iterate in a loop 60 times and each iteration is 1 second, and if any key from your keyboard is pressed will write a 1 in the file, for every second no key is pressed, will write a 0 into the output file.
PROVIDE CODE ONLY IN C++ / NO OTHER LANGUAGES PLEASE ADD SELECTION SORT/ INSERTION SORT/ AND...
PROVIDE CODE ONLY IN C++ / NO OTHER LANGUAGES PLEASE ADD SELECTION SORT/ INSERTION SORT/ AND BUBBLE SORT FUNCTION TO THIS PROGRAM #include <iostream> #include<vector> #include <algorithm >   #include <chrono>    #include <ctime> using namespace std; void bubblesSort() { // Please create Bubble Sort function// Make another for Selection Sort and  Insertion Sort } int main() { // empty vector vector<int> data; // data [0], data [1]... data[N-1] <-- end(data) // set of values to test N for (auto N :...
pleade provide the output and a brief explanation of the following C++ code: double dec1 =...
pleade provide the output and a brief explanation of the following C++ code: double dec1 = 2.5; double dec1 = 3.8; double *p, *q; p = &dec1; *p = dec2 - dec1; q = p; *q = 10.0; *p = 2 * dec1 + (*q); q =&dec2; dec1 = *p + *q; cout<<dec1<<" "<<dec2<< endl; cout<<*p<<" "<<*q<< endl; The following code should output the radius of th ebase, height , volume, and surface area of a cylinder. However, it fails...
C#: If the code is the only thing that you can provide without the pictures of...
C#: If the code is the only thing that you can provide without the pictures of the form, then that is fine as well. Topics: hiding/showing controls, StatusStrip, custom event arguments, radio buttons Students will create an application that uses a dialog to create a spaceship object to populate a ListView. This ListView will be able to display in either large or small icon mode using a menu option to switch between them. Selecting a spaceship in the ListView will...
Using SAS is preferred but not required. Please provide SAS code and the relevant output if...
Using SAS is preferred but not required. Please provide SAS code and the relevant output if SAS is used. •             Link to referenced FEV.CSV: https://drive.google.com/open?id=1t1CRIbnTE7xL_OE9Bmajb564RXcg8nDo For all hypothesis testing problems: •             state the null and alternative hypotheses, •             calculate the value of the test statistic, •             determine if the results are statistically significant (using rejection region or p-value approaches), •             then state your conclusion in terms of the problem. 1.            FEV (forced expiratory volume) is an index of pulmonary function...
java code Write a program that gives the user a menu of six choices (use integers)...
java code Write a program that gives the user a menu of six choices (use integers) to select from. The choices are circle, triangle, cone, cylinder, sphere, and quit. (The formulas are given below.) Once the figure is calculated, an informative message should be printed and the user shown the menu again, so that another choice can be made. The formulas are: Area of circle: a = 3.14 * radius * radius Area of triangle: a = ½ base *...
Can someone please provide C# code in Events,Delegates and Reflection for the below problem. ----------------- Agent-Policy...
Can someone please provide C# code in Events,Delegates and Reflection for the below problem. ----------------- Agent-Policy XYZ Assurance wants to categorize the policies based on the agent who sold the policy and the Insurance type. Given an Agent name, display the policies that were sold by that agent. Similarly, print the policies in the given Insurance type. Write a program to do the same. They have a list of few policies and want to update the list with a few...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT