Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A government research lab has concluded that certain chemicals commonly used in

ID: 3620081 • Letter: A

Question

A government research lab has concluded that certain chemicals commonly used in foods will cause death in laboratory mice. A friend of yours is desperate to lose weight but cannot give up Diet Coca-Colas. Your friend wants to know how much Diet Coca-Cola it is possible to drink without dying as a result. Write a program to supply the answer. The input to the program is the amount of artificial sweetener needed to kill a mouse, the weight of the mouse, and the weight of the dieter. To ensure the safety of your friend, be sure the program requests the weight at which the dieter will stop dieting, rather than the dieter

Explanation / Answer

First, determine what input you need from the user and how you will express it. The volume of cola consumed by the dieter is commonly expressed in Liters. The weight of the dieter is commonly expressed in pounds. The weight of the mouse will is commonly expressed in grams. The amount of sweetener needed to kill a mouse is commonly expressed in mL.

Next, request this information by using cout and cin and initialize the variables.

int nKillMouse;

int nMouseWeight;

int nDieterWeight;

cout << "Amount of artificial sweetener needed to kill a mouse in milliliters: ";

cin >> nKillMouse;

cout << endl;

cout << "Weight of the mouse in grams: ";

cin >> nMouseWeight;

cout << endl;

cout << "Weight at which the dieter will stop dieting in pounds: ";

cin >> nDieterWeight;

cout << endl;

Next, use a convsion for the weight of the mouse from grams to pounds, so calculation of the dieter’s weight will agree. Be sure to use the double data type to avoid overflow. The conversion is:

double dgTolb = 0.0022046226 /*pounds*/ / 1 /*grams*/;

Next, determine the amount of mililiters per pound of sweetener was consumed by the mouse by dividing the amount of sweetener consumed by the mouse by the converted weight of the mouse:

double dToxicConc = nKillMouse / (nMouseWeight * dgTolb);

Then find the amount of sweetener needed to kill at the dieters weight by multiplying the weight of the dieter by the Toxic concentration (nToxicConc).

double dToxicAmount = nDieterWeight * dToxicConc;

Next, find the amount of cola that can be consumed by the dieter before dying by multiplying the amount of sweetener needed to kill the dieter (dToxicAmount) by 1000, since the sweetener consists of one-thousandth of the cola or 1/10th of 1 percent, which is 0.001.

double dColaAmountmL = dToxicAmount * 1000;

Then convert the amount of cola needed to kill from mililiters to liters by dividing by 1000:

double dColaAmountL = dColaAmountmL / 1000;

Finally, print the findings on the screen by using cout.

cout << "Upto " << dColaAmountL << " Liters of Diet Coca-Cola can be consumed without dying." << endl;

The full program is as follows:

#include "stdafx.h"

#include "iostream"

int _tmain(int argc, _TCHAR* argv[])

{

      using namespace std;

      int nKillMouse;

      int nMouseWeight;

      int nDieterWeight;

      cout << "Amount of artificial sweetener needed to kill a mouse in milliliters: ";

      cin >> nKillMouse;

      cout << endl;

      cout << "Weight of the mouse in grams: ";

      cin >> nMouseWeight;

      cout << endl;

      cout << "Weight at which the dieter will stop dieting in pounds: ";

      cin >> nDieterWeight;

      cout << endl;

      double dgTolb = 0.0022046226 /*pounds*/ / 1 /*grams*/; //Coverts grams to pounds

      double dToxicConc = nKillMouse / (nMouseWeight * dgTolb); //mL of sweetener to kill per pound

      double dToxicAmount = nDieterWeight * dToxicConc; //Amount of sweetener in mL to kill dieter based on the dieter's weight

      double dColaAmountmL = dToxicAmount * 1000; //Amount of cola that will kill in mL

      double dColaAmountL = dColaAmountmL / 1000; //Amount of cola that will kill in L

      cout << "Upto " << dColaAmountL << " Liters of Diet Coca-Cola can be consumed without dying." << endl;

      return 0;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote