Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 5 - Computing a Shipment Now that you can compute the volume of the caramel center (using the volume of a sphere function) and

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Part 5 - Computing a Shipment Now that you can compute the volume of the caramel center (using the volume of a sphere function) and the chocolate shell (using your new function), you can finally make a program that computes orders! Oompa, Loompa, doom-pa-dee doo Ship the orders or they will sue. Oompa, Loompa, doom-pa-dee dee. We're a business - make some money! Seriously, what is wrong with those guys?! You going to compute the caramel and chocolate needed for a large for a shipment of candy. To accomplish this, you need to compute the required chocolate and caramel and store those values into variables. Then, you can multiply those values by the total number of candies that will be produced. Ta da! 1. Select all the shapes in your main function 2. Delete them (they were just for testing anyway) 3. Declare real variables that will store the amount of chocolate and caramel in a single candy 4. Declare a variable that represents the total number of candies to be produced. Think about what data type it should be. 7 5. Declare real variables for the two diameters - the whole candy and the caramel center. 6. Input both diameters. Give them nice prompts. 7. Input the total number of candies with a nice prompt. 8. Call your two functions - the volume of a sphere function and the volume of a shell function. Store the results. This will be for a single candy. 9. Oh wait! You still need something to store the total amount chocolate and caramel. Curses. Add those declarations too. 10. Compute the total amount of chocolate and caramel for the shipment. (hint: total chocolate = chocolate in one candy * the number of candies) 11. Now, output the results with nice labels. 12. Execute and test your program! Great job! Your flowchart has made Willy Wonka quite happy! Perhaps you can get a raise - or perhaps - one of those Everlasting Gobstoppers!Part 3 - Geometry Ah, geometry! As a computer programmer, you will get to use it on a regular basis. Not only is it a great way of measuring and analyzing real world problems - but makes incredibly easy to create lab activities (at least for us instructors). Some geometric shapes are more common place than others. In particular, simple geometric shapes such as cubes and spheres can be used (and often are) to create larger objects. Just look at Minecraft! Alright, alright... let's get to it! 4 Let's take a look at a sphere. If you forgot, the volume of a sphere can be computed with the following mathematical expression: Diameter Volume 3 3 2 Wait, wait, wait! Isn't that supposed to be radius? Why diameter divided by 2? Well, the two are the same thing. This formula uses a diameter for a neat project we will work on a sec. Also note that this expression contains PI. Fortunately, Flowgorithm (like most programming languages) has that constant built-in for you. In the case of Flowgorithm, you can just use: pi. 1. Add a new function called sphere or sphereVolume or something clever (the name is up to you). 2. Add a parameter for the diameter. Make it a real. 3. Calculate the volume of a sphere, and return that value. Ah, now that you have written such a nice function, it is time to check if it works correctly. Look at the following pseudocode (written in the book's format). It uses a function called sphereVolume (you might have named yours something different - and that's perfectly okay).Example Puudocode ModuIe main Declare Reel d Input d Display sphereVolumI [d] Ind Module This program declares a real variable called (I. Inputs it. and then displays the result of the function. This is a great technique for testing if you got the expression correct. 4. You main function should be blank. Implement the pseudooode above. 5. Execute it your owchart and test it with a few values. 6. Check your results with the table below 523.593333333332 1T6? .146025 4] 186 .79066666666 Did everything match up? If 30.... great work! It's time to move on. Otherwise, go back to your sphere function and double-check the expression. Part 4- Flowcharts and the Chocolate Factom You have a really cool job at a candy factory. The factory can make custom candies for anyone in the World. The only downside is the constant singing of the Oompa Loompas. Comps, Loompa, doom-ps-dee doc. Computer science is a talent of you. Comps, Loompa, doom-ps-dee dee. Using functions - it's so easy! They need to go on strike. You work in the division that creates chocolate-covered caramels. The factory equipment can create chocolate-cara mels of any size - and does so regularly. They can be as small as a pea or as big as a house. The company's main problem is determining how much chocolate and caramel will be needed fora shipment. Fortunately, you can write a program that will solve this dilemma! Let's look at the type of candy you are creating: chocolate-covered caramels. Basically, these are spheres. However, there is a catch Both the caramel center and the candy itself are spheres, but what exactly is the volume of the chocolate shell? It's denitely not the volume of a sphere with the full diameter. The center doesn*t take up delicious chocolate... it is delicious caramel! Diameter of Caramel Okay, time to put on your thinking cap (which, in this case, looks like crazy oompa-Ioompa wig). You need to gure out how to compute the volume of the chocolate shell. Let's create a new function that will get us this value! Miami a m0; 1. Add a new function 2. Give it a name - it's up to you. 3. For para meters, you want to pass in the total diameter of the larger sphere E the diameter of the internal sphere. Wait a sec! Didn't you already create a function for a sphere? Use that in your new function! 4. Using your existing sphere function, compute and return the volume of the shell. Ah, now that you nished that. It's time to test it and make sure the values look correctl Testing is an important part of being a great computer programmer. 5. Modify your main program so you can type in 2 values - the outside diameter and the inside diameter. The pseudocode is below. Again. the pseudocode may use a different function than you created. ...And again. it is perfectly okay. Don't' rename your function. 6 Example Pseudocode Module main Declare Real d Declare Real i Input d Input i Display sphereShell (d, i) End Module 6. Execute your flowchart. Check your results with the table below. Outside Diameter Inside Diameter Volume 1 0. 5 0 . 458148979166665 2 1 3. 66519183333333 1.9 0. 59742626883333 20 12 3284 . 01188266666 100 99 15551 . 4089488329 Did you get the correct results? If not double check your logic, your parameters, your data types etc.... Part of being a good programmer is being able to diagnose if a program isn't working right and figuring out why. Yes, sometimes programmers act like Sherlock Holmes So, if your data was correct then great work! If not, then you have a great chance to get some experience debugging! Trust me, it's a good thing.Part 6 - Running Total Your program is quite impressive now. However, let's make it a tad more sophisticated. If you are successful, perhaps the Oompa Loompas will stop singing to you. We can only hope. Currently, the program just reads in values and outputs the results for a single shipment. What if they want to handle multiple orders? In other words, can't we just have the program loop until we are done entering data? Well, that was the whole idea of the loops you have been writing - so yes! You are going to need a few more variables and a loop. After each shipment, you can ask the user if they need to enter another. You did a great job with the "Do you want to enter another" logic in a previous activity. So, let's use it again. 1. So, create a string variable called again, more, or a something else (the name is up to you). Since we are going to compute an entire shipment, we need new variables to store the grand totals for the chocolate and caramel needed. These values will start at zero and increase for each order. 2. Create these two variables. Give them good names. 3. Select your existing shapes - not the declarations. These should include the input, output and assignment shapes. 4. Cut them. 5. Add a Do Loop to your flowchart. 6. Paste them into the Do Loop. 7. Before the loop, initialize both of your new totals to zero. B. Inside your loop, after the rest of the shapes, add the running total logic. This way, each time you compute the total chocolate and caramel needed for a shipment, they are added to the grand totals. 9. Okay, now we need to ask the user if they want another shipment. Input that string variable you declared earlier. Add a nice prompt. 10. Set up the Do Loop logic so it continues while: again == "y". (Of course, you might have named it something different 11. Finally, print of the grand totals for the chocolate and caramel after the loop completes. Add some nice labels. Like before, go to the Tools Menu on Flowgorithm and select "Layout Windows" (you can also press Control+L). This time select "Variables & Console"

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

Step: 3

blur-text-image

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

More Books

Students also viewed these General Management questions

Question

What is overfitting? Why is it so important to watch out for?

Answered: 1 week ago

Question

2. To store it and

Answered: 1 week ago