19.06.2013 Views

Starting Out with C++: Early Objects - EEMB DERSLER

Starting Out with C++: Early Objects - EEMB DERSLER

Starting Out with C++: Early Objects - EEMB DERSLER

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

cubicYards = cubicFeet / 27<br />

totalPrice = cubicYards * PRICE_PER_CUBIC_YD<br />

Display cubicYards, PRICE_PER_CUBIC_YD, and totalPrice<br />

The Program<br />

Green Fields Landscaping Case Study—Part 1 141<br />

The next step, after the pseudocode has been checked for logic errors, is to expand the<br />

pseudocode into the final program. This is shown in Program 3-37.<br />

Program 3-37<br />

1 // Program used by Green Fields Landscaping to determine the number of<br />

2 // cubic yards of mulch a customer needs and its price.<br />

3 #include <br />

4 #include <br />

5 using namespace std;<br />

6<br />

7 const double PRICE_PER_CUBIC_YD = 22.00;<br />

8<br />

9 int main()<br />

10 {<br />

11 double squareFeet; // square feet of land to be covered<br />

12 int depth; // inches deep the mulch is to be spread<br />

13 double cubicFeet, // number of cubic feet of mulch needed<br />

14 cubicYards, // number of cubic yards of mulch needed<br />

15 totalPrice; // total price for all the cubic yards ordered<br />

16<br />

17 // Get inputs<br />

18 cout > squareFeet;<br />

20 cout > depth;<br />

22<br />

23 // Perform calculations<br />

24 cubicFeet = squareFeet * (depth / 12.0);<br />

25 cubicYards = cubicFeet / 27;<br />

26 totalPrice = cubicYards * PRICE_PER_CUBIC_YD;<br />

27<br />

28 // Display outputs<br />

29 cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!