Concept explainers
A metric ton is 35,273.92 ounces. Write a
Weight of breakfast package
Program Plan:
- Include required header files.
- Initializes “const” variable “OUNCES_PER_METRICTON” to “35273.92”.
- Define main function,
- Declare three variables in “double” datatype.
- Declare a “char” variable for user option.
- Then performs “do-while” loop.
- Prompt statement for read the weight of packages in ounces.
- Read the weight of packages from user.
- Compute the weight in metric tons using “ounces/OUNCES_PER_METRICTON” and then store it in a variable “weightMetricTon”.
- Compute the number of boxes required to produce “1” metric ton using “OUNCES_PER_METRICTON/ounces” and then store it in a variable “no_of_boxes”.
- Display the weight in metric tons and number of boxes.
- Prompt statement for read the user option to continue the calculation.
- Read the user option.
- Check the user option using “while” loop. If the user entered option is equal to “y” or “Y” then continue the above process.
- Otherwise, the program terminated.
The below program is used to compute the weight of package of breakfast cereal in metric tons and number of boxes from the given weight of package in ounces
Explanation of Solution
Program:
//Header file
#include <iostream>
//For standard input and output
using namespace std;
/* Initializes the const variable "OUNCES_PER_METRICTON" to "35273.92" */
const double OUNCES_PER_METRICTON = 35273.92;
//Define main function
int main()
{
//Declare variables in type of "double"
double ounces, weightMetricTon, no_of_boxes;
//Declare variable in type of "char"
char option;
//Check the condition using "do-while" loop
do
{
/* Prompt statement for read the weight of package in ounces */
cout << "Enter the weight of package of breakfast cereal in ounces: ";
//Read the weight in ounces from user
cin>>ounces;
//Compute the given weight in metric ton
weightMetricTon = ounces/OUNCES_PER_METRICTON;
/* Compute the number of boxes required to produce "1" metric ton */
no_of_boxes = OUNCES_PER_METRICTON/ounces;
//Display the weight in metric tons
cout << "Weight of packets in metric tons: " << weightMetricTon << endl;
//Display the number of boxes
cout << "Number of boxes needed to yield 1 metric ton of cereal: " << no_of_boxes << endl;
//Prompt statement for asking the user choice
cout << "Enter 'y' or 'Y' to continue (OR) Enter any character to terminate: ";
//Read option from user
cin >> option;
}
/* If the user entered option is "y" or "Y", then continue the above process. Otherwise program terminated */
while (option == 'y' || option == 'Y');
return 0;
}
Output:
Enter the weight of package of breakfast cereal in ounces: 4000
Weight of packets in metric tons: 0.113398
Number of boxes needed to yield 1 metric ton of cereal: 8.81848
Enter 'y' or 'Y' to continue (OR) Enter any character to terminate: y
Enter the weight of package of breakfast cereal in ounces: 4820
Weight of packets in metric tons: 0.136645
Number of boxes needed to yield 1 metric ton of cereal: 7.31824
Enter 'y' or 'Y' to continue (OR) Enter any character to terminate: n
Want to see more full solutions like this?
Chapter 2 Solutions
Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (9th Edition)
Additional Engineering Textbook Solutions
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Database Concepts (8th Edition)
Degarmo's Materials And Processes In Manufacturing
Starting Out with C++ from Control Structures to Objects (9th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
- what type of internet connection should be avoided on mobile devices?arrow_forwardI need help creating the network diagram and then revising it for the modified activity times.arrow_forwardActivity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.arrow_forward
- Given the following Extended-BNF grammar of the basic mathematical expressions: Show the derivation steps for the expression: ( 2 + 3 ) * 6 – 20 / ( 3 + 1 ) Draw the parsing tree of this expression. SEE IMAGEarrow_forwardWhentheuserenters!!,themostrecentcommandinthehistoryisexecuted.In the example above, if the user entered the command: Osh> !! The ‘ls -l’ command should be executed and echoed on user’s screen. The command should also be placed in the history buffer as the next command. Whentheuserentersasingle!followedbyanintegerN,theNthcommandin the history is executed. In the example above, if the user entered the command: Osh> ! 3 The ‘ps’ command should be executed and echoed on the user’s screen. The command should also be placed in the history buffer as the next command. Error handling: The program should also manage basic error handling. For example, if there are no commands in the history, entering !! should result in a message “No commands in history.” Also, if there is no command corresponding to the number entered with the single !, the program should output "No such command in history."arrow_forwardActivity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.arrow_forward
- 2. UNIX Shell and History Feature [20 points] This question consists of designing a C program to serve as a shell interface that accepts user commands and then executes each command in a separate process. A shell interface gives the user a prompt, after which the next command is entered. The example below illustrates the prompt osh> and the user's next command: cat prog.c. The UNIX/Linux cat command displays the contents of the file prog.c on the terminal using the UNIX/Linux cat command and your program needs to do the same. osh> cat prog.c The above can be achieved by running your shell interface as a parent process. Every time a command is entered, you create a child process by using fork(), which then executes the user's command using one of the system calls in the exec() family (as described in Chapter 3). A C program that provides the general operations of a command-line shell can be seen below. #include #include #define MAX LINE 80 /* The maximum length command */ { int…arrow_forwardQuestion#2: Design and implement a Java program using Abstract Factory and Singleton design patterns. The program displays date and time in one of the following two formats: Format 1: Date: MM/DD/YYYY Time: HH:MM:SS Format 2: Date: DD-MM-YYYY Time: SS,MM,HH The following is how the program works. In the beginning, the program asks the user what display format that she wants. Then the program continuously asks the user to give one of the following commands, and performs the corresponding task. Note that the program gets the current date and time from the system clock (use the appropriate Java date and time operations for this). 'd' display current date 't': display current time 'q': quit the program. • In the program, there should be 2 product hierarchies: "DateObject” and “TimeObject”. Each hierarchy should have format and format2 described above. • Implement the factories as singletons. • Run your code and attach screenshots of the results. • Draw a UML class diagram for the program.arrow_forward#include <linux/module.h> #include <linux/kernel.h> // part 2 #include <linux/sched.h> // part 2 extra #include <linux/hash.h> #include <linux/gcd.h> #include <asm/param.h> #include <linux/jiffies.h> void print_init_PCB(void) { printk(KERN_INFO "init_task pid:%d\n", init_task.pid); printk(KERN_INFO "init_task state:%lu\n", init_task.state); printk(KERN_INFO "init_task flags:%d\n", init_task.flags); printk(KERN_INFO "init_task runtime priority:%d\n", init_task.rt_priority); printk(KERN_INFO "init_task process policy:%d\n", init_task.policy); printk(KERN_INFO "init_task task group id:%d\n", init_task.tgid); } /* This function is called when the module is loaded. */ int simple_init(void) { printk(KERN_INFO "Loading Module\n"); print_init_PCB(); printk(KERN_INFO "Golden Ration Prime = %lu\n", GOLDEN_RATIO_PRIME); printk(KERN_INFO "HZ = %d\n", HZ); printk(KERN_INFO "enter jiffies = %lu\n", jiffies); return 0; } /* This function is called when the…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,