Question

C++ Programming Question for an intro course Complete a program that determines how many brownies will...

C++ Programming Question for an intro course

Complete a program that determines how many brownies will fit in a baking pan of a specified size. The program should do the following correctly:  Prompt the user to enter the length and width (in inches) of a baking pan.  Compute the surface area of the bottom of the pan.  Compute how many small brownies the pan will hold if each one is cut with a 1”x1” square bottom.  Compute how many big brownies the pan will hold if each one is cut with a 2”x2” square bottom.  Display, with appropriate labels, the pan dimensions, the number of small brownies, and the number of large brownies the pan can hold. The output might look something like this: A 12 X 9 inch pan can hold 108 small brownies or 27 large brownies.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: The sample output that is shown might not be correct. As the size of pan is 12 x 9, there is no way we can put more than 4 big brownies in the width of the pan, and because we can put 6 big brownies in the height, the maximum number of big brownies that we can place is 6*4 = 24 (and not 27) assuming we can not cut the brownies into half. Considering this the C++ code is as follows.

Code:

#include <iostream>

using namespace std;

int main(){
   int h,w,num_small,num_big;
   cout<<"Enter the length of the baking pan: ";
   cin>>h;
   cout<<"Enter the width of the baking pan: ";
   cin>>w;
   // As each cell in (h x w) pan will have a size of (1 x 1),
   // so h*w smaller brownies will fit in (h x w) sized pan.
   num_small = h*w;
   // As each (2 x 2) cell in (h x w) pan will fit a bigger brownie,
   // so only way to put brownies in the pan is if their number divides
   // the dimension of the pan evenly. Thus (h/2)*(w/2) (integer division)
   // bigger brownies will fit in the pan.
   num_big = (h/2)*(w/2);
   cout<<"A "<<h<<" X "<<w<<" inch pan can hold "<<num_small
   <<" small brownies or "<<num_big<<" large brownies.\n";
   return 0;
}

Screenshot of output:

Add a comment
Answer #2

import java.util.Scanner;


public class BrownieCalculator {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);


        // Prompt user for pan dimensions

        System.out.print("Enter the length of the baking pan (in inches): ");

        double length = scanner.nextDouble();


        System.out.print("Enter the width of the baking pan (in inches): ");

        double width = scanner.nextDouble();


        // Compute surface area of the bottom of the pan

        double surfaceArea = length * width;


        // Compute number of small and large brownies

        int smallBrownies = (int) surfaceArea;

        int largeBrownies = (int) (surfaceArea / 4);


        // Display the results

        System.out.println("A " + length + " X " + width + " inch pan can hold "

                + smallBrownies + " small brownies or " + largeBrownies + " large brownies.");


        scanner.close();

    }

}


answered by: Mayre Yıldırım
Add a comment
Know the answer?
Add Answer to:
C++ Programming Question for an intro course Complete a program that determines how many brownies will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Pr ogramming (CSC-115) Functions (pass by Reference) Programming project Using FUNCTIONS, write a C++ program...

    C++ Pr ogramming (CSC-115) Functions (pass by Reference) Programming project Using FUNCTIONS, write a C++ program that calculates the Area of a cirele, a square and a rectangle. Your program must prompt the user to select which area is to be calculated. Document your program. Apply the do while loop to repeat the program Apply the while loop for input validation. Apply the switch statements or the if/ else if statement to prompt the user for the area's selection. Based...

  • Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program...

    Please help with this Intro to programming in C assignment! Intro to Programming in C-Large Program 3 - Hangman Game Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman. You will need to: e You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of...

  • Part A) Write a C++ program that calculates the area under a curve. Here is the...

    Part A) Write a C++ program that calculates the area under a curve. Here is the equation: f(x) = x^2 +1.5x +4 You must prompt the user for the beginning and the ending x values. You are to assume, but not check, that the user will put in whole positive numbers. The units are inches. The program input/output should look something like this: This program calculates the area under a curve between two points on the x axis. The equation...

  • // Write a program that determines how many of each type of vowel are in an...

    // Write a program that determines how many of each type of vowel are in an entered string of 50 characters or less. // The program should prompt the user for a string. // The program should then sequence through the string character by character (till it gets to the NULL character) and count how many of each type of vowel are in the string. // Vowels: a, e, i, o, u. // Output the entered string, how many of...

  • Java programming 1. Write a program that reads an unspecified number of integers, determines how many...

    Java programming 1. Write a program that reads an unspecified number of integers, determines how many positive and negative value have been read, and computes the total and average of the input values (not counting zeros. Your program ends with the input 0. Display the average as a floating point number Here are sample runs: (red indicates a user input) Enter an integer, the input ends if it is 0: 1 2 -1 3 0 The number of positives is...

  • C# Programming Exercise and Bonus Exercise (Next Page) 1) Define a class called OrderPizza that has...

    C# Programming Exercise and Bonus Exercise (Next Page) 1) Define a class called OrderPizza that has member variables to track the type of pizza being order (either deep dish, hand tossed, or pan) along with the size (small, medium or large), type of toppings (pepperoni, cheese etc.) and the number of toppings. Create accessors for each property (ex.: type, size, type of toppings, and number of toppings). Implementation class should have a CalculateOrderPayment method to compute the total cost of...

  • Write a program that determines how many terms 10 students need to graduate. Step 1. Create...

    Write a program that determines how many terms 10 students need to graduate. Step 1. Create an algorithm (either flowchart or pseudocode) that you will use to write the program. Place the algorithm in a Word document. Step 2. Code the program in Eclipse and ensure the following steps are accomplished. 1.  Define a two-dimension array with 10 rows and 2 columns. 2.  Prompt the user to enter the number of courses they have left to graduate (value must be between 1...

  • (In C Programming) Your program should start by asking the user how many nodes will be...

    (In C Programming) Your program should start by asking the user how many nodes will be in the network. Nodes should be implemented by a node struct and maintained in a Linked List. •Each node should maintain all packets that have been generated and are ready to be be transmitted (one at a time). Packets should be implemented by a packet struct and maintained in a Linked List. •The protocol you will implement should run for 100 rounds. The first...

  • Write a C/C++ program that determines exactly how many hours have passed since a previous historical...

    Write a C/C++ program that determines exactly how many hours have passed since a previous historical event happened. For example, if the user entered the hour and date of the historical event (including the time of day in military format, the month in string format, the day of the month in integer format and year in 4 digit format); then your program would calculate the number of hours between then and the present time. No you should take into account...

  • Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To...

    Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To compile, build, and execute an interactive program with a simple loop, conditions, user defined functions and library functions from stdio.h and ctype.h. You will write a program that will convert characters to integers and integers to characters General Requirements • In your program you will change each letter entered by the user to both uppercase AND lowercase– o Use the function toupper in #include...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT