The modulus (%) operator does what? Write a declaration for an <fstream> object
ID: 3621667 • Letter: T
Question
The modulus (%) operator does what?Write a declaration for an <fstream> object used for inputting data.
10. The compiler generates an “unknown identifier” error from the following segment of code because:
cout << "Hello!" << endl;
int Radius;
cin >> Radius;
cout << "Radius: " << radius << endl;
a) all variables must be defined at the start of the program.
b) there is no prompt telling the user what to enter.
c) the variable Radius spelled in all lowercase in the fourth line
is undefined.
d)Radius must be a double rather than an int.
11. Which of the following correctly defines two integer variables?
I. int x, int y;
II. int x, y;
III. int x; int y;
a) I and III only
b) I only
c) II and III only
d) I, II, and III
12. What is the output produced by the following segment of code?
int x = 10;
int y = 24;
if ((x < y) && (y == 20))
cout << "One";
if ((x == y) || (x < y))
cout << "Two";
if ((x != y) || (x < y))
cout << "Three";
a) Two
b) TwoThree
c) Three
d) One
13. The following statement only evaluates to true when:
if ((x <= y)&&(y > 40))
a) Both expressions are true.
b) Either expression is true.
c) Neither expression is true.
d) None of the above.
14. Given the following definition: int x, y=2; which of the following are correct assignment statements?
I. x = 10;
II. x = y*2;
III. x*2 = y;
a) I only
b) I and II only
c) I and III only
d) I, II, and III
15. const identifiers should be used instead of variables when:
a) the value should not be changed by the program.
b) the value must be changed frequently during the run of the program.
c) the value is very large.
d) the name starts with an uppercase letter.
16. What is the output produced by the following segment of code?
int x = 10;
int y = 24;
if (x != y)
cout << "One";
else if (x < y)
cout << "Two";
else
cout << "Three";
a) One
b) Two
c) OneTwo
d) Three
17. What is the output produced by the following segment of code?
Score = 87;
if (Score > 70)
cout << "C";
else if (Score > 80)
cout << "B";
else if (Score > 90)
cout << "A";
a) A
b) B
c) C
d) CB
18. The output of the following code is:
#include <iostream>
using namespace std;
int main()
{
for(int i=0;i<5;i++)
cout << i + i * 2 << endl;
return 0;
}
19. The output of the following code is:
#include <iostream>
using namespace std;
int main()
{
int number = 0;
while (number < 10)
{
cout << ++number << endl;
}
return 0;
}
20. Define the difference between a post and pretest loop. What are advantages of each one?
21. Suppose the user entered the following values in the program below. 12 13 22 24 Ctrl-Z, what is the output?
#include <iostream>
using namespace std;
int main()
{
int number = 0, total=0;
cout << "Enter an integer ";
cin >> number;
for(;cin;)
{
total+=number;
cout << "Enter an integer ";
cin >> number;
}
cout << total << endl;
return 0;
}
22. Given the following code, what would be the output?
#include <iostream>
using namespace std;
int main()
{
int counter = 1;
do
{
cout << counter++ << endl;
}while(counter <= 10);
return 0;
}
23. Look at the following code, is there any problems? If so, how would you fix it?
#include <iostream>
using namespace std;
int main()
{
int age = 55;
bool isSenior = (age >= 55);
if(age > 55)
{
if(isSenior)
cout << "You get a discount of 15% " << endl;
else
cout << "You get a discount of 10% " << endl;
}
else
cout << "You get a discount of 5% " << endl;
return 0;
}
Explanation / Answer
please rate -thanks
The modulus (%) operator does what? does division and returns the remainder example 5%3 5/3=1 remainder 2 so the answer would be 2
Write a declaration for an <fstream> object used for inputting data. ifstream input;
10. The compiler generates an “unknown identifier” error from the following segment of code because:
cout << "Hello!" << endl;
int Radius;
cin >> Radius;
cout << "Radius: " << radius << endl; radius starts with lower case r but radius with upper case R was declared
a) all variables must be defined at the start of the program.
b) there is no prompt telling the user what to enter.
c) the variable Radius spelled in all lowercase in the fourth line is undefined.
d)Radius must be a double rather than an int.
11. Which of the following correctly defines two integer variables?
I. int x, int y;
II. int x, y;
III. int x; int y;
a) I and III only
b) I only
c) II and III only
d) I, II, and III
12. What is the output produced by the following segment of code?
int x = 10;
int y = 24;
if ((x < y) && (y == 20))
cout << "One";
if ((x == y) || (x < y))
cout << "Two";
if ((x != y) || (x < y))
cout << "Three";
a) Two
b) TwoThree
c) Three
d) One
13. The following statement only evaluates to true when:
if ((x <= y)&&(y > 40))
a) Both expressions are true.
b) Either expression is true.
c) Neither expression is true.
d) None of the above.
14. Given the following definition: int x, y=2; which of the following are correct assignment statements?
I. x = 10;
II. x = y*2;
III. x*2 = y;
a) I only
b) I and II only
c) I and III only
d) I, II, and III
15. const identifiers should be used instead of variables when:
a) the value should not be changed by the program.
b) the value must be changed frequently during the run of the program.
c) the value is very large.
d) the name starts with an uppercase letter.
16. What is the output produced by the following segment of code?
int x = 10;
int y = 24;
if (x != y)
cout << "One";
else if (x < y)
cout << "Two";
else
cout << "Three";
a) One
b) Two
c) OneTwo
d) Three
17. What is the output produced by the following segment of code?
Score = 87;
if (Score > 70)
cout << "C";
else if (Score > 80)
cout << "B";
else if (Score > 90)
cout << "A";
a) A
b) B
c) C
d) CB
18. The output of the following code is:
#include <iostream>
using namespace std;
int main()
{
for(int i=0;i<5;i++)
cout << i + i * 2 << endl;
return 0;
} no lines are skipped-they are 1 line after the other
0
3
5
9
12
19. The output of the following code is:
#include <iostream>
using namespace std;
int main()
{
int number = 0;
while (number < 10)
{
cout << ++number << endl;
}
return 0;
} again each of these is on the next line
1
2
3
4
5
6
7
8
9
10
20. Define the difference between a post and pretest loop. What are advantages of each one?pre test checks the condition before the body of the loop, posttest after the body of the loop. pretest you may do the loop zeroo times, posttest must execute at least once
21. Suppose the user entered the following values in the program below. 12 13 22 24 Ctrl-Z, what is the output?
#include <iostream>
using namespace std;
int main()
{
int number = 0, total=0;
cout << "Enter an integer ";
cin >> number;
for(;cin;)
{
total+=number;
cout << "Enter an integer ";
cin >> number;
}
cout << total << endl;
return 0;
}
71
22. Given the following code, what would be the output?
#include <iostream>
using namespace std;
int main()
{
int counter = 1;
do
{
cout << counter++ << endl;
}while(counter <= 10);
return 0;
}
1
2
3
4
5
6
7
8
9
10
23. Look at the following code, is there any problems? If so, how would you fix it?
#include <iostream>
using namespace std;
int main()
{
int age = 55;
bool isSenior = (age >= 55);
if(age > 55)
{
if(isSenior)
cout << "You get a discount of 15% " << endl;
else
cout << "You get a discount of 10% " << endl;
}
else
cout << "You get a discount of 5% " << endl;
return 0;
}
problem is when get to check if isSenior will always be true since age >55 so discount of 10% is useless
I can't fix it since I don't know what it's supposed to be - if that 10% discount is even supposed to be there
#include <iostream>
using namespace std;
int main()
{
int age = 55;
bool isSenior = (age >= 55);
if(isSenior)
cout << "You get a discount of 15% " << endl;
else
cout << "You get a discount of 5% " << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.