Name:
Student ID:
DUE: 10 PM Sunday, September 27. Email the instructor a text
file that contains your answers. Use "EE261 Quiz1" as subject of your
email.
1. Which of the following are valid C++ identifiers? [0.5%]
a. theDog
b. all-In-One
c. all_in_one
d. 2morrow
e. page#
f. AMOUNT
g. C++
h. i
i. _function
j. 100
Answer:
2. Which of the following are string literal constants? [0.5%]
a. 's'
b. 256
c. "Hi, I am not a string literal..."
d. 015
e. 1024f
f. 3.1415926
g. "s"
h. "256"
Answer:
3. [0.5%]
a) Write a C++ statement that declares a named constant PI of double
type with a value of 3.14.
Answer:
b) what are the advantages of using named constants
over literal constants?
Answer:
4. What is the value of each of the following expressions: [0.5%]
a.
27+8/5-7
answer:
b.
27+8/5.0-7
answer:
c. 25%7-4
answer:
d. int(15+12*2.3-3*14) answer:
5. Match the following terms to the definitions given below. [0.5%]
a. Unary operator
b. Binary operator
c. Type conversion
d. Type coercion
e. Mixed type expressions
f. Argument list
g. Void function
1. A computation that involves both floating point values and integer
values.
2. An operator with two operands.
3. A function that is called as a separate statement.
4. Explicitly changing a value of one type to another.
5. The values that appear in the parentheses in a function call.
6. An operator with just one operand.
7. Implicitly changing a value of one type to another.
Answer:
6. Given the following statements: [0.5%]
string str1="Gone with the wind.";
string str2="Dance with wolves.";
what is the result of each of the following expressions?
a.
str1.length()
answer:
b.
str1.find(str2)
answer:
c. str1.substr(5,
4)
answer:
d. str2.find(str1.substr(5,4)) answer:
7. Write a C++ expression for each of the following formulas. Assume
that the variables (a, b, x, y) are already defined. [0.5%]
a. The square root of the absolute value of
(a-b). Answer:
b. x to the power of cosine
y.
Answer:
8. Match the following terms to their definitions given below. [0.5%]
a. Machine language
b. Assembler
c. Compiler
d. Source program
e. Object program
1. A program that translates a high-level language program into machine
code.
2. The machine language version of a source program.
3. A program that translates an assembly language program into machine
code.
4. A language, made up of binary coded instructions, that is used
directly by the computer.
5. A program written in a high-level programming language.
Answer:
9. Match the following terms to their definitions given below. [0.5%]
a. Function
b. Variable
c. Literal
d. Data type
e. Expressions
1. An identifier referring to a value that can be changed.
2. A specific set of values, along with operations that can be applied
to those values.
3. A value that appears in a program.
4. A subprogram in C++.
5. An arrangement of identifiers, literals, and operators that can be
evaluated to obtain a value.
10. Given these assignments to string variables: [0.5%]
string1 = "Bjarne Stroustrup";
string2 = "C";
string3 = "programming language";
string4 = "++ because it is a
successor to the ";
string5 = " named his new ";
What is the value of the following expression?
string1+string5+string3+"
"+string2+string4+string2+" "+string3+"."
Answer:
Bonus question: (1%)
Assume that the following function isLeapYear()
is available, which will return true when the parameter year is a leap year.
boolean isLeapYear(int year) {... }
Write a new function named nextLeapYear(int
year). This function should return year if the value of year represents a leap year,
otherwise, return the next leap year.
For example, nextLeapYear(2004)
should return 2004, and nextLeapYear(1999) should return
2000.
int nextLeapYear(int year) {
// write your implemention here.
}