Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
Enter the lethal dose for the mouse in grams 100
Enter the desired weight of the dieter, in grams 45400
For these parameters: mouse weight: 15 grams
lethal dose for the mouse: 100 grams
Dieter weight: 45400 grams The lethal dose in grams of sweetener is: 302667
Lethal number of cans of pop: 864762
Y or y continues, any other character quits y
16
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
Enter the weight of the mouse in grams 30
Enter the lethal dose for the mouse in grams 100
Enter the desired weight of the dieter, in grams 45400
For these parameters: mouse weight: 30 grams
lethal dose for the mouse: 100 grams
Dieter weight: 45400 grams The lethal dose in grams of sweetener is: 151333
Lethal number of cans of pop: 432381
17
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
Y or y continues, any other character quits q
17:23:56:~/AW$
3. Pay Increase
The workers have won a 7.6% pay increase, effective 6 months retroactively. This program is to accept the previous annual salary, then outputs the retroactive pay due the employee, the new annual salary, and the new monthly salary. Allow user to repeat as desired. The appropriate formulae are:
const double INCREASE = 0.076;
18
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
newSalary = salary * (1 + INCREASE);
monthly = salary / 12; retroactive = (salary – oldSalary)/2; The code follows:
//Ch2Prob3.cc
//Given 6 mos retroactive 7.6% pay increase, //input salary
//Output new annual and monthly salaries, retroactive pay #include
const double INCREASE = 0.076;
19
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
int main() {
double oldSalary, salary, monthly, retroactive; char ans;
cout << \salary.\
<< \salary, monthly ”
<< “salary, and retroactive pay.\
cin >> oldSalary;//old annual salary salary =
oldSalary*(1+INCREASE);//new annual salary
monthly = salary/12;
20
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley