Exam 3: Part 1

The University of Michigan
EECS 183: Elem. Programming Concepts
Fall 2009
Exam 3: Part 1
Professor ML Dorf
Wednesday December 16, 2009
7:00 to 9:00 pm
Max: 100 points
Instructions
•
Part 1 of the exam consists of twenty six multi-choice questions worth 4 points each.
Please keep this in mind as you work
•
The exam is closed book. No books, notes or the like may be used. No computers,
calculators, PDAs, cell phones or other electronic devices may be used
•
The exam is closed neighbor. No 'partner' on this -- only on projects
•
Some questions are not simple, therefore, read carefully
•
Assume all code and code fragments compile, unless otherwise specified.
•
Assume/use only the standard ISO/ANSI C++.
•
Within the following questions, the term valid means: code uses standard ISO/ANSI
C++, code is explicit on all typing, i.e., does not make use of default settings.
•
This course operates under the rules of the College of Engineering Honor Code. Your
signature endorses the pledge below. After you finish your exam, sign your scantron sheet to
indicate the statement below
I have neither given nor received aid on this examination, nor have I concealed
any violations of the Honor Code.
1
Potpourri
1) In C++, an operator is said to be overloaded when:
A)
B)
C)
D)
E)
It is used at more than one place in a program
It tells compiler to implement an operator on ADT's
The compiler does not know how to use it resulting in a fail state
The compiler restricts its use to MAX_LIMIT number of times
It is tired of being used over and over again
2) What does "garbage" mean in computer science?
A)
B)
C)
D)
yesterday's pizza
food at the quad
allocated space that can no longer be reached
what you watched on TV after you were brain dead due to proj6
3) Implicit type casting may occur as the result of:
A) assignment
B) passing an argument to a function
C) returning a value from a value-returning function
D) all of the above
E) none of the above
4) When we talk about a library in EECS 183, what are we talking about?
A) A place you can go and check-out books (e.g. Hatcher, UGLi)
B) A pre-compiled file containing various helpful, pre-written
functions.
C) A pre-compiled file containing various functions provided as a base
for you as the developer to edit and improve.
D) A list of prototypes for functions that may come in helpful, and all
you need to do is write the implementation.
5) Which library needs to be included to declare a variable of type ofstream?
A)
B)
C)
D)
#include<iostream>
#include<ofstream>
#include<fstream>
#include<ostream>
6) To be able to declare C++ string objects, in standard C++, you need to include a specific
library.
A) True
B) False
7) When writing .h files for classes, these files are referred to as:
A)
B)
C)
D)
head files
header files
pre-loaders
libraries
2
2-Dim Arrays
8) Given
int arr[3][3] = { {0, 1, 2}, {3, 4, 5}, {6, 7, 8} };
How should the element whose value is 5 be accessed?
A) arr[1][2]
B) arr[2][1]
C) arr[2][3]
D) arr[3][2]
E) none of the above
9) In an MxN array, what is the maximum pair of indices that is allowable?
A)
B)
C)
D)
M,N
M-1,N-1
M-2,N-2
None of the above
10) Which of the following function prototypes employs incorrect syntax for its array parameter?
Assume that capitalized identifiers are defined as int constants.
A)void Func( const int singleDim[] );
B)void Func( int threeDim[][][DEPTH_SIZE]);
C)void Func( int& singleDim[ARRAY_SIZE]);
D)both (a) and (b)
E)both (b) and (c)
struct's/Class's
11)
An abstract data type consists of two parts: a specification and an implementation.
A) true
B) false
12)
Consider the following declarations:
struct Point {
int x;
int y;
};
Point p1, p2;
Which of the following code fragments will not compile? Select all choices that apply.
A) p1 = p2;
B) p1.x = p2.x;
C) p1.x = p2.y;
D) cout << p1;
E) None of the above
13) A class creates a user defined datatype.
A) true
B) false
3
14)
A)
B)
C)
D)
E)
Which of the following is not a good # statement to put in Point's interface file?
#ifndef
#define
#endif
#include"Point.h"
All the above are good
15) An array called carList contains elements of struct type Car which has components model,
year and price. Which of the following will reference the year of the third car?
struct Car{
string model;
int year;
double price;
}
Car carList[20];
A) carList[2].Car.year
B) Car[2].year
C) carList.year[2]
D) carList[2].year
16) If a member function has the following prototype:
bool is_win(int& winCount) const;
what does the 'const' signify?
A) The variables passed in cannot be modified
B) The function cannot be modified
C) The return value cannot be modified
D) The class’s variables cannot be modified
E) None of the above
17)
A)
B)
C)
D)
E)
Which of the following is always false when following C++ standards?
constructors have parameters
variables in a class are private, functions are public
instance of a class is the same thing as an object of the class
the specification file is hidden from the user of the class
None of the above -- they all may be true
18) Which of the following statements about structs and classes is false?
A)
B)
C)
D)
E)
Both structs and classes can have member functions.
Both structs and classes can be passed by value.
By default, members of structs and classes are public.
Members of structs and classes are selected by using dot notation.
Aggregate assignment is permitted for both structs and classes.
The following class Info will be used for the next 2 questions
class Info
{
4
private:
string firstName;
char middleInitial;
string lastName;
};
and
int main()
{
Info person[100];
...
}
19) The datatype of person[0] is?
A)
B)
C)
D)
E)
int
Info
an address
string
none of the above
20) The datatype of person[0].firstName.length()
A)
B)
C)
D)
unsigned int
Info
an address
string
21) A class Number has a member function triple that takes no parameters, returns
nothing, and modifies the member variables of the Number object. Which of the
following are correct function headers for the implementation of triple? Select all
choices that apply.
A)
B)
C)
D)
E)
void
void
void
void
void
triple() {...
Number.triple() {...
Number.triple() const {...
Number::triple() {...
Number::triple() const {...
22) Consider the following code fragment:
ifstream f;
f.open(”file.txt”);
Which of the following statements are true?
A) ifstream is a class
B) ifstream is an instance of a class
C) none of the above
5
The following declarations and client code is used in the next
4 questions
1 class Example
2 {
3
private:
4
int m,n;
5
string str;
6
public:
7
Example();
8
Example(int mVal, nVal);
9
void func();
10 };
and client code:
Example alpha;
Example omega;
23) Given the above code, what is the most specific term for the entity named Example() (as
listed on line 7)?
A) data member
B) public member function
C) default constructor
D) abstract data type
E) instance
24) Which identifiers are class objects?
A)
B)
C)
D)
E)
m, n, and str
alpha and omega
Example, m, n, and str
alpha, omega, m, n, and str
func, m, n, and str
25) Which identifiers are class data members?
A)
B)
C)
D)
E)
m, n, and str
alpha and omega
Example, m, n, and str
alpha, omega, m, and n
func and Example
26) What notation does the body of func use to assign the value 3 to n?
A)
B)
C)
D)
E)
n = 3;
Example.n = 3;
Example::n = 3;
alpha.n = 3;
It cannot be done, because n is private.
6