1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kirill115 [55]
2 years ago
5

Complete method printPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 2, print "Too

small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by " seconds". End with a newline. Example output for ounces
Computers and Technology
1 answer:
Sladkaya [172]2 years ago
6 0

Answer:

The complete method in cpp is given below.  

void printPopcornTime(int bagOunces)  

{  

if(bagOunces<2)  

cout<<"Too small"<<endl;  

else if(bagOunces>10)  

cout<<"Too large"<<endl;  

else  

cout<<6*bagOunces << " seconds"<<endl;  

}  

The program implementing the above method is given below.  

#include <iostream>  

using namespace std;  

//method declared  

void printPopcornTime(int bagOunces);  

int main() {  

//variable declared  

int bagOunces;  

//variable initialized  

bagOunces = 10;  

//method called which accepts integer parameter  

printPopcornTime(bagOunces);  

//program ends  

return 0;  

}  

//method defined  

void printPopcornTime(int bagOunces)  

{  

//output displayed based on the value of the variable  

if(bagOunces<2)  

cout<<"Too small"<<endl;  

else if(bagOunces>10)  

cout<<"Too large"<<endl;  

else  

cout<<6*bagOunces << " seconds"<<endl;  

}  

OUTPUT1  

60 seconds  

Explanation:

Program explanation is given below.

1. The method, printPopcornTime(), having return type as void and accepting an integer parameter, bagOunces, is declared as shown.  

void printPopcornTime(int bagOunces);  

2. Method declaration only contains return type, method name and parameters taken by the method, if any.  

3. Method definition consists of the complete method. All the code to be written inside the method is also included in its definition.  

4. The method definition for printPopcornTime() is shown in the beginning.  

5. The value of the integer parameter is tested using multiple if-else statements.  

6. The output is based on the value of the parameter. The output is ends with a newline inserted by endl.

7. The main() method has a return type integer and takes no parameters. The main() method is declared and defined together unlike as shown for the other method, printPopcornTime().  

8. The integer variable, bagOunces, is declared and initialized inside main().  

9. This variable is passed as parameter to the printPopcornTime() method and calling the method.  

printPopcornTime(bagOunces);  

10. The program ends with a return statement.  

11. All the results are shown based on the different values of the variable, bagOunces. The original output is obtained when the value of bagOunces is 10.  

12. If the value of bagOunces is 1, the message displayed is shown.  

OUTPUT2  

Too small  

13. If the value of bagOunces is 11, the message displayed is shown.  

OUTPUT3  

Too large  

You might be interested in
You have successfully compiled the file Hi.java, how do you run the corresponding program from the command line?
n200080 [17]
The answer is b. java Hi.class :)
8 0
2 years ago
Write a python computer program that prints out a factorial.
galina1969 [7]

I included my code in the picture below.

6 0
2 years ago
What is the value of the totalsString variable after the following code is executed? var totals = [141.95, 212.95, 411, 10.95];
Alex Ar [27]
<h2>Answer:</h2>

141.95|212.95|312.95|10.95|

<h2>Explanation:</h2>

<em>Reformatting the code snippet and giving it line numbers;</em>

1.       var totals = [141.95, 212.95, 411, 10.95];

2.      totals[2] = 312.95;

3.      var totalsString = "";

4.      for (var i = 0; i < totals.length; i++) {

5.          totalsString += totals[i] + "|";

6.      }

Line 1 creates an array called totals with four elements.

     First element = totals[0] =141.95

     Second element = totals[1] = 212.95

     Third element = totals[2] = 411

     Fourth element = totals[3] = 10.95

Line 2 replaces the value of the third element <em>totals[2]</em> = 411 with 312.95.

     Therefore the array <em>totals = </em>[141.95, 212.95, 312.95, 10.95]

Line 3 creates an empty string called totalsString

Lines 4 - 6 create a for loop that cycles from i=0 to i<totals.length

       totals.length = 4 (which is the number of items in the array totals)

       This means that the loop cycles from i=0 to i<4

       During cycle 1 when i = 0, the expression inside the for loop executes as follows;

            totalsString = totalsString + totals[0] + "|"   //substitute the values

            totalsString = "" + 141.95 + "|"

            totalsString = 141.95|

       During cycle 2 when i = 1, the expression inside the for loop executes as follows;

            totalsString = totalsString + totals[1] + "|"   //substitute the values

            totalsString = "141.95|" + 212.95 + "|"

            totalsString = 141.95|212.95|

       During cycle 3 when i = 2, the expression inside the for loop executes as follows;

            totalsString = totalsString + totals[2] + "|"   //substitute the values

            totalsString = "141.95|212.95|" + 312.95 + "|"

            totalsString = 141.95|212.95|312.95|

       During cycle 4 when i = 3, the expression inside the for loop executes as follows;

            totalsString = totalsString + totals[3] + "|"   //substitute the values

            totalsString = "141.95|212.95|312.95|" + 10.95 + "|"

            totalsString = 141.95|212.95|312.95|10.95|

At the end of the execution, totalsString = 141.95|212.95|312.95|10.95|

7 0
3 years ago
How to do a linear equations
Dimas [21]
Hey, there are many videos on the internet like youtube that you can watch. Juust type in your questions and there will be many videos that give a brief explanation :) hope it helped u
8 0
2 years ago
I need help please?!!!!!!!!!!
Debora [2.8K]

Answer:

Graduated Drivers License process

Explanation:

It gradually develops skills, just using logic. Hope it helped!

3 0
3 years ago
Read 2 more answers
Other questions:
  • Why are resources limited? Why can't we get everything all the time?
    12·1 answer
  • Web design people please help!
    7·1 answer
  • When a computer restarts without a hardware power-down-power-up cycle, it is doing a _______________?
    9·1 answer
  • While inspecting an element in the DOM on my website using the Chrome Devtools I accidentally deleted the DIV that had all my au
    8·1 answer
  • Comet Computer Company will make a splash with psychedelic laptop cover designs scheduled for release next year. The computers d
    11·1 answer
  • What is the boundary folding method?
    5·1 answer
  • Which renewable resources are available at any time?​
    15·1 answer
  • Elsa wants to save her work at the office to be continued at home either on a pen drive or CD. Outline three reasons why she wil
    6·1 answer
  • A spreadsheet contains the maximum weight and maximum height for fifty dog breeds. The breeds are located in rows, and the weigh
    5·1 answer
  • What are the 3 attributes of information?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!