C++ for Engineers and Scientists
C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
bartleby

Videos

Textbook Question
Book Icon
Chapter 3.4, Problem 7E

(General math) a. Write, compile, and run a C++ program to compute and display the value of the second-order polynomial a x 2   +   b x   +   c for any user-entered values of the coefficients a, b, c, and the variable x. Have your program display a message to inform users what the program does, and then display suitable prompts to alert users to enter the data. (Hint: Use a prompt such as Enter the coefficient of the x-squared term:.)

b. Check the result of your program written for Exercise 7a by using the following test data:

T e s t   d a t a   s e t   1 :   a   =   0 ,   b   =   0 ,   c   =   22 ,   x   =   56 T e s t   d a t a   s e t   2 :   a   =   0 ,   b   =   22 ,   c   =   0 ,   x   =   2 T e s t   d a t a   s e t   3 :   a   =   22 ,   b   =   0 ,   c   =   0 ,   x   =   2 T e s t   d a t a   s e t   4 :   a   =   2 ,   b   =   4 ,   c   =   5 ,   x   =   2

After finishing your verification, use your program to complete the following chartChapter 3.4, Problem 7E, (General math) a. Write, compile, and run a C++ program to compute and display the value of the

a.

Expert Solution
Check Mark
Program Plan Intro

Program plan:

  1. The variable a, b and c of type float is used to accept the coefficient of second order polynomial.
  2. The variable x of type float is used to accept the value of x of second order polynomial.
  3. 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.

Expert Solution
Check Mark
Program Plan Intro

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:

    abcxPolynomial Value
    2.017.0-12.01.3
    3.22.015.02.5
    3.22.015.0-2.5
    -2.010.00.02.0
    -2.010.00.04.0
    -2.010.00.05.0
    -2.010.00.06.0
    5.022.018.08.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.

    abcxPolynomial Value
    2.017.0-12.01.313.480
    3.22.015.02.540.000
    3.22.015.0-2.530.000
    -2.010.00.02.012.000
    -2.010.00.04.08.000
    -2.010.00.05.00.000
    -2.010.00.06.0-12.000
    5.022.018.08.3545.050
    4.2-16.0-20.0-5.2176.768

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
(Mathematical functions) a model of worldwide population, in billions of people, is given by this formula. Population = 6.0e0.02t Where t is the time in years (t=0 represents january 2000 and t = 1 represents january 2001). Using this formula, write a c++ program that displays a yearly population table for the years january 2005 through January 2010.
(C++ Programming) Question 1: Write a program which the user is asked to enter two integers. Then, the sum of these two integers and displayedon the screen. Question 2: Design a program using “For Loop” that will output the “seven” times table as follow:7 x 1 = 77 x 2 = 147 x 3 = 21:7 x 10 = 70
Problem 2. (Playing the Waltz) Write a program called playwaltz.py that accepts from standard input, a sequence of 32 integers representing the 32 measures of a waltz, and plays the waltz to standard audio. Before playing any audio, your program must check if the inputs are correct, and if they are not, must call sys.exit (message) to exit the program with an appropriate error message. The following errors must be handled: • If the number of measures is not 32, exit with the message "A waltz must contain exactly 32 measures". • If a minuet measure is not from [1,176], exit with the message "A minuet measure must be from [1, 176]". • If a trio measure is not from [1,96], exit with the message "A trio measure must be from [1, 96]". - "/vorkspace/project3 $ python3 generatewaltz.py < data/mozart.txt | python3 playwaltz. py Directions: • Read the waltz measures from standard input into a 1D list. • Handle the input errors described above. • Play each of the first 16 minuet measures by…

Chapter 3 Solutions

C++ for Engineers and Scientists

Ch. 3.1 - (Debug) Determine and correct the errors in the...Ch. 3.1 - Prob. 12ECh. 3.1 - Prob. 13ECh. 3.1 - (General math) The area of an ellipse (see Figure...Ch. 3.1 - Prob. 15ECh. 3.2 - Prob. 1ECh. 3.2 - Prob. 2ECh. 3.2 - (Practice) Write a C++ program that displays the...Ch. 3.2 - Prob. 4ECh. 3.2 - Prob. 5ECh. 3.2 - Prob. 6ECh. 3.2 - Prob. 7ECh. 3.2 - Prob. 8ECh. 3.2 - (Electrical eng.) The combined resistance of three...Ch. 3.2 - Prob. 10ECh. 3.2 - Prob. 11ECh. 3.2 - (Civil eng.) Write a C++ program to calculate and...Ch. 3.3 - Prob. 1ECh. 3.3 - Prob. 2ECh. 3.3 - (Practice) Write C++ statements for the following:...Ch. 3.3 - Prob. 4ECh. 3.3 - (General math) Write, compile, and run a C++...Ch. 3.3 - (General math) If a 20-foot ladder is placed on...Ch. 3.3 - (Physics) The maximum height reached by a ball...Ch. 3.3 - (Transportation) Road construction requires...Ch. 3.3 - Prob. 9ECh. 3.3 - Prob. 10ECh. 3.3 - Prob. 11ECh. 3.3 - Prob. 12ECh. 3.4 - Prob. 1ECh. 3.4 - (Practice) a. Write a C++ program that first...Ch. 3.4 - Prob. 3ECh. 3.4 - Prob. 4ECh. 3.4 - Prob. 5ECh. 3.4 - Prob. 6ECh. 3.4 - (General math) a. Write, compile, and run a C++...Ch. 3.4 - Prob. 8ECh. 3.4 - Prob. 9ECh. 3.4 - (Electrical eng.) For the series circuit shown in...Ch. 3.4 - Prob. 11ECh. 3.4 - Prob. 12ECh. 3.4 - Prob. 13ECh. 3.5 - Prob. 1ECh. 3.5 - Prob. 2ECh. 3.5 - Prob. 3ECh. 3.5 - Prob. 4ECh. 3.5 - Prob. 5ECh. 3.6 - Prob. 1ECh. 3.6 - (General math) The value of p can be approximated...Ch. 3.6 - Prob. 3ECh. 3.6 - (General math) The volume of oil stored in an...Ch. 3.6 - Prob. 5ECh. 3.6 - (General math) The perimeter, approximate surface...Ch. 3.6 - Prob. 7ECh. 3.6 - Prob. 8ECh. 3.6 - Prob. 9ECh. 3 - (General math) a. Write a C++ program to calculate...Ch. 3 - General math) a. Write a C++ program to calculate...Ch. 3 - (General math) Modify the program written for...Ch. 3 - (Biology) The number of bacteria, B, in a culture...Ch. 3 - Prob. 5PPCh. 3 - (Heat transfer) The formula developed in Exercise...Ch. 3 - Prob. 7PPCh. 3 - (Electrical eng.) a. The voltage gain of an...Ch. 3 - (Electrical eng.) a. Write, compile, and run a C++...Ch. 3 - (Electrical eng.) The amplification of electronic...Ch. 3 - (Acoustics) The loudness of a sound is measured in...Ch. 3 - (General math) a. A balance has the following...
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Boolean Algebra - Digital Logic and Logic Families - Industrial Electronics; Author: Ekeeda;https://www.youtube.com/watch?v=u7XnJos-_Hs;License: Standard YouTube License, CC-BY
Boolean Algebra 1 – The Laws of Boolean Algebra; Author: Computer Science;https://www.youtube.com/watch?v=EPJf4owqwdA;License: Standard Youtube License