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 2, Problem 1PP

(General math) a. Design, write, compile, and run a C++ program that calculates and displays the area of a triangle, such as the one in Figure 2.18, with a base of 1 in and a height of 1.5 in. The area is given by this formula:

Area = 1×2  ( base )  ×  ( height )

Chapter 2, Problem 1PP, (General math) a. Design, write, compile, and run a C++ program that calculates and displays the

b. Manually check the values computed by your program. After verifying that your program is working correctly, modify it to determine the area of a two-dimensional triangle with a base of 3.5 in and a height of 1.45 in.

(a)

Expert Solution
Check Mark
Program Plan Intro

Program plan:

In the coding window, write the necessary code:

  • To Declarethree float variable base=1, height=1.5 and area.
  • To calculate the area of triangle.
  • To display the calculated area of triangleto user.

Program description:

The main purpose of the program is to calculate the area of triangle with the given height and radius.In the main method,calculating the area of triangle with the given base and height and finally, displaying the output of area of triangle to user.

Explanation of Solution

Given information:

   Area= 1 2 ×base×height

   base=1 in

   height=1.5 in

Program:

Program code to calculate the area of triangle:

//importing essential header files
#include<iostream>
//using namespace standards
usingnamespace std;
//main method
int main()
{
//declaring variables
float base=1;
float height=1.5;
float area;
//calculating area
    area=height*base/2;
//displaying area to user
    cout<<"area of triangle with base "<<base<<" inch and height "<<height <<" inch  is "<<area<<"sq. inch";
return0;
}

Explanation:

In the main method, three float variable base=1, height=1.5 and area are declared. After that the area of triangle is calculated by using the below given formula:

   Area= 1 2 ×base×height

And the finally, calculated results are displayed to user.

Output:

Output of the above given program code:

  C++ for Engineers and Scientists, Chapter 2, Problem 1PP , additional homework tip  1

(b)

Expert Solution
Check Mark
Program Plan Intro

To verify the results produced by above program and then use the above program to calculate area of two-dimensional triangle whose base in 3.5in and height 1.5 in.

Explanation of Solution

Given information:

   Area= 1 2 ×base×height

   base=1 in

   height=1.5 in

Explanation:

Firstly, verifying the results calculate by the above program.

   Area= 1 2 ×base×height

   base=1 in

   height=1.5 in

Putting the given values in the above formula,

   Area= 1 2 ×1 in×1.5 in=0.75 i n 2

Thus, the calculated results are correct.

Now, modifying the program code to calculate the area of triangle with the given height =1.45 inch and base =3.5 inch.

Program code:

//importing essential header files
#include<iostream>
//using namespace standards
usingnamespace std;
//main method
int main()
{
//declaring variables
float base=3.5;
float height=1.45;
float area;
//calculating area
    area=height*base/2;
//displaying area to user
    cout<<"area of triangle with base "<<base<<" inch and height "<<height <<" inch  is "<<area<<"sq. inch";
return0;
}

Explanation:

In this program, in the main method, three float variable base=3.5, height=1.45 and area are declared. After that the area of triangle is calculated by using the below given formula:

   Area= 1 2 ×base×height

And the finally, calculated results are displayed to user.

Output:

  C++ for Engineers and Scientists, Chapter 2, Problem 1PP , additional homework tip  2

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
(C++ OOP) We have a house with 3 rooms.We need the user to enter 1 integer as the window number, 2 doubles as depth and width of the room, 1 double as the useless area, 1 boolean as the door's opening direction (e.g. 0 is outward).Program will compute and print the air condition as a string and the total useful area of the house as a double. Calculating the air condition: Name it air_c. Divide the useful area by the window number. If air_c >20, output "bad". If air_c <11 output "good". If 11<=air_c<=20, output "ideal". Attention: If the window number is 0, air condition is bad. Calculating the useful area of room: Width*Depth-(useless area)if the door is inward;Width*Depth-(useless area)-0.8The worst air condition of the 3 is the final air condition of house. --- 1)The information about the home must be all private within a class.2)The class must get these inputs within constructor func.3)Calculating the useful area of a room must be done within a function of a class.4)Air…
(C++ Programming language) There are following two major issues associated with cpp programs:• When a program is terminated, the entire data is lost. • If you have to enter a large number of data, it will take a lot of time to enter them all in the different programs.Suggest a solution and elaborate the same with the help of suitable examples.
(c++) Write a program that takes user input describing a playing card with the following shorthand: A = Ace 2...10  card values J = Jack Q = Queen, etc. D = Diamonds S = Spades. etc. Ex. if the user enters QS then your program responds with Queen of Spades

