Question

Create a C++ to calculate how many circles can fit in a square. Ask the user...

Create a C++ to calculate how many circles can fit in a square. Ask the user for the side of the square and the diameter of the circle. Tell the user how many of those circles can fit in the square. They do not have to be full circles. For instance, the answer can be 2.79.

Use 3.14159265358979 for the value of PI and PI must be a constant

Format your output to display two decimals.

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

C++ CODE:

#include <iomanip>
#include <iostream>
using namespace std;
int main() {
    const double PI = 3.14159265358979;
    double side, diameter, squareArea, circleArea;
    double n;  // Number of circles that can fit inside the square
    // Input
    cout << "Enter side of the square: ";
    cin >> side;
    cout << "Enter diameter of the circle: ";
    cin >> diameter;
    // Calculations
    squareArea = side * side;
    circleArea = PI * (diameter / 2) * (diameter / 2);
    n = squareArea / circleArea;
    // Output
    cout << "Circles that can fit in the square: " << setprecision(2) << fixed << n << endl;
    return 0;
}

SAMPLE OUTPUTS:

FOR ANY HELP JUST DROP A COMMENT

Add a comment
Know the answer?
Add Answer to:
Create a C++ to calculate how many circles can fit in a square. Ask the user...
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
  • In C++ please Create a coin-flipping game. Ask the user how many times to flip the...

    In C++ please Create a coin-flipping game. Ask the user how many times to flip the coin, and use the random function to determine heads or tails each time a coin is flipped. Assume the user starts with $50. Every time the coin is flipped calculate the total (heads +$10, tails -$10). Create another function to test if the user has gone broke yet (THIS FUNCTION MUST RETURN A BOOLEAN TRUE/FALSE VALUE). End the program when the user is broke...

  • write a program code that asks the user how many numbers they wish to find the...

    write a program code that asks the user how many numbers they wish to find the statistics of and then asks the user to enter those numbers. The program must then calculate and display the average variance and standard deviation of the numbers entered by the user. the program code must -ask three user how many numbers they wish to find the statistics of -ask the user to enter those numbers and store them in an array - use a...

  • Create two java programs. The first will ask the user to enter three integers. Once the...

    Create two java programs. The first will ask the user to enter three integers. Once the three integers are entered, ask the user to enter one of three functions. The “average” if they want the average of the three numbers entered, enter “min” if they want the minimum and “max” if they want the maximum. Display the answer. Ask the user if they want to calculate another function for the three numbers. If so, loop and ask what function they...

  • C programming Ask the user how many numbers they would like generated. Your program will then...

    C programming Ask the user how many numbers they would like generated. Your program will then generate that many numbers (between 0 and 1000, inclusive) into an array of the same size. Find the smallest and largest numbers in the array, printing out the values and locations of those numbers in the array. Then, find the sum and average of the numbers in the array. Finally, print out the entire array to verify. You MUST use functions where appropriate!

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

  • Create a code that performs the following actions: l. Define the flow rate and height of tank 2./ Have the user input a value for radius 3./ Ask the user for a value of many minutes the tan...

    Create a code that performs the following actions: l. Define the flow rate and height of tank 2./ Have the user input a value for radius 3./ Ask the user for a value of many minutes the tank should fill for 4. Clear the command window (clc) after all of the input commands are given 5. Call in a "tank solver" function that performs the following Takes F, h, r, and t final as inputs, and there are no variable...

  • Write a C Language Program that will ask the user how many elements the "maxminarray" will...

    Write a C Language Program that will ask the user how many elements the "maxminarray" will have. Read the elements from user and fill the "maxminarray” with it. Find maximum value and minimum value in maxminarray See the output below: Input number of elements of the array :6 Input 6 elements for the maxminarray : element [0]: 23 element [1] : 56 element [2] : 11 element [3]: 78 element [4]: 21 element [5]: 400 The Maximum element is :...

  • Skills Needed: cin, cout, constants, arithmetic expressions, rounding, int main, meaningful variable names, spacing, indentation, documentation,...

    Skills Needed: cin, cout, constants, arithmetic expressions, rounding, int main, meaningful variable names, spacing, indentation, documentation, output. Computing Basic Geometric Formulas Write a program to compute answers to some basic geometry formulas. The program prompts the user to input a length (in centimeters) specified as a floating point value. The program then echoes the input and computes areas of squares and circles and the volume of a cube. For the squares, you will assume that the input length value is...

  • Please write a Java program that ask the user how many beers he or she expects...

    Please write a Java program that ask the user how many beers he or she expects to consume each day, on average, as well as the average amount of money he or she spends on a single 12-ounce can of beer. Studies have shown that, on average, someone who consumes a single 12-ounce can of beer every day without compensating for the calorie intake through diet modifications or extra exercise, will gain approximately 15 pounds in one year. You can...

  • Write a program and flowchart. The program should ask the user how many customers they want...

    Write a program and flowchart. The program should ask the user how many customers they want to track. Then, it asks for customer numbers, and sales by customer. At the end, it prints out the customer number, the customer sales, and then the total sales and average sales. You must use two different arrays, one for customer number, and one for sales. These are, in effect, parallel arrays.   You must use a "while" loop to gather customer number and sales....

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