The Program Extension

xiaoxiao2021-03-06  129

Problem Description:

A manufactured item can have one of the solid shapes cone, cylinder or rectangle and can be made from one of a number of materials, such as plastic or metal. Write a program to input the density of the material and the shape and dimensions of the item and to display the weight of the item (Hint:. Different shapes will require different dimensions to be input and different calculations to be performed to calculate the volume Firstly, ask the user to specify the shape, and then use a switch statement to. Allow The Program To Perform Input and Calculation Specific To That Shape.)

My opinin:

Shall I use a structure to store the item information? For example, store the length, width and height of a rectangle, even the equation to calculating the weight. That will have a good extention. However, the problem is that the elements of the structure is changable For example, a cyclinder has only two element:. radius and height to calculate its cubage while a rectangle needs three:. length, width, height How can I solve this problem If the problem is solved, there is no need? TO Modify The Code WHEN A NEW ITEM IS ADDED. OtherWise, We Have No Choice But To Rewrite The Code. Which Way Should i Follow?

Timwang - China

August 18,2004

转载请注明原文地址:https://www.9cbs.com/read-125690.html

New Post(0)