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
I'm trying to connect fire stick but it doesn't have HDMI input so guys what would do you recommend to buy I tried a converter b
mihalych1998 [28]
I suggest you get a adapter from the old video input to HDMI
7 0
3 years ago
Please help I upped the points and please don't answer if you don't have the answer..
ikadub [295]

Answer:

3. Paying for my daughter to attend college and building a life outside of struggle. These goals must be accomplished by me finishing school, going onto college and maybe even starting my own business. I must set an appropriate example for my daughter to learn from someone who she believes in. Starting a family business to pass down to generations will be an excellent way to start financially planning now ahead of time.

4. Living in a family of mines, common financial resource is either government assisted or public security.An expense that I cannot escape now is the caring for of my daughter which will vary as she get older. Lastly a debt would be the over spending of credit cards with no money to pay it back as the interest rates climb.

Explanation:

3 0
3 years ago
why is this message poor or ineffective ,Due to low profits,there will be no annual year-end bonus this year. We hope to have a
Annette [7]
If it's a holiday, you should be getting a year-end bonus. They hope for you to have a new year when you aren't getting a bonus!
8 0
3 years ago
Read 2 more answers
2.<br> Fill in the blanks:<br> a) Software is a set of computer program
scoray [572]

Answer:

Software is a set of computer programs which makes computer work.

4 0
3 years ago
Which layer of the OSI model do network administrators typically check first when issues arise?
bazaltina [42]

Answer:

B

Explanation:

Typically I check the physical layer to ensure that the nodes are plugged accordingly.

4 0
2 years ago
Other questions:
  • what properties are associated with all Microsoft Office files and include author, title, and subject
    5·1 answer
  • What best compares potrait and landscape orientations
    6·1 answer
  • Question 14. (3.04 MC) how does the project manager evaluate the scope of a project
    14·1 answer
  • This assignment requires you to write a program to analyze a web page HTML file. Your program will read one character at a time
    13·1 answer
  • 2 (01.01 LC)
    5·1 answer
  • What would happen without satellites???
    12·2 answers
  • Ns.office.com/Pages/ResponsePage.aspx?id=bd8
    9·2 answers
  • What is functionality criteria or alternative word
    8·1 answer
  • Blogs may refer to any kind of communication over the internet is true​
    9·1 answer
  • A printer is considered to be in the category of
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!