need help on my pre exam After execution of the following code, what will be the
ID: 3863153 • Letter: N
Question
need help on my pre exam
After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time?
cin >> input_value;
if (input_value > 5)
input_value = input_value + 5;
else if (input_value > 2)
input_value = input_value + 10;
else
input_value = input_value + 15;
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 2 3 pts
Edit this Question Delete this Question
0 multiple_choice_question 133143
<p>What will following segment of code output?</p> <p><strong>int x = 5;</strong><br><strong>if (x = 2)</strong></p> <p><strong> cout << "This is true!" << endl;</strong></p> <p><strong>else</strong></p> <p><strong> cout << "This is false!" << endl;</strong></p> <p><strong> cout << "This is all folks!" << endl;</strong></p>
What will following segment of code output?
int x = 5;
if (x = 2)
cout << "This is true!" << endl;
else
cout << "This is false!" << endl;
cout << "This is all folks!" << endl;
This is true!
This is false!
This is true!
This is all folks!
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 3 3 pts
Edit this Question Delete this Question
0 multiple_choice_question 133144
<div class="WordSection1"> <p>What would be the output for the following code if the value input for plan is 4?</p> </div> <p><strong> int main(void)<br> {<br> int plan = 0, cost;<br> cin >> plan;<br> <br> switch (plan)<br> {<br> case 2:<br> case 3:<br> cost = 100;<br> case 4:<br> cost = 250;<br> break;<br> default:<br> cost = 50;<br> }<br> cout << cost << endl;<br> return 0;<br> }<br> <br> </strong></p>
What would be the output for the following code if the value input for plan is 4?
int main(void)
{
int plan = 0, cost;
cin >> plan;
switch (plan)
{
case 2:
case 3:
cost = 100;
case 4:
cost = 250;
break;
default:
cost = 50;
}
cout << cost << endl;
return 0;
}
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 4 3 pts
Edit this Question Delete this Question
0 multiple_choice_question 133145
<div class="WordSection1"> <p>What would be the output for the following code if the value input for plan is 2?</p> </div> <p><strong> int main(void)<br> {<br> int plan = 0, cost;<br> cin >> plan;<br> <br> switch (plan)<br> {<br> case 2:<br> case 3:<br> cost = 100;<br> case 4:<br> cost = 250;<br> break;<br> default:<br> cost = 50;<br> }<br> cout << cost << endl;<br> return 0;<br> }<br> <br> </strong></p>
What would be the output for the following code if the value input for plan is 2?
int main(void)
{
int plan = 0, cost;
cin >> plan;
switch (plan)
{
case 2:
case 3:
cost = 100;
case 4:
cost = 250;
break;
default:
cost = 50;
}
cout << cost << endl;
return 0;
}
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 5 3 pts
Edit this Question Delete this Question
0 multiple_choice_question 133151
<p>What is the output?</p> <p><strong>int main(void)<br> {<br> int fun = 13; int time = 3; int result;<br> <br> result = fun++ * ++time;<br> cout << fun << "***" << time << "***" << result << endl;<br> return 0;<br> }<br> <br> </strong></p>
What is the output?
int main(void)
{
int fun = 13; int time = 3; int result;
result = fun++ * ++time;
cout << fun << "***" << time << "***" << result << endl;
return 0;
}
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 6 3 pts
Edit this Question Delete this Question
0 multiple_choice_question 133152
How many times would the following loop be executed?<br> <strong>int i = 12;<br> while (i > 0) <br> {<br> cout << 2 * i << endl;<br> i += 2;<br> }</strong>
How many times would the following loop be executed?
int i = 12;
while (i > 0)
{
cout << 2 * i << endl;
i += 2;
}
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 7 3 pts
Edit this Question Delete this Question
0 multiple_choice_question 133153
<span><strong>while( n <= 5){</strong></span><br><span><strong> cout << n << " ";</strong></span><br><span><strong> n++; </strong></span><br><span><strong> }</strong></span>
while( n <= 5){
cout << n << " ";
n++;
}
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 8 3 pts
Edit this Question Delete this Question
0 multiple_choice_question 133154
How many times would the following loop be executed?<br> <strong> </strong><strong>int i = 3;<br> do<br> {<br> cout << 2 * i << endl;<br> i += 3;<br> }while (i < 10);<br> <br> </strong>
How many times would the following loop be executed?
int i = 3;
do
{
cout << 2 * i << endl;
i += 3;
}while (i < 10);
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 9 3 pts
Edit this Question Delete this Question
0 multiple_choice_question 133156
<p>Here is the prototype for a function named computeValue:</p> <p> <strong> void computeValue(int);</strong></p> <p>Which of the following is a correct call (invoke) to this function?</p>
Here is the prototype for a function named computeValue:
void computeValue(int);
Which of the following is a correct call (invoke) to this function?
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 10 3 pts
Edit this Question Delete this Question
0 multiple_choice_question 133157
<p>What is the output from the following piece of code?</p> <p><span>#include <iostream></span><br><span> using namespace std;</span><br><span> void copy (int& a, int& b, int& c);</span><br> <br><span> int main ()</span><br><span> {</span><br><span> int x = 5, y = 3, z = 7;</span><br><span> copy (x, y, z);</span><br><span> cout << x << " & " << y << " & " << z;</span><br><span> return 0;</span><br><span> }</span><br><span> void copy (int& a, int& b, int& c)</span><br><span> {</span><br><span> a *= 2;</span><br><span> b *= 2;</span><br><span> c *= 2;</span><br><span> }</span></p> <p> </p>
What is the output from the following piece of code?
#include <iostream>
using namespace std;
void copy (int& a, int& b, int& c);
int main ()
{
int x = 5, y = 3, z = 7;
copy (x, y, z);
cout << x << " & " << y << " & " << z;
return 0;
}
void copy (int& a, int& b, int& c)
{
a *= 2;
b *= 2;
c *= 2;
}
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 11 3 pts
Edit this Question Delete this Question
0 multiple_choice_question 133158
<p>What is the output from the following piece of code?</p> <p><span>#include <iostream></span><br><span> using namespace std;</span><br><span> void copy (int& a, int b, int& c);</span><br> <br><span> int main ()</span><br><span> {</span><br><span> int x = 5, y = 3, z = 7;</span><br><span> copy (x, y, z);</span><br><span> cout << x << " & " << y << " & " << z;</span><br><span> return 0;</span><br><span> }</span><br><span> void copy (int& a, int b, int& c)</span><br><span> {</span><br><span> a *= 2;</span><br><span> b *= 2;</span><br><span> c *= 2;</span><br><span> }</span></p> <p> </p>
What is the output from the following piece of code?
#include <iostream>
using namespace std;
void copy (int& a, int b, int& c);
int main ()
{
int x = 5, y = 3, z = 7;
copy (x, y, z);
cout << x << " & " << y << " & " << z;
return 0;
}
void copy (int& a, int b, int& c)
{
a *= 2;
b *= 2;
c *= 2;
}
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 12 3 pts
Edit this Question Delete this Question
0 multiple_choice_question 133159
A function can have zero to many parameters, and it can return this many values:
A function can have zero to many parameters, and it can return this many values:
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 13 3 pts
Edit this Question Delete this Question
0 multiple_choice_question 133160
This statement causes the execution of a function to cease.
This statement causes the execution of a function to cease.
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 14 3 pts
Edit this Question Delete this Question
0 multiple_choice_question 133161
When used as parameters, these types of variables allow a function to access the parameter's original argument (i.e. memory location).
When used as parameters, these types of variables allow a function to access the parameter's original argument (i.e. memory location).
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 15 2 pts
Edit this Question Delete this Question
0 true_false_question 133146
<p>. Given<br><strong> int a = 3; int b = 11;</strong></p> <p>Is the following expression true or false?<br> <strong> a > b</strong><br><br></p>
. Given
int a = 3; int b = 11;
Is the following expression true or false?
a > b
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 16 2 pts
Edit this Question Delete this Question
0 true_false_question 133147
<p>. Given<br><strong> int a = 3; int b = 11;</strong></p> <p>Is the following expression true or false?<br> <strong> a > 0 || a > b </strong><br><br></p>
. Given
int a = 3; int b = 11;
Is the following expression true or false?
a > 0 || a > b
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 17 2 pts
Edit this Question Delete this Question
0 true_false_question 133148
<p>. Given<br><strong> int a = 3; int b = 11;</strong></p> <p>Is the following expression true or false?<br> <strong> a > 0 && a > b</strong></p>
. Given
int a = 3; int b = 11;
Is the following expression true or false?
a > 0 && a > b
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 18 2 pts
Edit this Question Delete this Question
0 true_false_question 133149
<p>. Given<br><strong> int a = 3; int b = 11;</strong></p> <p>Is the following expression true or false?<br> <strong> !(a > 10)</strong></p>
. Given
int a = 3; int b = 11;
Is the following expression true or false?
!(a > 10)
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 19 2 pts
Edit this Question Delete this Question
0 true_false_question 133150
<p>. Given<br><strong> int a = 3; int b = 11;</strong></p> <p>Is the following expression true or false?<br> <strong> a == 3</strong></p>
. Given
int a = 3; int b = 11;
Is the following expression true or false?
a == 3
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 20 5 pts
Edit this Question Delete this Question
0 essay_question 133163
<p>Write the output:</p> <p> <strong>int i, j;<br> for (i = 1; i <=2; i++)<br> {<br> for( j = 0; j < 2; j++)<br> cout << "slow,";<br> for( j = 0; j < 2; j++)<br> cout << "quick,";<br> cout << endl;<br> }<br> <br> </strong></p>
Write the output:
int i, j;
for (i = 1; i <=2; i++)
{
for( j = 0; j < 2; j++)
cout << "slow,";
for( j = 0; j < 2; j++)
cout << "quick,";
cout << endl;
}
HTML Editor Rich Content Editor Keyboard Shortcuts
File
Edit
Insert
View
Format
Table
Font Sizes
Paragraph
p
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 21 5 pts
Edit this Question Delete this Question
0 essay_question 133155
<p>Rewrite the following for loop as a while loop. The while loop must output what the for statement does and no more. Assume <strong>int i; int num;</strong></p> <p>f<strong>or (i = 1; i <= num; i++)</strong><br><strong>{</strong><br><strong> if(num % i == 0)</strong><br><strong> cout << i << endl;</strong><br><strong>}</strong></p>
Rewrite the following for loop as a while loop. The while loop must output what the for statement does and no more. Assume int i; int num;
for (i = 1; i <= num; i++)
{
if(num % i == 0)
cout << i << endl;
}
HTML Editor Rich Content Editor Keyboard Shortcuts
File
Edit
Insert
View
Format
Table
Font Sizes
Paragraph
p
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 22 18 pts
Edit this Question Delete this Question
0 essay_question 133164
<p>Using the Metabolic Equivalent of Task value for a given activity, the number of calories burned per hour can be calculated. The formula is a person’s weight in pounds divided by 2.2 and multiplied by the MET value for the given activity. Write a program to input the MET value and out put the number of calories burned per hour for a person for each pound between 120 and 190 inclusive. The sample output is for the cycling MET which is 8.0.</p> <p>Write main() and <strong>no other functions. </strong>Output formatted as shown (actual width of columns not important as long as the decimal points are lined up and there is one point to right of decimal point for real numbers.</p> <pre>Enter MET for activity: 8.0<br> Weight Calories burned<br> 120 436.4<br> 121 440.0<br> 122 443.6<br> 123 447.3<br> 124 450.9<br> 125 454.5<br> 126 458.2<br> 127 461.8<br> . . .<br> 186 676.4<br> 187 680.0<br> 188 683.6<br> 189 687.3<br> 190 690.9<br> Press any key to continue </pre> <p> </p>
Using the Metabolic Equivalent of Task value for a given activity, the number of calories burned per hour can be calculated. The formula is a person’s weight in pounds divided by 2.2 and multiplied by the MET value for the given activity. Write a program to input the MET value and out put the number of calories burned per hour for a person for each pound between 120 and 190 inclusive. The sample output is for the cycling MET which is 8.0.
Write main() and no other functions. Output formatted as shown (actual width of columns not important as long as the decimal points are lined up and there is one point to right of decimal point for real numbers.
HTML Editor Rich Content Editor Keyboard Shortcuts
File
Edit
Insert
View
Format
Table
Font Sizes
Paragraph
p
Move To... This element is a more accessible alternative to drag & drop reordering. Press Enter or Space to move this question.
Flag this Question
Question 23 20 pts
Edit this Question Delete this Question
0 essay_question 133162
If you get a ticket for speeding, your fine is based on how much your speed exceeded the speed limit by. Suppose the fine is based on the following schedule:<br> <strong><span>Amount over limit:</span></strong> <strong><span>Fine</span></strong><br> Greater than 0 but less than or equal to 10 $ 80<br> Greater than 10 but less than or equal to 20 $250<br> Greater than 20 $500<br> Complete the program below to input the legal speed limit and the speed the driver was driving at. Compute and output the fine. Complete getData to input the legal speed and driver’s speed. Complete calcFine to calculate the fine. Add the prototypes (i.e. function declarations). <strong><em>Do not change any code already written in main(). </em></strong>(20 points possible.<br> <br> <strong>#include <iostream><br> #include <iomanip><br> using namespace std;<br> <br> //Function declarations<br> <br> ______________________________________________________<br> <br> ______________________________________________________<br> int main (void)<br> {<br> double speedLimit, driverSpeed, fine;<br> <br> //call function to input data<br> getData(speedLimit, driverSpeed);<br> <br> //Call function to calculate the fine<br> fine = calcFine(speedLimit, driverSpeed);<br> cout << setprecision(2) << fixed;<br> cout << "Your fine is: $ " << fine << endl;<br> return 0;<br> }//main<br> //*******************Define functions*******************<br> <br> </strong>
If you get a ticket for speeding, your fine is based on how much your speed exceeded the speed limit by. Suppose the fine is based on the following schedule:
Amount over limit: Fine
Greater than 0 but less than or equal to 10 $ 80
Greater than 10 but less than or equal to 20 $250
Greater than 20 $500
Complete the program below to input the legal speed limit and the speed the driver was driving at. Compute and output the fine. Complete getData to input the legal speed and driver’s speed. Complete calcFine to calculate the fine. Add the prototypes (i.e. function declarations). Do not change any code already written in main(). (20 points possible.
#include <iostream>
#include <iomanip>
using namespace std;
//Function declarations
______________________________________________________
______________________________________________________
int main (void)
{
double speedLimit, driverSpeed, fine;
//call function to input data
getData(speedLimit, driverSpeed);
//Call function to calculate the fine
fine = calcFine(speedLimit, driverSpeed);
cout << setprecision(2) << fixed;
cout << "Your fine is: $ " << fine << endl;
return 0;
}//main
//*******************Define functions*******************
HTML Editor Rich Content Editor Keyboard Shortcuts
File
Edit
Insert
View
Format
Table
Font Sizes
Paragraph
p
Time's Up! Submitting results in:
Ok, fine
15Explanation / Answer
1. it will be 15.
This is because 0 is less than both 2 and 5 so these statements wont be run.The execution will move to the else part which will add 15 to the current value of input_value(=0).
2.it will be
This is true!
This is all folks!
this is because in the if statement assignment operator(=) is used instead of equal to (==).Hence the line x=2 means value of 2 is assigned to x, which is always true.There fore the if part of the code will be executed printing "This is true!".The else part will be skipped and the code after else part will be executed, which will print "This is all folks!".(If no curly brackets are used after a loop or if else , the immediate one line after the loop declaration or the if else condition is taken as part of loop/if-else).
3. it will display 250.
the switch case matches the switch value(plan here) with the different cases provided and executes the code defined under the matched case.Here, plan = 4 which matches the switch case for 4 and its code is executed, assigning value 250 to cost.After the switch case ends, the cout line is executed printing the value of cost(i.e. 250) on the screen.
4.the answer will be 250.
this is because when case is input 2, the code for case two will be executed.there is no code assigned under case 2 so no changes will be made.However since no break statement is used the execution moves automatically to case 3 which will assign cost the value of 100.Again no break statement is used so the execution moves to case 4 which now assigns a value 250 to cost.Here break statement is used so the execustion wont pass any further and will move out of switch , executing cout line and printing value of cost which is 250.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.