IRM - Chapter - 6e - 02(2)

2019-04-23 19:55

Savitch

Problem Solving w/ C++, 6e Instructor’s Resource Guide

Chapter 2

boxesPerMetricTon = 1 / metricTonsPerbox;

cout << \box = \

<< metricTonsPerbox << endl;

cout << \metric ton = \

<< boxesPerMetricTon << endl;

cout << \any other character ”

<< “terminates.\endl;

cin >> ans; } return 0;

6

Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Savitch

Problem Solving w/ C++, 6e Instructor’s Resource Guide

Chapter 2

}

A sample run follows:

enter the weight in ounces of your favorite cereal: 14

metric tons per box = 0.000396905 boxes to yield a metric ton = 2519.49

Y or y continues, any other characters terminates. y

enter the weight in ounces of your favorite cereal: 20

metric tons per box = 0.000567007

7

Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Savitch

Problem Solving w/ C++, 6e Instructor’s Resource Guide

Chapter 2

boxes to yield a metric ton = 1763.65

Y or y continues, any other characters terminates. n

2. Lethal Dose

Certain artificial sweeteners are poisonous at some dosage level. It is desired to know how much soda a dieter can drink without dying. The problem statement gives no information about how to scale the amount of toxicity from the dimensions of the experimental mouse to the dimensions of the dieter. Hence the student must supply this necessary assumption as basis for the calculation.

8

Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Savitch

Problem Solving w/ C++, 6e Instructor’s Resource Guide

Chapter 2

This solution supposes the lethal dose is directly proportional to the weight of the subject, hence

weightOfDieter lethalDoseDieter = lethalDoseMouse * weightOfMouse

This program accepts weight of a lethal dose for a mouse, the weight of the mouse, and the weight of the dieter, and calculates the amount of sweetener that will just kill the dieter, based on the lethal dose for a mouse in the lab. If the student has problems with grams and pounds, a pound is 454 grams.

It is interesting that the result probably wanted is a safe number of cans, while all the data can provide is the minimum lethal number! Some

9

Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Savitch

Problem Solving w/ C++, 6e Instructor’s Resource Guide

Chapter 2

students will probably realize this, but my experience is that most will not. I just weighed a can of diet pop and subtracted the weight of an empty can. The result is about 350 grams. The label claims 355 ml, which weighs very nearly 355 grams. To get the lethal number of cans from the number of grams of sweetener, you need the number of grams of sweetener in a can of pop, and the concentration of sweetener, which the problem assumes 0.1% , that is a conversion factor of 0.001.

gramsSweetenerPerCan = 350 * 0.001 = 0.35 grams/can

cans = lethalDoseDieter / (0.35 grams / can)

10

Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


IRM - Chapter - 6e - 02(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:李春城案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: