Concept explainers
A metric ton is 35,273.92 ounces. Write a
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?
Chapter 1 Solutions
ABSOLUTE C++ -TEXT
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects (9th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Starting Out With Visual Basic (8th Edition)
SURVEY OF OPERATING SYSTEMS
Starting Out with C++ from Control Structures to Objects (9th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
- A parking garage charges a $20.00 minimum fee to park for up to three hours. The garage charges an additional $5.00 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24- hour period is $50.00. Assume that no car parks for longer than 24 hours at a time. Write a program that calculates and printsthe 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: Car Hours Charge1 1.5 20.002 4.0…arrow_forwarduse c languagre program.arrow_forwardWrite a program that computes the molecular weight of a carbohydrate (ingrams per mole) based on the number of hydrogen, carbon, and oxygenatoms in the molecule. The program should prompt the user to enter thenumber of hydrogen atoms, the number of carbon atoms, and the numberof oxygen atoms. The program then prints the total combined molecularweight of all the atoms based on these individual atom weights:Atom Weight(grams I mole)H 1.00794c 12.01070 15.9994For example, the molecular weight of water (H20) is: 2(1.00794) +15.9994 = 18.01528.arrow_forward
- Body Mass Index (BMI) is a measure of health on weight. It can be calculated by taking your weight in kilograms and dividing by the square of your height in meters. Write a program which prompts the user to enter the weight in kgs (integer value) and height in feet and inches (both integers) and then calculates the BMI of the person. Your program first need to convert inches to meters (i.e. inches * 0.0254) and then use the following formula to calculate BMI: weight kilogram / (height_meter)^2 Your program displays the BMI value in two decimal places and the corresponding status as shown in the examples below. Note that one inch is 0.0254 meters and 1 foot is 12 inches. For example: Input Result 62 5 10 89 6 0 45 BMI BMI < 18.5 18.5 s BMI < 25.0 25.0 ≤ BMI < 30.0 30.0 ≤ BMI 7 82 5 Interpretation Underweight Normal Overweight Obese 2 Enter weight (kg): Enter height (feet): Enter height (inches): BMI is 19.61, Normal Enter weight (kg): Enter height (feet): Enter height (inches): BMI is…arrow_forwardGiven an airplane's acceleration and take-off speed v, you can compute the minimum runway length needed for an airplane to take off using the following formula. length=v^2/2*a. write a program that prompts the user to enter V in meters and acceleration an in meter/second and display the minimum runway length.arrow_forwardMeadowdale Dairy Farm sells organic brown eggs to local customers. It charges $3.25 for a dozen eggs, or 45 cents for individual eggs that are not part of a dozen. Write a program that prompts a user for the number of eggs in the order and then display the amount owed with a full explanation using the following wording: You ordered 27 eggs. That’s 2 dozen at $3.25 per dozen and 3 loose eggs at 45 cents each for a total of $7.85. write a program that calculates the following: The program calculates the cost of 12 egss The program calculates the cost of 35 eggs The program calculates the cost of 6 eggs JAVA import java.util.Scanner; class Eggs { public static void main(String[] args) { // Write your code here } }arrow_forward
- Meadowdale Dairy Farm sells organic brown eggs to local customers. It charges $3.25 for a dozen eggs, or 45 cents for individual eggs that are not part of a dozen. Write a program that prompts a user for the number of eggs in the order and then display the amount owed with a full explanation using the following wording: You ordered 27 eggs. That’s 2 dozen at $3.25 per dozen and 3 loose eggs at 45 cents each for a total of $7.85.arrow_forwardMeadowdale Dairy Farm sells organic brown eggs to local customers. It charges $3.25 for a dozen eggs, or 45 cents for individual eggs that are not part of a dozen. Write a program that prompts a user for the number of eggs in the order and then display the amount owed with a full explanation using the following wording: You ordered 27 eggs. That’s 2 dozen at $3.25 per dozen and 3 loose eggs at 45 cents each for a total of $7.85. So far everything is right but something in my equations is causing my ouput to show up as 45.0arrow_forwardGiven the sample code above in generating a random number. Create a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Don't display the computer's choice yet.) 2. The user enters his or her choice of "rock", "paper", or "scissors" at the keyboard. (You can use a menu if you prefer.) 13. The computer's choice is displayed. 4. A winner is selected according to the following rules: a. If one player chooses rock and the other player chooses scissors, then rock wins. (The rock smashes the scissors.) b. If one player chooses scissors and the other player chooses paper, then scissor wins. (Scissors cuts paper.) c. If one player chooses paper and the other player…arrow_forward
- Write a program to calculate the position of a projectile at a given time t. For an initial velocity vo and angle of departure ®g, the position is given by x and y coordinates as follows (note: the gravity constant g is 9.81 m/s²): X= V0 Cos (0)t y=vo sin (8,)t –; gt The program should initialize the variables for the initial velocity, time, and angle of departure. It should then call a function to find the x and y coordinates, and then another function to print the resultsarrow_forwardthere are three seating categories at a stadium. for a softball game, class A seats are $30, Class B seats are $20 and Class C seats are $15. Write a program that asks how many tickets for each class of seats were sold and then displays the amount of income generated from ticket sales. answer using C++arrow_forwardWrite a program to read basic salary (bsalary) and sales (sales) then calculate and print the net salary that represents bsalary + (commission comm) and if you know that the commission is calculated as follows: 2% of the basic salary, if sales are less or equal Three times the base salary comm = 0.02 * bsalary, 3% of the base salary if sales are more than three times the base %3D salary (comm = 0.03 * bsalary) 5% of the base salary, if sales are more than five times the base salary (comm = 0.05 * bsalary) %3Darrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning