Concept explainers
Distance per Tank of Gas
A car with a 20-gallon gas tank averages 23.5 miles per gallon when driven in town, and 28.9 miles per gallon when driven on the highway. Write a
Hint: The following formula can be used to calculate the distance:
Distance = Number of Gallons × Average Miles per Gallon
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Additional Engineering Textbook Solutions
Modern Database Management (12th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Computer Systems: A Programmer's Perspective (3rd Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
- The following table shows the approximate speed of sound in air, water, and steel: Write a program that asks the user to enter “air”, “water”, or “steel” and the distance that a sound wave will travel in the medium. The program should then display the amount of time it will take. You can calculate the amount of time it takes sound to travel in air with the following formula: Time = Distance / 1,100 You can calculate the amount of time it takes sound to travel in water with the following formula: Time = Distance / 4,900 You can calculate the amount of time it takes sound to travel in steel with the following formula: Time = Distance / 16,400arrow_forwardRunning the program Your program should take 5 arguments: start annual years return inflation where start is the initial investment amount annual is the amount that is added to the investment every year years is the number of years that the investment is held return is the annual investment return expressed as a percentage inflation is the annual inflation rate expressed as a percentage So, to calculate the future and present value of $1000 investment after 10 years where you add $100 every year with a 7% return and 2% inflation, you give the following arguments and get this output: $ ./fv 1000 100 10 7 2 Future Value: $3445.51 Present Value: $2826.52 Writing the code Starter code is provided for you below int main(int arge, char **argv ) { int a, n double value, present, I, is value= atof(argv[1]); a = atoi (argv [2]); natoi (argv[3]); r = atof (argv[4])/100; i = atof(argv[5])/100; // TODO write your code here printf("Future Value: $%.2f\n", value) printf("Present Value: $%.2f\n",…arrow_forwardWrite a program that can calculate the future and present value of an investment given various parameters. When you calculate the future value of an investment, the more years you hold the investment and the higher the rate of return, the more valuable it is. For example, a $1000 investment at 7% return will give you $1070 (1000+ 0.07-1000) after one year and $1144.90 (1070+0.07-1007) after two years. However, because of inflation, that $1144.90 after two years is not worth the same as $1144.90 now. If the inflation rate is 2%, $1144.90 in two years is the equivalent of $1100.44 now-i.e- L02 More generally, the present value, p, of an investment is 1.02² 1144.90 f p= where is the inflation rate as a percentage. Typically, one would add to the investment with annual contributions. Let's say you start with a $1000 investment and add $100 every year. Therefore, after the first year, you will have $1177 - 7% return on $1100i.e. $1000 initial investment + the $100 year one contribution.…arrow_forward
- Running the program Your program should take 5 arguments: start annual years return inflation where start is the initial investment amount annual is the amount that is added to the investment every year years is the number of years that the investment is held return is the annual investment return expressed as a percentage inflation is the annual inflation rate expressed as a percentage So, to calculate the future and present value of $1000 investment after 10 years where you add $100 every year with a 7% return and 2% inflation, you give the following arguments and get this output: $ ./fv 1000 100 10 7 2 Future Value: $3445.51 Present Value: $2826.52 Writing the code Starter code is provided for you below int main(int arge, char **argv ) { int a, n double value, present, I, is value= atof (argv[1]); a = atoi (argv[2]); natoi (argv[3]); r = atof (argv[4])/100; i = atof(argv[5])/100; // TODO write your code here printf ("Future Value: $%.2f\n", value) printf("Present Value: $%.2f\n",…arrow_forwardAverage acceleration is defined as the change of velocity divided by the time taken to make the change, as shown in the following formula: a = ( v1 - v0 ) / t Write a program that prompts the user to enter the starting velocity in meters/second, the ending velocity in meters/second, and the time span t inseconds, and displays the average acceleration.arrow_forwardBody Mass Index is a simple calculation using a person's height and weight. The formula is BMI = kg/m2 where kg is a person's weight in kilograms and m2 is their height in meters squared. Calculate a persons Body Mass index using their weight in pounds. This means you must first convert pounds to kilograms (kg) then apply the formula above. In converting pounds to kg, 1 pound = 0.453592 kg. So to convert pounds to kg, either multiply the pound value by 0.45359237 or divide by 2.2046226218. Then you must convert their height in inches to meters. The length in meters is equal to the inches multiplied by 0.0254. Write a program that accepts a users height as an integer in inches and their weight in pounds. Convert those inputs to their metric equivalents outlined above and determine their body mass index. Display what the conversions from and to their metric equivalents are. Display the body mass index and the category it belongs to.arrow_forward
- Write a Phyton program that computes the duration of a projectile’s flight and its height above the ground when it reaches the target. As part of your solution, you should display instructions to the program user. Relevant formula: time = distancevelocity xcos (θ) height = velocity xsin x time- g x time22 use the following variables: g = gravitational constant = 32.17 = angle of elevation in radian v = velocity or the projectile velocity (ft/sec) d= distance to target t = time of flight in seconds. h = height at impact Try your program on these data sets.arrow_forwardAverage acceleration is defined as the change of velocitydivided by the time taken to make the change, as given by the following formula: a =v1 - v0 /t Write a program that prompts the user to enter the starting velocity v0 in meters/second, the ending velocity v1 in meters/second, and the time span t in seconds,then displays the average acceleration. Here is a sample run: Enter v0, v1, and t: 5.5 50.9 4.5The average acceleration is 10.0889arrow_forwardBody mass index (BMI) is a measure of health based on weight. It can be calculated by taking your weight in kilograms and dividing it by the square of your height in meters. Write a program that prompts the user to enter a weight in pounds and height in inches and displays the BMI. Note that one pound is 0.45359237 kilograms and one inch is 0.0254 meters.arrow_forward
- The volume of any cylinder can be calculated using the following formula: volume = π * radius2 * height Write a program which asks the user to enter the radius and height of a cylinder. If the radius and the height are both greater than 0, calculate the volume of the cylinder and print "value is the volume of the cylinder" where value is the calculated volume of the cylinder. Otherwise, print "The radius and height of a cylinder must both be positive values." Remember to include a comment at the start of the program. (Hint: The value of π is approx. 3.1416)arrow_forwardPLEASE COMMENT CODE Write a Python program that does the following Asks the user to enter the order. If the order is greater than $1000, there is 17% discount, if the order is greater than $800 and less or equal to $1000, the discount is 13%, if the order is less or equal to $ 800 but greater than $ 500, the discount is 9%, otherwise the discount is 5%. The tax percent is 13%. The program calculates the total invoice of the customer after the appropriate discount and the tax amount are applied. The program prints out the customer name (entered by the user), the discounted amount, the tax amount and the total invoice. The program asks if the user wants to continue using the application with a new order (y/n). Sample run: Please, enter the name of the customer: John Smith Please, enter the total of your order: $1100 Customer name: John Smith The order amount: $1100 The discounted…arrow_forwardOne acre of land is equivalent to 43,560 square feet. Write a program that asks the user to enter the total square feet in a tract of land and calculates the number of acres in the tract. Hint: Divide the amount entered by 43,560 to get the number of acres.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning