(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
- Node A is connected to node B by a 2000km fiber link having a bandwidth of 100Mbps. What is the total latency time (transmit + propagation) required to transmit a 4000 byte file using packets that include 1000 Bytes of data plus 40 Bytes of header.arrow_forwardanswer should avoid using AI and should be basic and explain pleasearrow_forwardasnwer should avoid using AIarrow_forward
- answer should avoid using AI (such as ChatGPT), do not any answer directly copied from AI would and explain codearrow_forwardWrite a c++ program that will count from 1 to 10 by 1. The default output should be: 1, 2, 3, 4, 5, 6 , 7, 8, 9, 10 There should be only a newline after the last number. Each number except the last should be followed by a comma and a space. To make your program more functional, you should parse command line arguments and change behavior based on their values. Argument Parameter Action -f, --first yes, an integer Change place you start counting -l, --last yes, an integer Change place you end counting -s, --skip optional, an integer, 1 if not specified Change the amount you add to the counter each iteration -h, —help none Print a help message including these instructions. -j, --joke none Tell a number based joke. So, if your program is called counter, counter -f 10 --last 4 --skip 2 should produce 10, 8, 6, 4 Please use the last supplied argument. If your code is called counter, counter -f 4 -f 5 -f 6 should count from 6. You should…arrow_forwardshow workarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning