
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++ (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)
- #include int main (void) { int i, *p, count } p = &count; = 10%; for (i = 5; i >= 0; i--) { count++; (*p) ++; } printf("count return 0; = %d, Have a wonderful day.\n", count); 1. [20 pts] What is the output of the program? Please explain why. 2. [15 pts] What is the gdb command to set a breakpoint in line 6 (p = &count;)? 3. [15 pts] Explain in your own words how the [break. need to use such command? ... if expr] command works. When might youarrow_forwardPlease run and debug the following program and answer the questions.arrow_forward(OnlineGDB) #include <stdio.h>int main(void) {int a;char *s;int v0 = 4, v1 = 5, v2 = 6, v3 = 1, v4 = 2;printf("Exercise 1:\n====================\n");switch(v0) {case 0: printf("Hello October\n"); break;case 1: printf("Go Kean!\n"); break;case 2: printf("Academic Building Center \n"); break;case 3: printf("UNION \n"); break;case 4: printf("Go ");case 5: printf("Kean! \n");default: printf("Have a great semester! \n"); break;}for(a=5; a<v1; a++) {printf("Kean");}printf("\n");if (v2 == 6) {s = "Go";}else {s = "Hello";}if(v3 != v4) {printf("%s Kean!\n",s);} else {printf("%s Computer Science!\n",s);}return 0;} Assume the following codes are added between line 36 (}) and line 38 (return 0;) v0>0 ? ++v1, ++v2 : --v3; Please give the values of v0, v1, v2, v3, and v4 after this line and explain the reason. You can test the program to verify your answer if you like.arrow_forward
- #include <stdio.h>int main(void) {int a;char *s;int v0 = 4, v1 = 5, v2 = 6, v3 = 1, v4 = 2;printf("Exercise 1:\n====================\n");switch(v0) {case 0: printf("Hello October\n"); break;case 1: printf("Go Kean!\n"); break;case 2: printf("Academic Building Center \n"); break;case 3: printf("UNION \n"); break;case 4: printf("Go ");case 5: printf("Kean! \n");default: printf("Have a great semester! \n"); break;}for(a=5; a<v1; a++) {printf("Kean");}printf("\n");if (v2 == 6) {s = "Go";}else {s = "Hello";}if(v3 != v4) {printf("%s Kean!\n",s);} else {printf("%s Computer Science!\n",s);}return 0;} Output: Exercise 1:====================Go Kean! Have a great semester! Go Kean! Please only modify the initial value of v0, v1, v2, v3 and v4 to get the following output. Youneed to show your program output (in the screenshot) and submit the code that youmodified.Exercise 1:====================Hello OctoberKeanHello Computer Science!arrow_forward(OnlineGDB) 1. Please read and run the following code and answer the questions.#include <stdio.h>int main(void) {int a;char *s;int v0 = 4, v1 = 5, v2 = 6, v3 = 1, v4 = 2;printf("Exercise 1:\n====================\n");switch(v0) {case 0: printf("Hello October\n"); break;case 1: printf("Go Kean!\n"); break;case 2: printf("Academic Building Center \n"); break;case 3: printf("UNION \n"); break;case 4: printf("Go ");case 5: printf("Kean! \n");default: printf("Have a great semester! \n"); break;}for(a=5; a<v1; a++) {printf("Kean");}printf("\n");if (v2 == 6) {s = "Go";}else {s = "Hello";}if(v3 != v4) {printf("%s Kean!\n",s);} else {printf("%s Computer Science!\n",s);}return 0;} What is the output of the program? Please explain why.arrow_forward1.[30 pts] Answer the following questions: a. [10 pts] Write a Boolean equation in sum-of-products canonical form for the truth table shown below: A B C Y 0 0 0 1 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 0 a. [10 pts] Minimize the Boolean equation you obtained in (a). b. [10 pts] Implement, using Logisim, the simplified logic circuit. Include an image of the circuitarrow_forward
- In the past, encryption and decryption were mostly done by substitution and permutation of letters in a text message. study those classic cryptographic schemes Then, develop an automatic cipher using Javascript The cipher should be able to perform the following tasks: generate keys encrypt a given plaintext message with a key selected from the list of keys generated decrypt a given ciphertext message with a known cipher keyarrow_forwardList reasons why teachers should and shouldn’t be replaced by computers? State your response in a descriptive context. Provide five references from the with internet with your answers.arrow_forwardThe attached picture shows the RTCAPI memory mapped register which has the address 0x180. 1) Program the MCU's registers so that a) SIRC is the clock source b) the clock is divided by 16K c) the clock is enabled d) load is enabledarrow_forward
- What is the ALU result if the 4-bit ALU Control signal is 0100? What happens if the ALU Control signal is 0101?arrow_forwardIn the past, encryption and decryption were mostly done by substitution and permutation of letters in a text message. study those classic cryptographic schemes Then, develop an automatic cipher using a programming language of your choice. The cipher should be able to perform the following tasks: generate keys encrypt a given plaintext message with a key selected from the list of keys generated decrypt a given ciphertext message with a known cipher keyarrow_forwardCase Study Instructions: Offshore Wind Energy in the North Sea For this case study, students will analyze the institutional challenges and social rules surrounding offshore wind energy development in the Dutch North Sea, as explored in the case study from the textbook (pages 44-46). Additional resources in this week’s learning module will provide further perspectives on the impact of wind energy on different stakeholders. Students should refer to the syllabus for specific guidelines regarding length, format, and content requirements. Reflection Questions to Consider: What are the key institutional challenges in implementing offshore wind energy in the North Sea? How do formal and informal social rules shape the use of this shared space? What conflicts arise between different stakeholders (e.g., fishermen, naval transport, military, and wind energy developers)? How can policymakers balance economic, environmental, and social considerations when allocating space for wind energy?…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,




