Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++program that receives two double-precision floating-point values from the user. The program then should print the sum (addition), difference (subtraction), product (multiplication), and

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Write a C++program that receives two double-precision floating-point values from the user. The program then should print the sum (addition), difference (subtraction), product (multiplication), and quotient (division). Your program should use only integers. A sample program run would look like (the user enters the 10 and the 2.5 after the colons, and the program prints the rest): Please enter the first number: 10 Please enter the second number: 2.5 10+2.5=12.5 102.5=7.5 102.5=25 10/2.5=4 Can you explain the results it produces for all these operations? What happens if you attempt to compute the remainder after division (modulus) with double-precision floating-point values? 5. In mathematics, the midpoint between the two points (x1,y1) and (x2,y2) is computed by the formula (2x1+x2,2y1+y2) Write a C++program that receives two mathematical points from the user and computes and prints their midpoint. A sample run of the program produces Please enter the first point: (0,0) Please enter the second point: (1,1) The midpoint of (,0) and (1,1) is (0.5,0.5) The user literally enters " (0,0) " and "(1,1)" with the parentheses and commas as shown. To see how to do this, suppose you want to allow a user to enter the point (2.3,9), assigning the x component of the point to a variable named x and the y component to a variable named y. You can add the following code fragment to your program to achieve the desired effect: Table 4.7: Calorie content of several fast food items double x,y char left_paren, comma, right_paren; std: :cin > left_paren > comma >y right_paren; If the user literally types (2.3,9), the std: : cin statement will assign the (character to the variable left_paren. It next will assign 2.3 to the variable x. It assigns the , character to the variable named comma, the value 9 to the y variable, and the ) character to the right_paren variable. The left_paren, comma, and right_paren variables are just placeholders for the user's input and are not used elsewhere within the program. In reality, the user can type in other characters in place of the parentheses and comma as long as the numbers are in the proper location relative to the characters; for example, the user can type 2.3:9#, and the program will interpret the input as the point (2.3,9). Table 4.7 lists the Calorie contents of several foods. Running or walking burns off about 100 Calories per mile. Write a C++ program that requests three values from the user: the number of bean burritos, salads, and shakes consumed (in that order). The program should then display the number of miles that must be run or walked to burn off the Calories represented in that food. The program should run as follows (the user types in the 321 ): Number of bean burritos, bowls of salad, and milkshakes eaten? 321 You ingested 1829Calories You will have to run 18.29 miles to expend that much energy Observe that the result is a floating-point value, so you should use floating-point arithmetic to compute the answers for this

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions