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]
2 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]2 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
This type of connection uses radio waves to connect devices on a network.
Tresset [83]
I believe data carries radio waves
5 0
3 years ago
Read 2 more answers
Give four advantages for ssd compared to hdd
Goshia [24]

Answer:

Explanation:

SSD is not affected by magnets

SSD is more reliable because it uses flash technology instead of platters and arms.

SSD has no moving parts so it has less chance of breaking down

SSD makes no noise because it has no moving parts.

6 0
2 years ago
Read 2 more answers
Which save as element allows a user to save a presentation on a computer?
s344n2d4d5 [400]

Answer:

This PC

Explanation:

Got it right

7 0
3 years ago
Read 2 more answers
When connecting to the internet, most internet users connect to a tier 1 network.​?
denis23 [38]
False

Tier 1 ISPs exchanges traffic with other tier 1 internet traffic providers and are the backbone of the internet. They do not provide traffic to end users but provide internet to other ISPs. Tier 3 is the last mile provider who delivers internet access to homes and businesses.



8 0
3 years ago
BJP4 Self-Check 7.21: swapPairs<br><br> plsssss
Vedmedyk [2.9K]

Answer:

needs more expiation

Explanation:

add a worksheet to the question

6 0
2 years ago
Other questions:
  • A ________ restricts the number of a certain type of product that can be imported into a country.
    5·1 answer
  • A(n) ____ is the computer counterpart to an ordinary paper file you might keep in a file cabinet or an accounting ledger.a. data
    6·1 answer
  • Which of the following controls will provide an area in the form for the user to enter a name? a. button b. label c. text box d.
    8·1 answer
  • What are the ethical implications of online social media after someone has died
    8·2 answers
  • Why is population composition by age important give reason​
    13·1 answer
  • Knowing the meaning of the acronym WAS I WHY can be most helpful to you when you?
    14·1 answer
  • Write a python program that should determine from the range you choose to enter :
    9·1 answer
  • Which type of file can be opened directly into Excel?
    15·1 answer
  • A(n) ________ cloud does not free an organization from the issues associated with managing the cloud infrastructure, but it does
    7·1 answer
  • How to implement switch statement in Python?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!