Define an algorithm. What is an identifier? List four atomic (built-in) data typ
ID: 3621618 • Letter: D
Question
Define an algorithm.What is an identifier?
List four atomic (built-in) data types.
Every C++ statement is terminated with a(n)?
What are the three types of control structures?
6. List the six relational and equality operators.
List the logical operators.
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;
}
24. Look at this code. What is the output?
#include <iostream>
using namespace std;
int main()
{
for(int i=10;i>0;i--)
cout << i << " ";
cout << endl;
return 0;
}
25. Write a short C++ program that displays:
+
++
+++
++++
+++++
Use a looping structure.
Explanation / Answer
1.Algorithm: An algorithm is a seuence of unambiguous instructions for solving a problem for obtaining a required output for any legitimate input in a finite amount of time. (or) a step-by-step method of solving a problem or making decisions, as in making a diagnosis.
2. Identifier: An identifier is nothing but a data type. It may variable, content, structure or a pointer. An identifier consists of an arbitrary number of letters, digits, or the underscore character.The first character in an identifier must be a letter or the _ (underscore) character.
3. Atomic (built-in) data types: There are four primitive atomic data types:
1. Booleans
2. Integer
3 characters and
4. Floats
4. Every C++ statement is terminated with a semicolon ( ; ).
5. Three Basic Control Structures are:
1) Iterative Structures
2) Control Structures
3) Selective Structures
6. Relational and equality operators:
Try remaining questions.
== Equal to != Not equal to > Greater than < Less than >= Greater than or equal to <= Less than or equal to
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.