Programming Exercises 1. Explain why each of the following names does or does no
ID: 3732199 • Letter: P
Question
Programming Exercises 1. Explain why each of the following names does or does not seem like a good vari- able name to represent a state sales tax rate. a. stateTaxRate b. txRt c. t d. stateSalesTaxRateValue e. state tax rate f. taxRate g. 1TaxRate h. moneyCharged If productCost and productPrice are numeric variables, and productName is a string variable, which of the following statements are valid assignments? If a statement is not valid, explain why not. a. productCost 100 b. productPrice = productCost C. productPrice = productName 2. d. productPrice "24.95" e. 15.67 = productCost f, productCost $1,345.52 g. productCost productPrice 10 h. productName "mouse pad" i. productCost 20 productPrice j. productName 3-inch nails k. productName 43 1. productName = "44" 18 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in swhole or in part WCN 02-300-302Explanation / Answer
Answer:
Question 1:
a. "StatetaxRate" is a Good Variable Name
b. "txRt" is a Good Variable Name
c. "t" is a Good Variable Name
d. "stateSalesTaxRateValue" is a Good Variable Name
e. "state tax rate" is not a good variable name because It doesn't contain spaces in it.
f. "taxRate" is a Good Variable Name.
g. "1TaxRate" is not a good variable name because It doesn't start with a numeric
h. "moneyCharged" is a Good Variable Name.
Question 2:
a. "productCost=100" is valid because 100 is assigned to a numeric variable.
b. "productPrice=productCost" is valid because assiging a numeric value stored in "productCost" to another numeric variable "productPrice"
c. "productPrice=productName" is invalid because assiging a string value stored in "productName" to numeric variable "productPrice"
d. productPrice="24.95" is invalid because assigning string "24.95" to a numeric varaible "productPrice"
e. "15.67=productCost" is invalid because while assigning a value to the variable, the variable name should be in the left hand side, and the value should be in the right hand side.
f. "productCost=$1,345.52" is invalid because special symbols ($ and , ) are not allowed in the values.
g. "productCost=productPrice-10" is valid because "productPrice-10" yield an numeric value which is assigned to another numeric variable.
h. productName="mouse pad" is valid because "mouse pad" is a string and is assigned to the string variable "productName"
i. "productCost+20=productPrice" is invalid because the left hand side of the expression should have only the variable name, and right hand side may have the expression.
j. "productName=3-inch nails" is invalid because the right hand side of the expression should have the string which is enclosed in pair of double quotes.
k. "productName=43" is invalid because a string should be enclosed in a pair of double quotes.
l. productName="44" is valid because "44" is a string which is assigned to a string variable.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.