ABSOLUTE C++ -TEXT
ABSOLUTE C++ -TEXT
6th Edition
ISBN: 2810017515514
Author: SAVITCH
Publisher: PEARSON
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
Find the error, assume data is a string and all variables have been declared. for ch in data:         if ch.isupper:             num_upper = num_upper + 1         if ch.islower:             num_lower = num_lower + 1         if ch.isdigit:             num_digits = num_digits + 1         if ch.isspace:             num_space = num_space + 1
Find the Error: date_string = input('Enter a date in the format mm/dd/yyyy: ') date_list = date_string.split('-') month_num = int(date_list[0]) day = date_list[1] year = date_list[2] month_name = month_list[month_num - 1] long_date = month_name + ' ' + day + ', ' + year print(long_date)
Find the Error:       full_name = input ('Enter your full name: ')       name = split(full_name)       for string in name:         print(string[0].upper(), sep='', end='')         print('.', sep=' ', end='')

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++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
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