Question

In: Computer Science

This is a question about C# programming: True / False questions: for (int i=5; i <...

This is a question about C# programming:

True / False questions:

for (int i=5; i < 55; i+=5)
{ decimal decPrcPerGal = decGalPrc + i;
decPayPrc = iBuyGall * decPrcPerGal;
if (decPrcPerGal > decMAX_GALPRC) { continue; }
if (decPrcPerGal > decMAX_GALPRC) { break; }
Console.WriteLine(" {1} gallon(s) at {0,3} would cost {2,8:$###,##0.00}", decPrcPerGal, iBuyGall, decPayPrc); }

In the code above:

1. If decGalPrc is 10.57 decPrcPerGal will always be some number of dollars and 57 cents   True/ False?
2. In some cases, the loop’s code block will run several times without showing anything on the console True/ False?
3. Removing only the code if (decPrcPerGal > decMAX_GALPRC) { continue; } would change the output of the program   True/ False?
4. Removing only the code if (decPrcPerGal > decMAX_GALPRC) { break; } would change the output of the program True/ False?
5. Removing the code if (decPrcPerGal > decMAX_GALPRC) { continue; } Would allow the program to avoid performing some unnecessary steps   True/ False?

Solutions

Expert Solution

In case of any query do comment. Please rate answer Thanks.

Answer 1: True

Explanation: Because inside the loop, you are adding index i of the loop to decGalPrc to calculate decPrcPerGal where i is integer value only and this is the only place where you are calculating the value of decPrcPerGal. That is why answer is yes.

10.57 + 1 = 11.57

10.57 + 2 =12.57... so on

Answer 2: True

Explanation: When decPrcPerGal is greater than decMAX_GALPRC from first index only, then it will not print on console and will keep on running because of continue keyword.

Answer 3: False

Explanation: If you remove the code if (decPrcPerGal > decMAX_GALPRC) { continue; }, then output will not be changed in this program because next line which is having same condition but it is breaking the loop so you will not have any output again after the above condition met.

Answer 4: False

Explanation: If you remove the code if (decPrcPerGal > decMAX_GALPRC) { break; } , it would not affect the output of the program because this line of code was not reachable because of previous line of code where you are checking the same condition and when condition met you are continuing the loop.

Answer 5: True

Explanation: If you remove the code if (decPrcPerGal > decMAX_GALPRC) { continue; }, It will remove the unnecessary processing of the loop because in next line you are checking the same condition and breaking the loop.

E.g. if decMAX_GALPRC = 18 and decGalPrc =10

So after first iteration i =5, decPrcPerGal = 10 + 5 =11

in second iteration when i =10 decPrcPerGal = 10 + 10 = 20

if (decPrcPerGal > decMAX_GALPRC) { continue; }, code is not there it will break because of next line which is

if (decPrcPerGal > decMAX_GALPRC) { break; }


Related Solutions

C++ Questions: 1. True/False: an int uses 4 bytes in memory on all systems. 2. True/False:...
C++ Questions: 1. True/False: an int uses 4 bytes in memory on all systems. 2. True/False: a double typically offers better precision than a float. 3. True/False: The following two statements are equivalent assuming isPair is a variable of type bool: if (isPair) if (isPair == true) 4. Provide a value we could put in the blank so that the value of x will be 20 after the code snippet. int x = _____; x *= 4; 5. Provide a...
A. TRUE / FALSE QUESTIONS Enter “True” or “False” on the blank preceding each question. ______...
A. TRUE / FALSE QUESTIONS Enter “True” or “False” on the blank preceding each question. ______ 1. A “time line” can be drawn to illustrate the cash flows associated with a given investment. ______ 2. Calculating the present value of an expected cash flow is also known as “compounding.” ______ 3. An “annuity due” will always be worth less than an otherwise comparable “ordinary annuity,” because interest will compound for an additional time period. ______ 4. With a “perpetuity,” the...
I have a question about C++ programming Language class. I am confused with these terms and...
I have a question about C++ programming Language class. I am confused with these terms and what they are for. 1. Unix 2. Terminal 3. Git 4. CLOC 5. Linux Please explain each words and what's their jobs for C++. Also, if you know some good sources/websites, could you please provide me a link where I can learn how to use Unix, Terminal, Git, etc.
True/False Questions. For each question below, please answer “true” or “false” and explain why. 6. A...
True/False Questions. For each question below, please answer “true” or “false” and explain why. 6. A consumer with convex preferences who is indifferent between the bundles (5,2) and (11,6) will like the bundle (8,4) at least as well as either of the first two bundles. Assume these two goods are imperfect substitutes. 7. The marginal rate of substitution is always the same constant number when the goods are imperfect substitutes and no matter how many of each good is being...
PART 6: True or false and multiple-choice questions Question 16: True or false, firms in situation...
PART 6: True or false and multiple-choice questions Question 16: True or false, firms in situation of monopolistic competition have deadweight losses associated with monopoly because of barriers to entry. Question 17: Which of the two demands functions below is most elastic A) Qa=100-2p B) Qb=120-p Question 18: If a buyer values an object for $4 and a seller’s cost is $1, which of the statements below is false! If a transaction takes place, total surplus will be equal to...
The following questions are on recursion in C++ Programming. I had some trouble with these questions,...
The following questions are on recursion in C++ Programming. I had some trouble with these questions, can you please help me? Thank you! Consider the following recursive function void funcEx8(int u, char v) //Line 1 { //Line 2 if (u == 0) //Line 3 cout << u << " "; //Line 4 else //Line 5 { //Line 6 int x = static_cast (v); //Line 7 if (v < 'A') //Line 8 v = static_cast (x + 1); //Line 9 else...
True/ False Questions: For the following questions, first write whether they are true or false then...
True/ False Questions: For the following questions, first write whether they are true or false then write in a few sentences why it’s true or false. (1.5) a. The processes for producing penicillin and blue cheese both use the Penicillium fungus.     b. The reproductive organs of Amanita muscaria are popular pizza toppings.     c. The fungus Claviceps purpurea is thought to have triggered the infamous Salem witch trials.     d. Saccharomyces cerevisiae is a common household bread mold.    ...
C++ Visual Studios How many times will "!" print? int i = -5 while(-5 <= i...
C++ Visual Studios How many times will "!" print? int i = -5 while(-5 <= i <= 0) { cout << "!"; --i; }
(True or False) The following is an infinite loop. int main() { bool flag = false;...
(True or False) The following is an infinite loop. int main() { bool flag = false; int num = 0; while(!flag); { cin >> num; if(num == -1) { flag = true; } } return 0; }
I. Answer part A, B, and C 1a) Return true if the given int parameter is...
I. Answer part A, B, and C 1a) Return true if the given int parameter is both positive and less than 10, and false otherwise. Remember that 0 is not positive! positiveLessThan10(10) → false positiveLessThan10(9) → true positiveLessThan10(11) → false 1b) Return true if the parameters are in ascending order, from left to right. Two values that are equal are considered to be in ascending order. Remember, you can just type return true or return false to return true or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT