Absolute C++
Absolute C++
6th Edition
ISBN: 9780133970784
Author: Walter Savitch, Kenrick Mock
Publisher: Addison-Wesley
bartleby

Concept explainers

bartleby

Videos

Textbook Question
100%
Book Icon
Chapter 1, Problem 1PP

A metric ton is 35,273.92 ounces. Write a program that will read the weight of a package of breakfast cereal in ounces and output the weight in metric tons as well as the number of boxes needed to yield one metric ton of cereal.

Expert Solution & Answer
Check Mark
Program Plan Intro

List of variables:

ounces: Store the weight of the breakfast meal in ounces.

result: Store the weight in metric tons.

List of functions used:

ceil(): Calculate the ceiling value of the function.

cin(): To take input from input streams like keyboard, files, etc.

cout(): To display the output.

Summary Introduction:

Program will use Main () method to prompt the user to enter the weight of the breakfast meal in ounces and convert it into metric tons and also find the number of boxes needed to yield one metric ton of cereal.

Program Description:

Purpose of program is to find the weight in metric tons and also find the number of boxes needed to yield one metric ton of cereal.

Explanation of Solution

Program:

Following is the C++ program to find the weight in metric tons, and to find the number of boxes needed to yield one metric ton of cereal.

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
 float ounces;
cout<< "Enter the weight of the breakfast meal in ounces: ";
cin>> ounces;
// Conversion from ounces to metric tons 
 float result = ounces/35273.92;
cout<<endl;
cout<< "The weight of the package of breakfast in metric ton is : " << result;
cout<<endl;
cout<< "The number of boxes needed to yield the one metric ton of cereal are: " << ceil(1/result);
cout<<endl;
 return 0;
}

Explanation:

In the above program,the user prompts the weight of the breakfast meal in ouncesand the formula to convert the weight from ounce to metric ton is used. The number of boxes needed is the reciprocal of the weight in metric tons. Then cout() function is used to show the output of the program.

Sample Output:

Following is the sample output for the given program:

Enter the weight of the breakfast meal in ounces: 350 
The weight of the package of breakfast in metric ton is : 0.00992235 
The number of boxes needed to yield the one metric ton of cereal are : 101

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
A parking garage charges a $2.00 minimum fee to park for up to three hours and an additional $1 per hour for each hour or part thereof over four hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time. Write a program that will calculate and print the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should print the results in a neat tabular format, and should calculate and print the total of yesterday's receipts. The program should use the function calculate Charges to determine the charge for each customer.
A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time. Write a program that calculates and prints the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should print the results in a neat tabular format and should calculate and print the total of yesterday’s receipts. The program should use the function calculateCharges to determine the charge for each customer. Your outputs should appear in the following format Sample output Enter the hours parked for 3 cars: 1.5 4.0 24.0 Car Hours Charge 1 1.5 2.00 2 4.0 2.50 3 24.0 10.00 TOTAL 29.5 14.50
One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of acres in a tract of land with 389,767 square feet.

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
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
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Constants, Variables, Data types, Keywords in C Programming Language Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=d7tdL-ZEWdE;License: Standard YouTube License, CC-BY