Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am a bit confused as to how I would incorporate classes into this assignment, specifically the pointers with the treasure class are given me

I am a bit confused as to how I would incorporate classes into this assignment, specifically the pointers with the treasure class are given me a hard time. Would appreciate any help.

image text in transcribed

King Hicro II of Syracuse has hired you to write a program to detemine whether or not the gold expected density and the tolerance (which will be 1% or 0.01). The isPure method should return the Boolean value of true or false depending on the outcome of the above test for being within Wikipedia and can use your new found knowledge that the density of pure gold is 19.32 grams per cubic centimeter (as measured on earth). For the decision, you will need a function that takes both the weight and the volune of the ite and returns true or false depending on whether the punty is within 1% of the expected density That means they can be up 1% more or less than the expected density and still be considered pure by King Hier II hough not by Swiss bankers, whose standards are somewhat higher). To make the detemination, compute the density in grams per CC, and compare the result to the known density of gold. 19.3 grams per CC, times 1 minus the tolerance or 0.99 (it must be greater than this minimum) and 19.3 times 1 plus the toleance or 1.01 t must be less than this To support the use of the isPure method, give the Treasure class four constants in the public part of the class declaration, called GOLD, SILVER. ONE PERCENT, and TENTH_PERCENT The GOLD constant should be initialized to the density of pure gold in grams per CC which is 19.3. The SILVER constant should be initialized to the density of pure silver in grams per CC which is 10.5. One percent is 0.01, while a tenth of a percent is 0.001. In C-. dass constants other than int have to be declared with a special type, which is constex (Because C++ is closer to hardware than Java, this special type refers to something about the underlying hardware implementation.) Here is what it should look like for the GOLD constant Unfortunately, you don't have a scale that measures the weight of large items in grams. But the scale at a nearby Publix can measure the weight in pounds. Not to worry, in your programming class, you leamed how to create objects that can use more than one kind of units. So your Weight class must include both tAsGrams0 and sstAsPounds0 methods. statis const double GOLD 193 By having these constants in the Treasure class your main can call isPure in either of the two if (rownisPure(Treasue GOLD. Treasure ONE PERCENT or them in your bathtub to see how much water they displace You have already marked your bathtub for measurement in gallons. Again, no big deal. You can create a Volume class with Your assignment's main class should have a static public void function called test reasu that prompts for and reads two values, the weight in pounds and the volume in gallons. The values given by the user may include a fractional part?The main class is the only place in your code that should interact with the user) The code in testTreasure should then put these values into objects of the appropriate class (Weight and Volume), and thea give those objects to an object of the Treasure class. Finally, it should call the isPure function to perform the test. At the end it should report whether or not it is pure gold. You may use a loop in the main0 function that calls test Treasure several times to test differeat ites while the program is still running, but that is not To convert gallons to cubic centimeters, you should perform the calculation in two steps. First gal o liters, at 3.785 liters per gallon, and then liters to cubic centimetes, at 1000 cubic centimeters per liter. Similarly to convert pounds to grams, you can convert pounds to ounces at 16 ounces per pound, and then ounces to grams at 28.35 grams per ounce. Choose an intermal For this project, create a third class called Treasure. That class should have two variables for the item's weight and volume which should be pointers to a Weight and a Volume object To set these two objects, it should have two setters that also take pointers. It does not need getters for As a test, 3 gallons of gold weighing 480 pounds should test pure

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions