Question

How to make a program in c++ that has these 2 options in a menu :1....

How to make a program in c++ that has these 2 options in a menu :1. Add a coefficient and degree of variable x to a polynomial 2. Give a value to the variable x in the polynomial and receive the result. While using the program, if the user decides to choose option 1 again, the value entered will be added to the existing polynomial.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

#include <iostream>
#include<cmath>
using namespace std;

int main()
{
int ch=0,i=0,j,v,result=0;
int length{};
length=2;
int *array{ new int[length]{} }; //dynamic array that used to store coefficient and degrees.
  
while(ch!=2){
cout<<"1.Add a coefficient and degree of variable x to a polynomial"<<endl;
cout<<"2.Give a value to variable x and get the result."<<endl;
cin>>ch;
if(ch==1){
cout<<"Enter coefficient:"<<endl;//if ch is 1,read inouts from user and add them to array
cin>>array[i];
cout<<"Enter degree:"<<endl;
cin>>array[i+1];
i=i+2;
length=length+2;
}
else if(ch==2){//if ch is 2,read valur for x and compute polynomial value
cout<<"Enter value to variable x";
cin>>v;
for(j=0;j<=i-2;j+=2){
result+=(array[j]*pow(v,array[j+1]));//use the coefficient and degree values from array and compute result
}
cout<<"The result is :"<<result<<endl;
}
}
return 0;
}

Screenshots:
The screenshots are attached below for reference along with output.
Please let me know in comments in case of any help.
Please upvote if you are satisfied.
  


Add a comment
Know the answer?
Add Answer to:
How to make a program in c++ that has these 2 options in a menu :1....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How can I make a program in c++ that lets the user create a polynomial by...

    How can I make a program in c++ that lets the user create a polynomial by letting him add values when he chooses the option in a menu. Another option in the menu should be to print the polynomial in order. Meaning that (for example), if the first coefficient entered was 2x^2, but the second coefficient entered was 2x, the polynomial should be printed as "2x+2x^2",

  • Write a program that displays a menu on the screen. The menu will give the user...

    Write a program that displays a menu on the screen. The menu will give the user four options - enter two integers, enter two decimal numbers (#.#), enter one integer and one decimal number, or quit. The inputs should be labelled a, b, c, or d, and you should enter in the letter to choose the appropriate option. Once the user selects the option, two numbers will be read in from the user. The numbers will be added together and...

  • Write a menu driven program to demonstrate the use of array and switch. It must be...

    Write a menu driven program to demonstrate the use of array and switch. It must be written in C language . Here is the menu - Press 1 to add a number to the array. Press 2 to display the numbers entered in the array so far Press 3 to find the average of the numbers entered. Press 4 to exit. Option 1 - The user should be able to enter 20 numbers only. If all twenty numbers are entered...

  • Menu-driven programs will display the menu options to the user and then prompt them for a...

    Menu-driven programs will display the menu options to the user and then prompt them for a menu choice. This program will display the following menu in the following format: Calculator Options: Calculate the area of a circle Calculate the area of a rectangle Calculate the area of a triangle Calculate the area of a trapezoid Calculate the area of a sphere Exit Enter your choice (1-6) Once the user enters a choice for the menu, the program should use a...

  • Write a calculator that will give the user this menu options: 1)Add 2)Subtract 3)Multiply 4)Divide 5)Exit...

    Write a calculator that will give the user this menu options: 1)Add 2)Subtract 3)Multiply 4)Divide 5)Exit . Your program should continue asking until the user chooses 5. If user chooses to exit give a goodbye message. After the user selections options 1 - 4, prompt the user for two numbers. Perform the requested mathematical operation on those two numbers. Round the result to 1 decimal place. Please answer in python and make it simple. Please implement proper indentation, not just...

  • c++ A menu-driven program gives the user the option to find statistics about different baseball players....

    c++ A menu-driven program gives the user the option to find statistics about different baseball players. The program reads from a file and stores the data for ten baseball players, including player’s team, name of player, number of homeruns, batting average, and runs batted in. (You can make up your data, or get it online, for example: http://espn.go.com/mlb/statistics ) Write a program that declares a struct to store the data for a player. Declare an array of 10 components to...

  • Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve...

    Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve the following program. -Use Microsoft Visual C++ .NET 2010 Professional compiler using default compiler settings. -Use Microsoft Visio 2013 for developing your flowchart. -Adherence to the ANSI C++  required -Do not use <stdio.h> and <conio.h>. -Do not use any #define in your program. -No goto statements allowed. Upon execution of the program, the program displays a menu as shown below and the user is prompted to make a selection from the menu....

  • Write a C++ program that will display the following menu and work accordingly. A menu that...

    Write a C++ program that will display the following menu and work accordingly. A menu that will display the following choices and uses functions to carry out the calculations: 1. Call a function named classInfo() to ask the user the number of students and exams in a course. 2. Call a function getGrade() that will get the information from classInfo() and asks the user to enter the grades for each student. 3. Call a function courseGrade() to display the average...

  • // Group Names: // Date: // Program Description: //   Import required packages //--> //   Declare class...

    // Group Names: // Date: // Program Description: //   Import required packages //--> //   Declare class (SwitchDoLab) //--> {    //   Declare the main method    //-->    {        //   Declare Constant integers SUM = 1, FACTORIAL = 2, QUIT = 3.        //-->        //-->        //-->        //   Create an integer variable named choice to store user's option.        //-->        //   Create a Scanner object        //   Create...

  • Write a program in Python that will: Here are following requirements to completing Menu shapes: 1....

    Write a program in Python that will: Here are following requirements to completing Menu shapes: 1. Create a "MENU" with 4 - 5 options have the user click the option and thereafter ask the user to enter the amount of stars from 1 - 50. From there your "for loop" will create the shape. Menu options need to be: 1. Filled Triangle 2. filled Square 3. This can be any shape such as a Square, circle, a different angle of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT