|
|
VARIABLE DECLARATIONS and ASSIGNMENTS
1.
Declare and initialize in a single C++ statement a double variable that will
have the value 3.14.
2.
Write one line of C++ code that adds one to the integer variable iCounter.
3.
Declare a float constant named RATE that has a value of 2.75.
4.
Declare and initialize in a single C++ statement a floating point variable
named fVal that has a
value
of 27.5.
5.
Declare and initialize in a single C++ statement a character variable that will
have the value 'R'.
6.
Declare and initialize in a single C++ statement a boolean variable that will
have the value false.
7.
Declare and initialize in a single C++ statement a long integer variable that
will have the value
154332.
8.
Declare and initialize in a single C++ statement a short integer variable that
will have the value 2.
9.
Declare and initialize in a single C++ statement a string variable(STL string
class) that will have
the
value "Fred".
10.
Declare an integer constant named MAX that has a value of 1000.
11.
Declare a double constant named CPP that has a value of 1000.01.
12.
Declare a short constant named XTRABITS that has a value of 0.
OPERATORS
1.
Place parentheses in the following expression that correctly describe the order
in which the
operations
would be performed by default.
6 + 7 * 3 - 4 / 2
2.
Suppose we have two integers iVal1 = 10 and iVal2 = 4. What is the output for
each of the
following
lines of C++ code?
A.
cout << float(iVal1/iVal2);
B.
cout << iVal1 % iVal2;
C.
cout << float(iVal1)/iVal2;
3.
Given the code below, write the output.
bool bA = true;
bool bB = false;
if(bA || bB)
cout <<
"Hi";
else
cout <<
"Bye";
4.
Given the code below, write the output.
bool bA = true;
bool bB = false;
if(bA && bB)
cout <<
"Hi";
else
cout <<
"Bye";
5.
Given the code below, write the output.
bool bA = true;
bool bB = false;
if(bA == bB)
cout <<
"Hi";
else
cout <<
"Bye";
6.
Given the code below, write the output.
bool bA = true;
bool bB = false;
if(bA = bB)
cout <<
"Hi";
else
cout <<
"Bye";
7.
Given the code below, write the output.
int iVal1 10;
int iVal2 = 3;
if(!(iVal1 >
iVal2))
cout <<
"Hi";
else
cout <<
"Bye";
8.
Given the equation y = ax2 + bx + c, which of the
following is the correct C++ assignment
statement
for this equation?
A. y
= a*x*x*(b*x+c)
B. y
= a*(x*x)+b*x+c
C. y
= (a*x)*x*x+b*(x+c)
D. y
= a*(x*2)+b*x+c
E.
None of these
9.
Given the equation y = ax2+bx/c , which of the following is the correct C++
assignment statement
for
this equation?
A. y
= (a * x * x + b * x) / c
B. y
= (a * x * x * x + b * x) / c
C. y
= (a * x * 2 + b * x) / c
D. y
= a * x * x + b * x / c
E.
None of these
10.
Given the following code, what is the value of siVal1 after the code has
executed?
short siVal1 = 15;
short siVal2 = 5;
siVal1 = siVal1 -
siVal2;
11.
Given the code below, what is the output?
int iA = 6;
if(iA = 5)
cout <<
"Hello";
cout << "
World";
12.
Given the code below, what is the value of iN
after it is executed?
int iN = 6;
iN++;
13.
Given the code below, what is the value of fNum
after it is executed?
float fNum = 2.0;
double dNum = 5.0;
dNum = dNum * fNum;
I/O
1.
Write the output produced by the following code segment.
int iX = 10, iY = 12,
iZ = 4;
cout << iX
<< iZ << iY << endl;
cout << iX;
cout << iY
<< "\n";
cout << iZ;
2.
Write the output produced by the following code segment.
short siNum = 5;
cout <<
"siNum = " << siNum;
PRE PROCESSOR
1.
What does the following statement do when placed at the beginning of a .cpp or
.h file?
#include
<iostream.h>
2.
What does the following statement do when placed at the beginning of a .cpp or
.h file?
#include
<fstream.h>
3.
Write a user include statement to include a file named foo.h.
|
|
If You Enjoyed This Post Please Take 5 Seconds To Share It.
Subscribe for free
Get our latest articles delivered to your email inbox.











0 comments:
Post a Comment