Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c code please 7_28 Nllow the uscr to chooose whether to calculate a circle's circumference, a circle's arcia or a sphere's volurne. The program should

c code please

7_28

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Nllow the uscr to chooose whether to calculate a circle's circumference, a circle's arcia or a sphere's volurne. The program should then input a radius from the user, perform the appropriate calculation and display the resulc. Usc an array of function poincers in which cach pointer repressents a function that returns vaid and receives a double paramcter. The corresponding functions should each display messuges indicating which calculation was performed, the value of the radius and the resule of the calculation. 7.26 (Calculater Using Function Pointers) Using the tochniques you learned in Hig. 7.18, create a menu-driven program that allows the user to choose whether to add, subcract, multiply or divide rwo numbers. The program should then input two double values from the user, perform the appropriate calculation and display the result. Use an array of funcrion pointers in which each pointer represents a funcrion that returns void and receives two double parameters. The corresponding functions should each display messages indicating which calculation was performed, the values of the paramerers and the result of the calculation. 7.27 (Carbon Foorprinu Calcularor) Using arrays of function pointers, as you learned in this chapter, you can specify a set of functions that are called with the same types of arguments and retum the same type of data. Govemments and companies worldwide are beconuing increasingly concerned with carbon footprints (annual releases of carbon dioxide into the atmosphere) from huildings harning various rypes of fuels for heat, vehicles burning fucts for power, and the like. Many scicntists blane these grounhouse gases for the phenomenon called global warming. Crease three functions that help calculate che carbon footprint of a building a car and a bicycle, rcspectivcly. Fach function should input appropriate data from the user, then calculate and display the carbon footprint. (Check out a few wcbsitcs that explain how to calculate carbon footprints.) Each function should receive no parameters and return vond. Write a program that prompts the user to enter the rype of carbon footprint to calculate, then calls the corresponding function in the array of function pointers. For each type of carbon footprint, display some identifying information and the object's carhon footprint. Special Section-Building Your Own Computer as a Virtual Machine In the next several exercises, we take a temporary diversion away from the world of high-level language programming. We "pecl open" a fake simple computer and look at its internal structure. We introduce machine-language programaning for this computer and write scveral machine-language programs. To make this an especially valuable experience, we then build a software-based simulation of this computer on which you actually can execute your machinc-language programs! Such a simulated computer is often called a virtual machine. 7.28 (Madvine-Language Programuing) Let's create a computcr wc'll call the Simpletron. As its name implies, it's a simple machine, but as we'll soon see, it's a powerful one as well. The Simpletron runs programs written in the only language it directly understands - that is, Simpletron Machine Language, or SML for short. Special Section-Building Your Own Computer as a Virtual Machine 363 The Simpletron contains an accumulator a "spccial rcgistcr" in which information is put before the Simpletron uses that information in calculations or examines it in various ways. All information in the Simpletron is handled in terms of words. word is a signed four-eligit decimal number sech as +3364,1293,+000/,0001, etc. 'The Simpletron is cquipped with a 100 -word memory, and these words are rcferenced by their location numbers 00,01,,99. Before runaing an SML program, we must load or place the program inco memory. The first instruction (or statement) of every \$ML program is always placed in location 00. Each SML instruction occupies one word of the Simpletron's memory, so instructions are signed four-digit decimal numhers. We assurne an SML. instruction's sign is always plus, but a data word's sign may he plus or minus. Fach Simplerron mennory location may contain an instruction, a data value used by a program or an unused (and hence undefined) area of memory. F.ach SMT. instrucrion's first two digits ate the operation code specifying the operation to perform. The SML opera rion codes are summarized in the following table: Sample SML Program That Adds Two Numbers Let's consider several simple SML programs. The following SML program reads two numbers from dhe keyboard, then computcs and prints thcir sum: The instruction +1097 reads the first number from the keybexatel and places it into location 07 . Then +1008 reads the next number into location 08 . The load instruction, +2007, copies the first number into the accumulator. The add instruction, +3008, adds the second number to the number in the accumulator. ADI SML aribimesic insructions leave their nsults in the accumulator, The ssare instruction, +2109,00 ies the result from the accumulator into memory location 09 , from which the wrise instruction, +1109, then takes the number and prints it as a signed four-digir decimal number to the screen. The hall instruction, +4300, terminates execution. Sample SML Program That Determines the Largest of Two Values The next SML. program reads two numbers from the keyhoard, then determines and prines the larger value: Special Section-Building Your Own Computer as a Virtual Machine 365 The instruction +1107 is a conditional transfer of control, like an if statenent. Now write SML programs to accomplish each of the following tasks. a) Usc a scntincl-controlled loop to rcad positive intcgers, then compute and print their sum. b) Usc a councer-controlled loop to read seven numbers, some positive and some negative. Compute and print their average. c) Read a series of numbers. Determine and print che largest number. The first number read indicates how many numbers should be processed. 7.29 (A Computer Simulator) It may at first secm outrageous, but in this cxcrcise you'll build your own computer. No, you won't be soldering, components together. Rather, you'll use the powerful technique of software-hased simulation to create a software model of the Simpletron. You will not be disappointed. Your Simpletron simulator will turn the computer you're using into a Simpletron, and you'll actually be able to run, test and debug the SML programs you wrote in Exercise 7.28! When you run your Simpletron simulator, it should begin by printing: Simulate the memory of the Simpletron with a 100 -element one-dimensional array menory. Now assume that the simulator is running, and let's examine the dialog as we enter the program of Example 2 of Exercise 7,28 : The SMI. program has now heen placed (or kaded) into the array nenory. Next, the Simpletron executes the SML program. It begins with the instruction in location

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

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions