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.
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:

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();
}
}
C++ Programming Question for an intro course Complete a program that determines how many brownies will...
Write a small program that asks the user how many asterisks it should print out. The user responds with a number, then the program prints that number of asterisks. The number of asterisks to print should be stored in a variable. Finally the program asks the user if it should start over, and repeats as many times as the user wants. The prompt to run the program again should look like the one below, and should wait at the end...
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 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 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 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 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 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 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 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...
Question: C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to prov... C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to provide practice programming using structs and pointers. Your program will accept user input and store it in a dynamic array of structs. First, you will define a structure to describe a item to be bought. Your program will prompt the user for the initial size of the array. It will...