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
Eva8 [605]
3 years ago
5

Write a C console application that will be used to determine if rectangular packages can fit inside one of a set of spheres. You

r program will prompt the user for the three dimensions that define a rectangular box; the length, the width, and the height. The interior diameter of a sphere is used to identify its size. Spheres are available in the following five sizes: 4- inch, 6-inch, 8-inch, 10-inch, and 12-inch. Your program will execute repeatedly until the user enters a value of zero for one or more of the rectangular box dimensions. After obtaining the dimensions of the rectangular box, your program will call a function named getSphereSize that determines if the box will fit inside one of the five spheres. The formula for calculating the diagonal of a rectangular box is:
Computers and Technology
1 answer:
MatroZZZ [7]3 years ago
7 0

Answer:

#include <cmath>

#include <iostream>

using namespace std;

int getSphereSize(double length, double breadth, double height) {

   double diagonal = sqrt(length * length + breadth * breadth + height * height);

   if (diagonal <= 4)

       return 4;

   if (diagonal <= 6)

       return 6;

   if (diagonal <= 8)

       return 8;

   if (diagonal <= 10)

       return 10;

   if (diagonal <= 12)

       return 12;

   return 0;

}

int main() {

   double length, breadth, height;

   int sphereCounts[5] = {0};

   int sphereSize;

   while (true) {

       // Get dimensions of the box

       cout << "Enter the dimensions of the box:\n";

       cout << "Length: ";

       cin >> length;

       cout << "Breadth: ";

       cin >> breadth;

       cout << "Height: ";

       cin >> height;

       if (length <= 0 || breadth <= 0 || height <= 0)

           break;

       sphereSize = getSphereSize(length, breadth, height);

       if (sphereSize == 0)

           cout << "The box cannot fit in any of the spheres";

       else

           cout << "The box can fit in the " << sphereSize << "-inch sphere";

       // Increment the counter

       if (sphereSize == 4)

           sphereCounts[0]++;

       else if (sphereSize == 6)

           sphereCounts[1]++;

       else if (sphereSize == 8)

           sphereCounts[2]++;

       else if (sphereSize == 10)

           sphereCounts[3]++;

       else if (sphereSize == 12)

           sphereCounts[4]++;

       cout << "\n\n";

   }

   cout << "\nNumber of 4-inch spheres: " << sphereCounts[0];

   cout << "\nNumber of 6-inch spheres: " << sphereCounts[1];

   cout << "\nNumber of 8-inch spheres: " << sphereCounts[2];

   cout << "\nNumber of 10-inch spheres: " << sphereCounts[3];

   cout << "\nNumber of 12-inch spheres: " << sphereCounts[4];

   cout << endl;

   return 0;

}

Explanation:

The "cmath" library is included in the c++ program. The getSphereSize function is used to return the sphere size the rectangle dimension can fit into. It program continuously prompts the user for the length, breadth, and height of the rectangle and passes the values to the getSphereSize function in the while but breaks if any or all of the variable value is zero.

The sizes of the sphere objects in inches are collected in an array of five integer values of zeros and are incremented by one for every match with a rectangle.

You might be interested in
If the catch-or-declare requirement for a checked exception is not satisfied ________. a. a stack trace will be displayed indica
irakobra [83]

Answer: I think the answer is B. the compiler will issue an error message indicating that the exception must be caught or declared.

Explanation:

7 0
3 years ago
What is Naptha used for?
denis-greek [22]

Answer:

Naphtha is used to dilute heavy crude oil to reduce its viscosity and enable/facilitate transport; undiluted heavy crude cannot normally be transported by pipeline, and may also be difficult to pump onto oil tankers. Other common dilutants include natural-gas condensate, and light crude.

7 0
3 years ago
Read 2 more answers
-Define three types of user mode to kernel mode transfers?
Ivahew [28]

Answer:

 The three types of user mode to the kernel mode transferred occurred due to the:

  • It is mainly occurred due to the interrupt when, it send to the central processing unit (CPU).
  • It also occurs due to the hardware exception and when the memory is access illegally as it is divided by the zero.
  • It is mainly implemented or executed by the trap instruction as the system are basically executed by the program.
7 0
3 years ago
What happens by default when you copy a formula from one cell to another cell?
natta225 [31]
By default, all cell references are relative references. When copiedacross multiple cells, they change based on the relative position of rows and columns. For example, if you copy the formula =A1+B1 from row 1 to row 2, the formula will become =A2+B2.
8 0
3 years ago
Based on the net income of the shop, the sales staff at Francesca's Fashions receive performance bonuses. In periods of declinin
Lena [83]

<u>Answer</u>:   A : LIFO

<em>LIFO stands for Last in First Out</em>

<em>LIFO accounting is method which is applied in United States. All the other countries use FIFO (First in First Out). </em>

<u>Explanation:</u>

<em>A LIFO method believes that the last entered item in the inventory will be first item which would have been sold.</em> It is significant to track the inventory costs, in order to take the business expenses into account and those can be deducted from the business tax.

Suppose there is an entry like below

<em>Batch 1: 1500 products produced Costs 4000 </em>

<em>Batch 2: 2000 products produced Costs 2500 </em>

<em>Batch 3: 3200 products produced Costs 3500 </em>

So LIFO assumes that Batch 3 is the first entry.

3 0
3 years ago
Other questions:
  • Select the answer that best describes what an opportunity cost is?
    8·2 answers
  • What would be one advantage and one risk of using an electric car?
    14·2 answers
  • Which css property is used to change the text color of an element?
    15·1 answer
  • Do anti viruses install themselves on other computers in the network
    6·1 answer
  • Which method would provide you with pictures you could upload from a disc that you insert in your computer?
    8·1 answer
  • Which statement about images is correct? A) A virtual image cannot be formed on a screen. B) A virtual image cannot be viewed by
    12·1 answer
  • What are the benefits of using an ordered list vs. an unordered list? What are the costs?
    10·1 answer
  • Which of these statements best compares P waves and S waves of an earthquake?
    5·1 answer
  • Write a program num2rome.cpp that converts a positive integer into the Roman number system. The Roman number system has digits I
    8·1 answer
  • Brainly app won't let me watch ads anymore. I search my question and there is no skip button to watch an ad it only makes me buy
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!