Anda di halaman 1dari 9

CSCI 1470

Quiz 1
Name: _________________________________________
(3pts each, 108 total)
___1. Programmer-defined names of memory locations that may hold data are:
a. Operators
b. Variables
c. Syntax
d. Operands
e. None of the above.

ANS=B
___2. _______________ are used to translate each source code instruction into the
appropriate machine language instruction.
a. Modules
b. Library routines
c. Compilers
d. Preprocessor directives
e. None of the above

ANS=C
___3. What statement best describes a variable and its primary purpose?
a. A variable is a structured, general-purpose language designed primarily for
teaching programming.
b. A variable is a collection of eight bits.
c. A variable is a word that has a special meaning to the compiler.
d. A variable is a named storage location in the computer's memory used for
holding
a piece of information.
e. A variable is a "line" of code in the body of a program, that may change.

ANS=D
___4. A variable declaration announces the name of a variable that will be used in a
program, as well as:
a. The type of data it will be used to hold
b. The operators that will be used on it
c. The number of times it will be used in the program
d. The area of the code in which it will be used
e. None of the above

ANS=A
___5. In a C++ program, two slash marks ( //) indicate:
a. The end of a statement
b. The beginning of a comment
c. The end of the program
d. The beginning of a block of code
e. None of the above

ANS=B

___6. A statement that starts with a #is called a:


a. Comment
b. Function
c. Preprocessor directive
d. Key word
e. None of the above.

ANS=C
___7. For every opening brace in a C++ program, there must be a:
a. String literal
b. Function
c. Variable
d. Closing brace
e. None of the above

ANS=D
___8. Of the following, which is a valid C++ identifier (variable)?
a. June1997
b. _employee_number
c. ___department
d. myExtraLongVariableName
e. All of the above are valid identifiers.

ANS=E
___9. A character literal is enclosed in ________ quotation marks, whereas a string literal
is enclosed in ________ quotation marks.
a. double, single
b. triple, double
c. open, closed
d. single, double
e. None of the above

ANS=D
___10. What is the output of the following statement?
cout<<4*(15/(1+3))<<endl;
a. 15
b. 12
c. 63
d. 72
e. None of these

ANS=B
___11. This is used to mark the end of a complete C++ programming statement.
a. Pound Sign
b. Semicolon
c. Data type
d. Void
e. None of the above

ANS=B
___12. If you use a C++ key word as an identifier (variable), your program will:
a. Execute with unpredictable results
b. not compile
c. understand the difference and run without problems
d. Compile, link, but not execute
e. None of the above

ANS=B
___13. In the C++ instruction, given the following declaration statement:
intnumber=38,children=4,cookies;
cookies=number%children;
what is the value of cookies after the execution of the statement?
a. 2
b. 0
c. 9
d. .5
e. None of these

ANS=A
___14. How would you consolidate the following declaration statements into one
statement?
intx=7;
inty=16;
intz=28;
a. intx=7;y=16;z=28;
b. intx=7y=16z=28;
c. intx,y,z=7,16,28
d. intx=7,y=16,z=28;
e. None of these will work

ANS=D
___15. Every complete C++ program must have a _____________.
a. comment
b. function named main
c. preprocessor directive
d. symbolic constant
e. coutstatement

ANS=B
___16. Look at the following program and answer the question that follows it.
1 //Thisprogramdisplaysmygrosswages.
2 //Iworked40hoursandImake$20.00perhour.
3 #include<iostream>
4 usingnamespacestd;
5
6 intmain()

7{
8 inthours;
9 doublepayRate,grossPay;
10
11 hours=40;
12 payRate=20.0;
13 grossPay=hours*payRate;
14 cout<<"Mygrosspayis$"<<grossPay<<endl;
15 return0;
16 }

Which line(s) in this program cause output to be displayed on the screen?


a. 13 and 14 d. 13
b. 8 and 9
e. 15
c. 14

ANS=C
___17. Which of the following defines a double-precision floating point variable named
payCheck?
a. floatpayCheck;
b. doublepayCheck;

c. payCheckdouble;
d. DoublepayCheck;

ANS=B
___18. What will the following code display?
cout<<"Monday";
cout<<"Tuesday";
cout<<"Wednesday";
a.
b.
c.
d.

Monday
Tuesday
Wednesday
MondayTuesdayWednesday
MondayTuesdayWednesday
"Monday"
"Tuesday"
"Wednesday"

ANS=B
___19. What will the following code display?
intx=0,y=1,z=2;
cout<<x<<y<<z<<endl;
a. 012c. xyz
b. 0
1
2
d. 012

ANS=D
___20. What will the following code display?

cout<<"Four\n"<<"score\n";
cout<<"and"<<"\nseven";
cout<<"\nyears"<<"ago"<<endl;
a. Four
score
and
seven
yearsago
c. Four
score
andseven
yearsago
b. Fourscoreandseven
yearsago
d. Fourscore
andseven
yearsago

ANS=A
___21. What will the value of xbe after the following statements execute?
intx;
x=18/4;
a. 4.5
b. 4

c. 0
d. unknown

ANS=B
___22. What will the value of xbe after the following statements execute?
intx;
x=18%4;
a. 0.45
b. 4

c. 2
d. unknown

ANS=C
___23. You can use these to override the rules of operator precedence in a mathematical
expression.
a. [Brackets]
b. (Parentheses)
c. {Braces}
d. The escape character \
e. None of these

ANS=B
___24. In the following C++ statement, what will be executed first according to the order
of precedence.
result=63*2+710/2;

a. 63
b. 3*2
c. 2+7
d. 710
e. 10/2

ANS=B
___25. Assume that xis an intvariable. What value is assigned to xafter the
following assignment statement is executed?
x=3+4%6/5;
a. 0
b. 1
c. 2
d. 3
e. None of these

ANS=D
___26. When using the sqrtfunction you must include this header file.
a. cstdlib
b. cmath
c. cstring
d. iostream
e. iomanip

ANS=B
___27. What will the value of xbe after the following statements execute?
intx=0;
inty=5;
intz=4;
x=y+z*2;
a. 13 c. 0
b. 18 d. unknown

ANS=A
___28. Which statement is equivalent to the following?
number+=1;
a. number=number+1;
b. number+1;

c. number=1;
d. None of these

ANS=A
___29. Which statement is equivalent to the following?
x=x*2;
a. x*2; c. x=x*x;
b. x*=2; d. None of these

ANS=B

___30. Which line in the following program will cause a compiler error?
1 #include<iostream>
2 usingnamespacestd;
3
4 intmain()
5{
6 constintMY_VAL;
7 MY_VAL=77;
8 cout<<MY_VAL<<endl;
9 return0;
10 }
a. 6
b. 8

c. 9
d. 7

ANS=D(A)
___31. After execution of the following code, what will be the value of input_valueif
the value 0 is entered at the keyboard at run time?
cin>>input_value;
if(input_value>5)
input_value=input_value+5;
elseif(input_value>2)
input_value=input_value+10;
else
input_value=input_value+15;
a. 15
b. 10
c. 25
d. 0
e. 5

ANS=A
___32. What will be the output of the following code segment after the user enters 0 at
the keyboard?
intx=1;
cout<<"Entera0ora1fromthekeyboard:";
cin>>x;
if(x)
cout<<"true"<<endl;
else
cout<<"false"<<endl;
a. Nothing will be displayed
b. false
c. x
d. true

ANS=B

___33. This operator is used in C++ to represent equality.


a. =
b. ><
c. !!
d. ==
e. None of these

ANS=D
___34. What will the following program segment display?
intfunny=7,serious=15;
funny=serious%2;
if(funny!=1)
{
funny=0;
serious=0;
}
elseif(funny==2)
{
funny=10;
serious=10;
}
else
{
funny=1;
serious=1;
}
cout<<funny<<""<<serious<<endl;
a. 7 15
b. 0 0
c. 10 10
d. 1 1
e. None of these

ANS=D
___35. What will the following program display?
#include<iostream>
usingnamespacestd;
intmain()
{
inta=0,b=2,x=4,y=0;
cout<<(a==b)<<"";
cout<<(a!=b)<<"";
cout<<(b<=x)<<"";
cout<<(y>a)<<endl;
return0;
}

a. 0 1 1 0
b. 0 0 1 0
c. 1 1 0 1
d. 1 0 0 1
e. None of these

ANS=A
___36. What is the value of donutsafter the following code executes?
intdonuts=10;
if(donuts!=10)
donuts=0;
else
donuts+=2;
a. 12 c. 0
b. 10 d. 2

ANS=A

Anda mungkin juga menyukai