(General math) a. Write, compile, and run a C++
b. Check the result of your program written for Exercise 7a by using the following test data:
After finishing your verification, use your program to complete the following chart
a.
Program plan:
- The variable a, b and c of type float is used to accept the coefficient of second order polynomial.
- The variable x of type float is used to accept the value of x of second order polynomial.
- The variable p of type float calculates the value of second order polynomial.
Program description:
The main purpose of the program is to accept the coefficient of x and value of x and then calculate and display the value of second order polynomial.
Explanation of Solution
Program
#include <iostream> #include <math.h> using namespace std; int main() { // declaration of variables float a, b, c; float x; float p; // Input values cout<<"Input values to calculate value of the second-order polynomial :: ax^2 + bx +c"; cout<<"\nEnter the coefficient of the x-squared term(a) :: "; cin>>a; cout<<"\nEnter the coefficient of the x term (b) :: "; cin>>b; cout<<"\nEnter the coefficient of the term (c) :: "; cin>>c; cout<<"\nEnter the value of x :: "; cin>>x; // Calculate value of the second-order polynomial p = a * x * x + b * x + c ; cout<<"\nThe value of the second-order polynomial is :: "<<p; return 0; }
Explanation:
In the above program a, b and c accepts the coefficient of x for second order polynomial. The variable x accepts the value of x and then second order polynomial is calculated and displayed.
Sample Output:
Enterthecoefficientofthex-squaredterm(a)::0
Enterthecoefficientofthexterm(b)::0
Enterthecoefficientoftheterm(c)::22
Enterthevalueofx::56
Thevalueofthesecond-orderpolynomialis::22
b.
To check the given program for the test values as follows:
Test data set 1: a = 0, b = 0, c = 22, x = 56
Test data set 2: a = 0, b = 22, c = 0, x = 2
Test data set 3: a = 22, b = 0, c = 0, x = 2
Test data set 4: a = 2, b = 4, c = 5, x = 2
To complete the following chart:
a | b | c | x | Polynomial Value |
2.0 | 17.0 | -12.0 | 1.3 | |
3.2 | 2.0 | 15.0 | 2.5 | |
3.2 | 2.0 | 15.0 | -2.5 | |
-2.0 | 10.0 | 0.0 | 2.0 | |
-2.0 | 10.0 | 0.0 | 4.0 | |
-2.0 | 10.0 | 0.0 | 5.0 | |
-2.0 | 10.0 | 0.0 | 6.0 | |
5.0 | 22.0 | 18.0 | 8.3 | |
4.2 | -16.0 | -20.0 | -5.2 |
Explanation of Solution
Given Program
#include <iostream> #include <math.h> using namespace std; int main() { // declaration of variables float a, b, c; float x; float p; // Input values cout<<"Input values to calculate value of the second-order polynomial :: ax^2 + bx +c"; cout<<"\nEnter the coefficient of the x-squared term(a) :: "; cin>>a; cout<<"\nEnter the coefficient of the x term (b) :: "; cin>>b; cout<<"\nEnter the coefficient of the term (c) :: "; cin>>c; cout<<"\nEnter the value of x :: "; cin>>x; // Calculate value of the second-order polynomial p = a * x * x + b * x + c ; cout<<"\nThe value of the second-order polynomial is :: "<<p; return 0; }
Explanation:
Test data set 1:
a = 0, b = 0, c = 22, x = 56
Sample Output:
Input values to calculate value of the second-order polynomial :: ax^2 + bx +c
Enterthecoefficientofthex-squaredterm(a)::0
Enterthecoefficientofthexterm(b)::0
Enterthecoefficientoftheterm(c)::22
Enterthevalueofx::56
Thevalueofthesecond-orderpolynomialis:: 22
Test data set 2:
a = 0, b = 22, c = 0, x = 2
Sample Output:
Input values to calculate value of the second-order polynomial :: ax^2 + bx +c
Enter the coefficient of the x-squared term(a) :: 0
Enter the coefficient of the x term (b) :: 22
Enter the coefficient of the term (c) :: 0
Enter the value of x :: 2
The value of the second-order polynomial is :: 44
Test data set 3:
a = 22, b = 0, c = 0, x = 2
Sample Output:
Input values to calculate value of the second-order polynomial :: ax^2 + bx +c
Enter the coefficient of the x-squared term(a) :: 22
Enter the coefficient of the x term (b) :: 0
Enter the coefficient of the term (c) :: 0
Enter the value of x :: 2
The value of the second-order polynomial is :: 88
Test data set 4:
a = 2, b = 4, c = 5, x = 2
Sample Output
Input values to calculate value of the second-order polynomial :: ax^2 + bx +c
Enter the coefficient of the x-squared term(a) :: 2
Enter the coefficient of the x term (b) :: 4
Enter the coefficient of the term (c) :: 5
Enter the value of x :: 2
The value of the second-order polynomial is :: 21
Chart
Following chart displays the polynomial value for different values of a, b, c and x.
a | b | c | x | Polynomial Value |
2.0 | 17.0 | -12.0 | 1.3 | 13.480 |
3.2 | 2.0 | 15.0 | 2.5 | 40.000 |
3.2 | 2.0 | 15.0 | -2.5 | 30.000 |
-2.0 | 10.0 | 0.0 | 2.0 | 12.000 |
-2.0 | 10.0 | 0.0 | 4.0 | 8.000 |
-2.0 | 10.0 | 0.0 | 5.0 | 0.000 |
-2.0 | 10.0 | 0.0 | 6.0 | -12.000 |
5.0 | 22.0 | 18.0 | 8.3 | 545.050 |
4.2 | -16.0 | -20.0 | -5.2 | 176.768 |
Want to see more full solutions like this?
Chapter 3 Solutions
C++ for Engineers and Scientists
- Pattern RecognitionPCA algorithmplease write the steps not only last answerarrow_forwardPlease original work Final Project: Part I Background Information: E-TechMart, established in 2005, has grown to become a leading global electronics retailer, renowned for its extensive range of electronic devices and accessories. With a robust online platform and numerous brick-and-mortar stores spread across various regions, E-TechMart serves millions of customers worldwide. The company's product offerings include the latest smartphones, laptops, tablets, smart home devices, and a variety of electronic accessories, catering to both individual consumers and businesses. E-TechMart has always prioritized customer satisfaction and aims to provide an exceptional shopping experience. This commitment is evident in their comprehensive customer service, competitive pricing, and a well-organized loyalty program that rewards repeat customers. Despite these strengths, E-TechMart faces increasing competition from other major players in the electronics retail market. To maintain its competitive…arrow_forwardCan you show me how to redesign the GameStop website using HTML and CSS using Sublime Text?arrow_forward
- Manhattan distancearrow_forwardAiwhat cost from Oradea to Goal which Eforie us A* Algorithm G(n)+H(n) last what ıs the costarrow_forwardWhat is the SELECT statement? give one reference with your answer What is a URL and what is it used for? give one reference with your answer What is e-mail, and what are its advantages? Give one reference with your answerarrow_forward
- What is the difference between the World Wide Web (WWW) and the Internet? Give two references from a journal along with your answer.arrow_forwardDiscuss with appropriate examples, the types of relationship in a database. Give two references from an article.arrow_forwardWhat is a cloud and why do we use it? Give one reference with your answer.arrow_forward
- What are triggers and how do you invoke a trigger on demand? give one reference with your anwer.arrow_forwardWhy is database normalization important? Give one reference with your answer.arrow_forwardDescribe the role of databases and database management systems in the context ofenterprise systems. Give two references with your answer.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education