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
Which of the following option is not available in Insert&gt;&gt;Picture?
zysi [14]

Answer:

Word art

Explanation:

its copy and paste

7 0
3 years ago
Read 2 more answers
Trace the code below to find the two errors.
nasty-shy [4]

Answer:subtotal =.08

Explanation:

8 0
2 years ago
The tcp/ip ____ layer commonly uses the transmission control protocol (tcp) to maintain an error-free end-to-end connection.
aleksklad [387]
The answer would be the TCP/IP Application Layer.
6 0
3 years ago
Please help,
MAXImum [283]

Answer:Answer I think it might be true Explanation in the Explanation

Explanation: So I think it might be true because Ergonomics is the science of conforming the workplace and all of its elements to the worker, and in the question it says that "How a product relates to the human body", so I think it might be true, Sorry if I got this wrong.

GOOOOOOD LUUUUUCCCCCCKK

8 0
3 years ago
What did czarnowski and triantafyllou learn from observing boat propulsion systems?
noname [10]
Czarnowski and Triantafyllou learned that boat propellers are not very efficient, except penguin propulsion systems.
7 0
3 years ago
Other questions:
  • The most popular input device of a computer is a(n) ____.
    6·1 answer
  • What is a motherboard?
    6·2 answers
  • John works for Internal Computer Specialists, which focuses on helping small business owners resolve MIS infrastructure issues.
    12·1 answer
  • You maintain an RODC running Windows Server 2012 R2 at a branch office, and you want Juanita, who has solid computer knowledge,
    13·1 answer
  • Jackson is teaching the decimal number system. He wants his students to know how to expand numbers by powers of 10. Which is the
    13·2 answers
  • A cloud file system (CFS) allows users or applications to directly manipulate files that reside on the cloud.
    6·1 answer
  • Who is responsible for ensuring the security of business systems and developing strategies and safeguards against attacks by hac
    9·1 answer
  • There are many different types of documents that are used to convey information in the business world-letters and
    12·1 answer
  • Your help will help me understand my answers by comparing to yours. Your kind contribution is very much appreciated.
    6·1 answer
  • Call of duty vanguard, war zone , fornite, gta what’s your favorite
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!