Chapter 2 Solutions

C++ for Engineers and Scientists

Ch. 2.1 - (Practice) You’re a sophomore in college and are...Ch. 2.1 - (Practice) You’re given the job of planting a...Ch. 2.1 - (Practice) You’re responsible for planning and...Ch. 2.1 - (Data processing) a. A national medical testing...Ch. 2.2 - (Debug) a. Will the following program work?...Ch. 2.2 - (Modify) Rewrite the following programs to conform...Ch. 2.2 - (For thought) a. When used in a message, the...Ch. 2.2 - (For thought) a. A token of a computer language is...Ch. 2.3 - (Practice) Determine data types appropriate for...Ch. 2.3 - (Practice) Compile and run Program 2.5.Ch. 2.3 - Prob. 3ECh. 2.3 - (Practice) Show how the name KINGSLEY is stored in...Ch. 2.3 - Prob. 5ECh. 2.3 - Prob. 6ECh. 2.3 - Prob. 7ECh. 2.3 - (For thought) Although you have concentrated on...Ch. 2.3 - (Practice) Although the total number of bytes...Ch. 2.4 - (Practice) For the following correct algebraic...Ch. 2.4 - (Practice) Determine the values of the following...Ch. 2.4 - (Practice) Determine the value of the following...Ch. 2.4 - (Practice) Evaluate the following mixed-mode...Ch. 2.4 - Prob. 5ECh. 2.4 - Prob. 6ECh. 2.4 - Prob. 7ECh. 2.4 - Prob. 8ECh. 2.4 - Prob. 9ECh. 2.4 - (Program) Write a C++ program that displays the...Ch. 2.4 - Prob. 11ECh. 2.5 - (Practice) State whether the following variable...Ch. 2.5 - Prob. 2ECh. 2.5 - (Practice) a. Write a declaration statement to...Ch. 2.5 - Prob. 4ECh. 2.5 - Prob. 5ECh. 2.5 - Prob. 6ECh. 2.5 - Prob. 7ECh. 2.5 - Prob. 8ECh. 2.5 - (Practice) a. Using Figure 2.14 and assuming the...Ch. 2.5 - Prob. 10ECh. 2.5 - Prob. 11ECh. 2.6 - (Modify) a. Modify Program 2.11 to calculate the...Ch. 2.6 - (Modify) a. Modify Program 2.11 to determine the...Ch. 2.6 - Prob. 3ECh. 2.6 - Prob. 4ECh. 2.6 - (Conversion) a. Design, write, compile, and run a...Ch. 2.6 - (Hydraulics) a. Write, compile, and run a C++...Ch. 2.6 - (Thermodynamics) a. Design, write, compile, and...Ch. 2.6 - Prob. 8ECh. 2 - (General math) a. Design, write, compile, and run...Ch. 2 - (General math) a. Design, write, compile, and run...Ch. 2 - (Physics) a. Design, write, compile, and run a C++...Ch. 2 - Prob. 4PPCh. 2 - (Hydraulics) a. Design, write, compile, and run a...Ch. 2 - Prob. 6PPCh. 2 - (Physics) a. The weight of an object on Earth is a...Ch. 2 - (Modify) a. Modify the program you wrote for...Ch. 2 - (Civil eng.) The maximum load that can be placed...Ch. 2 - (Civil eng.) Modify the program written for...Ch. 2 - (Mechanical eng.) The minimum radius required for...
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