Solution Manual for Engineering Problem Solving With C++, 4th Edition

Preview Extract
Exam Practice! 1. T 2. F 3. T 4. T 5. F 6. Not Correct. int i, j, k; 7. Correct. 8. Incorrect. double D1, D2, D3; 9. Correct. 10. Correct. 11. (d) 12. (b) 13. (a) 14. (c) 15. (e) Memory Snapshots 16. x1=>2, z=>2, x=>2 17. x=>2, y=>1, a=>3.8, n=>2 Output 18. value_1 = 5.78263 19. Missing ; (value_4 = 6.645832e+01) 20. value_5 = 7750 Programming Exercises /*——————————————————————–*/ /* Problem chapter2_21 */ /* */ /* This program converts miles to kilometers. */ #include using namespace std; int main() { /* Declare variables. */ double miles, kilometers; /* Enter number of miles from the keyboard. cout <> miles; */ /* Compute the number of kilometers equal to the specified miles. */ kilometers = 1.6093440*miles; /* Print the number of kilometers. */ cout << miles << " miles = " << kilometers << " kilometers n"; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_22 */ /* */ /* This program converts meters to miles. */ ยฉ2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved. #include using namespace std; int main() { /* Declare variables. double miles, meters; */ /* Enter number of meters from the keyboard. cout <> meters; */ /* Compute the number of miles equal to the specified meters. */ miles = meters/1609.3440; /* Print the number of miles. */ cout << meters << " meters = "<< miles << " miles n"; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_23 */ /* */ /* This program converts pounds to kilograms. */ #include using namespace std; int main() { /* Declare variables. */ double pounds, kilograms; /* Enter number of pounds from the keyboard. cout <> pounds; */ /* Compute number of kilograms equal to the specified pounds. kilograms = pounds/2.205; */ /* Print the number of kilograms. */ cout << pounds << " pounds = " << kilograms << " kilograms n"; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_24 */ /* */ /* This program converts newtons to pounds. */ #include ยฉ2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved. using namespace std; int main() { /* Declare variables. */ double pounds, newtons; /* Enter number of newtons from the keyboard. cout <> newtons; */ /* Compute number of pounds equal to the specified newtons. pounds = newtons/4.448; */ /* Print the number of pounds. */ cout << newtons << " newtons = " << pounds << " pounds n"; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_25 */ /* */ /* This program converts degrees Fahrenheit to degrees Rankin. */ #include using namespace std; int main() { /* Declare variables. */ double degrees_F, degrees_R; /* Enter temperture in degrees Fahrenheit from the keyboard. cout <> degrees_F; /* Compute the equivalent temperature in degrees Rankin /* from the given temperature. degrees_R = degrees_F + 459.67; */ */ */ /* Print the temperatures. */ cout << degrees_F << " degrees Fahrenheit = " << degrees_R << " degrees Rankin n"; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_26 */ /* */ /* This program converts degrees Celsius to degrees Rankin. */ #include ยฉ2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved. using namespace std; int main() { /* Declare variables. */ double degrees_C, degrees_F, degrees_R; /* Enter temperture in degrees Celsius from the keyboard. cout <> degrees_C; /* Compute the equivalent temperature in degrees Rankin /* from the given temperature. degrees_F = (9.0/5.0)*degrees_C + 32; degrees_R = degrees_F + 459.67; */ */ */ /* Print the temperatures. */ cout << degrees_C << " degrees Celsius = " << degrees_R << " degrees Rankin n"; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_27 */ /* */ /* This program converts degrees Kelvin to degrees Fahrenheit. */ #include using namespace std; int main() { /* Declare variables. */ double degrees_R, degrees_K, degrees_F; /* Enter temperture in degrees Kelvin from the keyboard. cout <> degrees_K; */ /* Compute the equivalent temperature in degrees Fahrenheit /* from the given temperature. degrees_R = (9.0/5.0)*degrees_K; degrees_F = degrees_R – 459.67; */ */ /* Print the temperatures. */ cout << degrees_K << " degrees Kelvin = " << degrees_F << " degrees Fahrenheit n"; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ ยฉ2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved. /* /* /* Problem chapter2_28 */ */ */ This program finds the area of a rectangle. #include using namespace std; int main() { /* Declare variables. double a, b, area; */ /* Enter the lengths of sides of the rectangle. */ cout <> a >> b; /* Compute the area of the rectangle. area = a*b; “; */ /* Print the value of the area. */ cout << "The area of a rectangle with sides " << a << " and " << b << " is " << area << endl; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_29 */ /* */ /* This program finds the area of a triangle. */ #include using namespace std; int main() { /* Declare variables. double h, b, area; */ /* Enter the base and the height of the triangle. */ cout <> b >> h; /* Compute the area of the triangle. area = 0.5*b*h; */ /* Print the value of the area. */ cout << "The area of a triangle with base " << b << " and height " << h << "is " << area << endl; /* Exit program. return 0; */ } /*——————————————————————–*/ ยฉ2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved. /*——————————————————————–*/ /* Problem chapter2_30 */ /* */ /* This program finds the area of a circle. */ #include using namespace std; const double PI = 3.141593; int main() { /* Declare variables. double r, area; */ /* Enter the radius. */ cout <> r; /* Compute the area of the circle. area = PI*r*r; */ /* Print the value of the area. */ cout << "The area of a circle with radius " << r << " is " << area << endl; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_31 */ /* */ /* This program computes the area of a sector of a circle when */ /* theta (u) is the angle in radians between the radii. */ #include using namespace std; int main() { /* Declare variables. double u, r, area; */ /* Enter the lengths of the radii and */ /* the angle between them. */ cout << "Enter the length of the radii and the angle " <> r >> u; /* Compute the area of the sector. area = (r*r*u)/2.0; */ /* Print the value of the area. */ cout << "The area of sector is " << area << endl; ยฉ2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved. /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_32 */ /* */ /* This program computes the area of a sector of a circle when */ /* the input (d) is the angle in degrees between the radii. */ #include using namespace std; const double PI = 3.141593; int main() { /* Declare variables. */ double d, r, area, theta; /* Enter the lengths of the radii and */ /* the angle between them. */ cout << "Enter the length of the radii and the angle " <> r >> d; /* Compute the value of the angle in radians. theta = d * PI / 180; /* Compute the area of the sector. area = (r*r*theta)/2.0; */ */ /* Print the value of the area. */ cout << "The area of sector is " << area << endl; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_33 */ /* */ /* This program computes the area of an */ /* ellipse with semiaxes a and b. */ #include using namespace std; const double PI = 3.141593; int main() { /* Declare variables. */ ยฉ2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved. double a, b, area; /* Enter the length of the semiaxes. */ cout <> a >> b; /* Compute the area of the ellipse. area = PI*a*b; */ /* Print the value of the area. */ cout << "The area of an ellipse with semiaxes " << a << " and " << b << " is " << area << endl; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_34 */ /* */ /* This program computes the area of the surface */ /* of a sphere of radius r. */ #include using namespace std; const double PI = 3.141593; int main() { /* Declare variables. double r, area; */ /* Enter the radius of the sphere. */ cout <> r; /* Compute the area of the sphere. area = 4.0*PI*r*r; */ /* Print the value of the area. */ cout << "The area of a sphere with radius " << r << " is " << area << endl; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_35 */ /* */ /* This program computes the volume */ /* of a sphere of radius r. */ #include ยฉ2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved. #include using namespace std; const double PI = 3.141593; int main() { /* Declare variables. double r, volume; */ /* Enter the radius of the sphere. */ cout <> r; /* Compute the volume of the sphere. volume = (4.0/3)*PI*pow(r,3); */ /* Print the value of the volume. */ cout << "The volume of a sphere with radius " << r << " is " << volume << endl; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_36 */ /* */ /* This program computes the volume of a cylinder */ /* of radius r and height h. */ #include using namespace std; const double PI = 3.141593; int main() { /* Declare variables. double r, h, volume; */ /* Enter the radius and height of the cylinder. */ cout <> r >> h; /* Compute the volume of the cylinder. volume = PI*r*r*h; */ /* Print the volume. */ cout << "The volume of a cylinder of radius " << r << " and " << "height " << h << " is " << volume << endl; /* Exit program. return 0; */ } /*——————————————————————–*/ ยฉ2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved. /*——————————————————————–*/ /* Problem chapter2_37 */ /* */ /* This program computes the molecular weight of the */ /* amino acid glycine. */ #include using namespace std; /* Defines symbolic constants for the appropriate atomic weights. const double OXYGEN = 15.9994; const double CARBON = 12.011; const double NITROGEN = 14.00674; const double HYDROGEN = 1.00794; */ int main() { /* Declare variables. */ double molecular_weight; /* Compute the molecular weight of glycine. molecular_weight = (2*OXYGEN) + (2*CARBON) + NITROGEN + (5*HYDROGEN); */ /* Print the molecular weight. */ cout << "The molecular weight of glycine is " << molecular_weight << endl; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_38 */ /* */ /* This program computes the molecular weights of the */ /* amino acids glutamic and glutamine. */ #include using namespace std; /* Defines symbolic constants for the appropriate atomic weights. const double OXYGEN = 15.9994; const double CARBON = 12.011; const double NITROGEN = 14.00674; const double HYDROGEN = 1.00794; int main() { /* Declare variables. */ double mol_weight_glutamic, mol_weight_glutamine; /* Compute the molecular weights. */ mol_weight_glutamic = (4*OXYGEN) + (5*CARBON) + ยฉ2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved. */ NITROGEN + (8*HYDROGEN); mol_weight_glutamine = (3*OXYGEN) + (5*CARBON) + (2*NITROGEN) + (10*HYDROGEN); /* Print the molecular weights. */ cout << "The molecular weight of glutamic is " << mol_weight_glutamic << endl; cout << "The molecular weight of glutamine is " << mol_weight_glutamine << endl; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_39 */ /* */ /* This program computes the molecular weight of a particular */ /* amino acid given the number of atoms for each of the five */ /* elements found in the amino acid. */ #include using namespace std; /* Defines symbolic constants for the appropriate atomic weights. const double OXYGEN = 15.9994; const double CARBON = 12.011; const double NITROGEN = 14.00674; const double HYDROGEN = 1.00794; const double SULFUR = 32.066; */ int main() { /* Declare variable. */ int no_oxy, no_carbon, no_nitro, no_hydro, no_sulfur; double molecular_weight; /* Enter the number of atoms for each of the five elements. cout <> no_oxy; cout <> no_carbon; cout <> no_nitro; cout <> no_sulfur; cout <> no_hydro; */ /* Compute the molecular weight. */ molecular_weight = (no_oxy*OXYGEN) + (no_carbon*CARBON) + (no_nitro*NITROGEN) + (no_sulfur*SULFUR) + (no_hydro*HYDROGEN); ยฉ2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved. /* Print the molecular weight. */ cout << "The molecular weight of this particular amino acid is " << molecular_weight << endl; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_40 */ /* */ /* This program computes the average atomic weight of the atoms */ /* found in a particular amino acid given the number of atoms for */ /* each of the five elements found in amino acid. */ #include using namespace std; /* Defines symbolic constants for the appropriate atomic weights. const double OXYGEN = 15.9994; const double CARBON = 12.011; const double NITROGEN = 14.00674; const double HYDROGEN = 1.00794; const double SULFUR = 32.066; */ int main() { /* Declare variables. */ int no_oxy, no_carbon, no_nitro, no_hydro, no_sulfur, total_no; double average_atomic_weight; /* Enter the number of atoms for each of the five elements. cout << "Enter the number of oxygen atoms found " <> no_oxy; cout <> no_carbon; cout <> no_nitro; cout <> no_sulfur; cout <> no_hydro; */ /* Compute the average weight of the atoms. */ total_no = no_oxy + no_carbon + no_nitro + no_sulfur + no_hydro; average_atomic_weight = ((no_oxy*OXYGEN) + (no_carbon*CARBON) + (no_nitro*NITROGEN) + (no_sulfur*SULFUR) + (no_hydro*HYDROGEN))/total_no; /* Print the average atomic weight. */ cout << "The average weight of the atoms in this particular amino " << "acid is " << average_atomic_weight << endl; /* Exit program. return 0; */ ยฉ2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved. } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_41 */ /* */ /* This program reads in a positive number and then computes */ /* the logarithm of that value to the base 2. */ #include #include using namespace std; int main() { /* Declare variables. double x, answer; */ /* Enter a positive number. */ cout <> x; “; /* Compute the logarithm to base 2. answer = log(x)/log(2.0); */ /* Print the answer. */ cout << "The logarithm of " << x << " to the base 2 is " << answer << endl; /* Exit program. return 0; */ } /*——————————————————————–*/ /*——————————————————————–*/ /* Problem chapter2_42 */ /* */ /* This program reads in a positive number and then computes */ /* the logarithm of that value to the base 8. */ #include #include using namespace std; int main() { /* Declare variables. double x, answer; */ /* Enter a positive number. */ cout <> x; “; /* Compute the logarithm to base 8. answer = log(x)/log(8.0); */ ยฉ2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved. /* Print the answer. */ cout << "The logarithm of " << x << " to the base 8 is " << answer << endl; /* Exit program. return 0; */ } /*——————————————————————–*/ ยฉ2017 Pearson Education, Inc. Hoboken, NJ. All Rights Reserved.

Document Preview (14 of 213 Pages)

User generated content is uploaded by users for the purposes of learning and should be used following SchloarOn's honor code & terms of service.
You are viewing preview pages of the document. Purchase to get full access instantly.

Shop by Category See All


Shopping Cart (0)

Your bag is empty

Don't miss out on great deals! Start shopping or Sign in to view products added.

Shop What's New Sign in