1: Which of the following names seem like good variable names to you? If a name
ID: 3626202 • Letter: 1
Question
1: Which of the following names seem like good variable names to you? If a name doesn’t seem like a good variable name, explain why not.
a) C
The Variable is too short and lacks description
b) Cost
The word “cost” is a great variable because the value of a variable can be changed and this word still gives you a good idea as to what it alludes to.
c) CostAmount
This one does give good description; although, it does not use the Hump configuration
d) Cost amount
This word “Cost Amount” does not work because it has a space and the first letter of each word is capitalized.
e) Cstofdngbsns
This term “Cstofdnghbsns” is garbage and is usually displayed when the value is unknown.
f) costOfDoingbusinessThisFiscalYear
This one does not work because to me its way too long; although, it does explain its selfs its just too long.
g) costYear2012
This variable is perfect it has the numbers after the letters, and the letters have the hump.
h) 2012YearCost
This does not work because it has the numbers before the letters and each first word is capitalized.
2: If myAge and yourRate are numeric variables, and departmentName is a string variables, which of the following statements are valid assignments? If a statement is not valid , explain why not.
a) myAge = 23
Valid
b) myAge = YourRate
Invalid, myAge cannot be equal to your rate because myAge is a numeric constant nmyAge = departmentName
c) 42 = myAge
Invalid,the order is incorrect “myAge” should be “is”= too “42” not the other way around.
d) yourRate = 3.5
Valid
e) yourRate = myAge
Valid
f) yourRate= departmentName
Invalid, a string variable “departmentName” cannot be equal to a numeric value because one is a constant and the others value can be changed.
g) 6.91 = yourRate
Invalid, only because it is ordered from left to right instead of being ordered from right to left.
h) departmentName = Personnel
Valid
i) departmentName = “Personnel”
Valid
j) departmentName = 413
A string name cannot contain numbers unless it is in quotations
k) departmentName=“413”
Valid
n) departmentName = myAge
Invalid, a string cannot represent a Numeric variable
o) departmentname = yourRate
Invalid, The name used as a string contains a syntax error.
p) 413 = departmentName
Invalid,The order is incorrect it should start out at departmentName = 413, and that the answer it self is incorrect because it is not in quotations.
q)”413” = departmentName
Invalid, the order is in correct, the solution this time would be correct if it were in the correct order.
3: Assume that cost = 10 and price = 12. What is the value of each of the following expressions?
a) Price – cost * 2
Solution is 4
b) 15 + price – 3 *2
Solution is 21
c) (price + cost) * 3
Solution 66
d) 4 – 3 * 2 + cost
Solution is 8
e) Cost * ((price – 8) + 5) + 100
Solution is 190
5: Draw the hierarchy chart and then plan the logic for a program for the sales manager of The Couch Potato Furniture Company. The manager needs a program to determine the profit of any item sold. Input includes the wholesale price. Use three Modules. The main program declares global variables and calls housekeeping, detail,and end-of-job modules. The housekeeping module prompts for and accepts the retail price, computes the profit, and displays the result. The end-of-job module displays the messege “ Thanks for using this program”
Start
Declarations
num wholesalePrice
num retailPrice
num profit
string QUIT = “xxx”
string PROFIT_REPORT = “Profit Report”
string END_LINE = “Thanks for using this program”l
housekeeping ()
while not name = QUIT
detail loop()
endwhile
endOfJob()
stop
housekeeping()
output PROFIT-REPORT
input name
return
detail loop()
input wholesalePrice
profit = wholesalePrice – retailPrice
output name, wholesalePrice, retailPrice, profit
input name
return
endOfJob()
output END_LINE
return
Explanation / Answer
1: Which of the following names seem like good variable names to you? If a name doesn’t seem like a good variable name, explain why not.
a) C
The Variable is too short and lacks description
b) Cost
The word “cost” is a great variable because the value of a variable can be changed and this word still gives you a good idea as to what it alludes to.
Cost is a meaningful name, and it adheres to convention.
c) CostAmount
This one does give good description; although, it does not use the Hump configuration
"CostAmount" is redundant. The name is unnecessarily long.
d) Cost amount
This word “Cost Amount” does not work because it has a space and the first letter of each word is capitalized.
e) Cstofdngbsns
This term “Cstofdnghbsns” is garbage and is usually displayed when the value is unknown.
f) costOfDoingbusinessThisFiscalYear
This one does not work because to me its way too long; although, it does explain its selfs its just too long.
g) costYear2012
This variable is perfect it has the numbers after the letters, and the letters have the hump.
h) 2012YearCost
This does not work because it has the numbers before the letters and each first word is capitalized.
2: If myAge and yourRate are numeric variables, and departmentName is a string variables, which of the following statements are valid assignments? If a statement is not valid , explain why not.
a) myAge = 23
Valid
b) myAge = YourRate
Invalid, myAge cannot be equal to your rate because myAge is a numeric constant
Invalid; YourRate is not a variable name (case sensitive)
myAge = departmentName
c) 42 = myAge
Invalid,the order is incorrect “myAge” should be “is”= too “42” not the other way around.
d) yourRate = 3.5
Valid
e) yourRate = myAge
Valid
f) yourRate= departmentName
Invalid, a string variable “departmentName” cannot be equal to a numeric value because one is a constant and the others value can be changed.
g) 6.91 = yourRate
Invalid, only because it is ordered from left to right instead of being ordered from right to left.
h) departmentName = Personnel
Valid
Invalid, Personnel is not a variable nor a string
i) departmentName = “Personnel”
Valid
j) departmentName = 413
A string name cannot contain numbers unless it is in quotations
k) departmentName=“413”
Valid
n) departmentName = myAge
Invalid, a string cannot represent a Numeric variable
o) departmentname = yourRate
Invalid, The name used as a string contains a syntax error.
p) 413 = departmentName
Invalid,The order is incorrect it should start out at departmentName = 413, and that the answer it self is incorrect because it is not in quotations.
q)”413” = departmentName
Invalid, the order is in correct, the solution this time would be correct if it were in the correct order.
3: Assume that cost = 10 and price = 12. What is the value of each of the following expressions?
a) Price – cost * 2
Solution is 4
12-10*2 = -8
b) 15 + price – 3 *2
Solution is 21
c) (price + cost) * 3
Solution 66
d) 4 – 3 * 2 + cost
Solution is 8
e) Cost * ((price – 8) + 5) + 100
Solution is 190
5: Draw the hierarchy chart and then plan the logic for a program for the sales manager of The Couch Potato Furniture Company. The manager needs a program to determine the profit of any item sold. Input includes the wholesale price. Use three Modules. The main program declares global variables and calls housekeeping, detail,and end-of-job modules. The housekeeping module prompts for and accepts the retail price, computes the profit, and displays the result. The end-of-job module displays the messege “ Thanks for using this program”
Start
Declarations
num wholesalePrice
num retailPrice
num profit
string QUIT = “xxx”
string PROFIT_REPORT = “Profit Report”
string END_LINE = “Thanks for using this program”
housekeeping ()
while not name = QUIT
detail loop()
endwhile
endOfJob()
stop
housekeeping()
output PROFIT-REPORT
input name
return
detail loop()
input wholesalePrice
profit = wholesalePrice – retailPrice
output name, wholesalePrice, retailPrice, profit
input name
return
endOfJob()
output END_LINE
return
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.