Logic7e_Solutions_ch02 - Programming Logic and Design 7e...

This preview shows page 1 - 4 out of 26 pages.

Programming Logic and Design, 7eSolutions 2-1Programming Logic and Design, 7th EditionChapter 2Exercises1.Explain why each of the following names does or does not seem like a good variable name to you.
2.If productCostand productPriceare numeric variables, and productNameis a string variable, which of the following statements are valid assignments? If a statement is not valid, explain why not.
Programming Logic and Design, 7eSolutions 2-2punctuation.g.productCost = productPrice -10Validh.productName = “mouse pad”Validi.productCost + 20 = productPriceNot valid. Value on left must represent an address.j.productName = 3-inch nailsNot valid. String constant must be placed within quotes.k.productName = 43Not valid Variable on left is a string but valueon right is numeric.l.productName = “44”Valid.m.“99” = productNameNot valid. Value on left must represent an address.n.productName = brushNot valid. String constant must appear withinquotes.o.battery = productNameNot valid. Value on left is not a declared variable.p.productPrice = productPriceValid, but trivial.q.productName = productCostValid.3.Assume that income = 8and expense = 6. What is the value of each of the following expressions?Answer: a.income + expense * 220b.income + 4 – expense / 29c.(income + expense) * 228d.income – 3 * 2 + expense8e.4 * ((income – expense) + 2) + 1026
Programming Logic and Design, 7eSolutions 2-3

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture