Shared Flashcard Set

Details

Engineering 112 TAMU - Final Exam
Programming in C++ Final Exam
95
Electrical Engineering
Undergraduate 3
04/23/2012

Additional Electrical Engineering Flashcards

 


 

Cards

Term
In C++

double f();

a. says that this double returns a function
b. says that this function returns an double
c. says that f is a function
d. a and b
e. b and c
Definition
e
Term
2. A main function should

a. return 0 if it fails
b. return 1 if it succeeds
c. return a nonzero value if it fails
d. return a nonzero value if it succeeds
e. none of the above
Definition
c. return a nonzero value if it fails
Term
3. std_lib_facilities.h

a. is a header file
b. should be #included
c. contains the code for sqrt
d. a and b
e. a and c
Definition
d. a and b
Term
4. To read something from the keyboard, you may use

a. cin <<
b. cerr >>
c. cout <<
d. cin >>
e. cout >>
Definition
d. cin >>
Term
Type safety

a. is ignored by the C++ compiler
b. refers to making sure only legal values are stored in a variable
c. is impossible in practice, so there is no point in trying
d. can never be violated
e. none of the above
Definition
b. refers to making sure only legal values are stored in a variable
Term
Every type specifies

a. legal values and operations
b. which compiler to use
c. the font and point size
d. whether values are upper or lower case
e. none of the above
Definition
a. legal values and operations
Term
7. \t

a. means divide by t
b. means print the t in italics
c. means a single tab character
d. means a string containing two characters
e. none of the above
Definition
c. means a single tab character
Term
The linker

a. outputs a source code file
b. outputs an object code file
c. outputs a header file
d. outputs an executable file
e. none of the above
Definition
d. outputs a header file
Term
A literal

a. has a name which is its value
b. has a type but not a value
c. has a value but not a type
d. has a name but not a value
e. has a value but not a name
Definition
e. has a value but not a name
Term
cin >> x >> y

a. reads as many characters as it can, consistent with the type of x, then the type of y
b. ignores leading whitespace before x and before y
c. fails if there is no input corresponding to the type of x
d. all of the above
e. none of the above
Definition
d. all of the above
Term
cout

a. converts objects to printable characters
b. converts printable characters to objects
c. fails if the value is too big for one line on the screen
d. all of the above
e. none of the above
Definition
a. converts objects to printable characters
Term
x=x+1;

a. is illegal in C++ since it implies 0=1, for example
b. is an example of a shorthand operator
c. is an assignment followed by an addition
d. is an initialization
e. none of the above
Definition
e. none of the above
Term
+ is overloaded because

a. it is formed from the two characters | and –
b. it is defined the same for strings and numbers
c. it is defined differently for strings and numbers
d. a and b
e. a and c
Definition
c. it is defined differently for strings and numbers
Term
14. The value of (x>y) is
a. -1 or 0
b. true or false
c. the result of outputting object y to stream x
d. of type Boolean (the same as Java)
e. none of the above
Definition
b. true or false
Term
15. == (two equal characters)
a. indicate a typing mistake
b. indicate an if statement
c. indicate a while statement
d. indicate an assignment
e. indicate a comparison
Definition
e. indicate a comparison
Term
16. Variables should generally be initialized
a. when they are declared
b. before they are used
c. after each use
d. a and b
e. a and c
Definition
d. a and b
Term
17. s1 + s2 always means concatenation
a. if s1 and s2 are chars
b. if s1 and s2 are ints
c. if s1 and s2 are strings
d. a and b
e. a and c
Definition
c. if s1 and s2 are strings
Term
Which of the following causes an unsafe conversion warning
a. char lower_case = 'A';
b. int pi = 3.14159;
c. double whole_part = 123456789E+10;
d. string model_number = "40-5098-SPX";
e. none of the above
Definition
b. int pi = 3.14159;
Term
19. %
a. indicates conversion to percent (division by 0.01)
b. indicates conversion to percent (multiplication by 100)
c. indicates the quotient from dividing whole numbers
d. indicates the remainder from dividing whole numbers
e. indicates the quotient times the divisor in whole number division
Definition
d. indicates the remainder from dividing whole numbers
Term
20. The value of (true || x)
a. is always true
b. is always false
c. is true if x is true, and false if x is false
d. is false if x is true, and true if x is false
e. none of the above
Definition
a. is always true
Term
21. The value of (x && false)
a. is always true
b. is always false
c. is true if x is true, and false if x is false
d. is false if x is true, and true if x is false
e. none of the above
Definition
b. is always false
Term
22. The value of (!x)
a. is always true
b. is always false
c. is true if x is true, and false if x is false
d. is false if x is true, and true if x is false
e. none of the above
Definition
d. is false if x is true, and true if x is false
Term
23. The C++ switch statement is logically equivalent to
a. if…else if statements
b. while statements
c. when statements
d. on…off statements
e. none of the above
Definition
a. if…else if statements
Term
24. A C++ for statement is equivalent to
a. an if…else if statement
b. a while statement
c. a switch statement
d. a why statement
e. none of the above
Definition
b. a while statement
Term
BLANK
Definition
a. nothing
Term
26. What is the output of the statements:
int i = 1; while(i<3) cout<<++i<<" ";
a. nothing
b. 1
c. 1 2
d. 2
e. 2 3
Definition
e. 2 3
Term
27. If a function does not return a value, the last statement executed should be
a. break;
b. continue;
c. return;
d. return null;
e. none of the above
Definition
a. return;
Term
28. The first element of a vector v is indicated by
a. v[0]
b. v[1]
c. either v[0] or v[1], depending on whether the vector was initialized to 0 or 1
d. v[v.begin()-1]
e. v[v.begin()]
Definition
a. v[0]
Term
The last element of a vector v is indicated by
a. v[v.size()-1]
b. v[v.size()]
c. either v[v.size()-1] or v[v.size()], depending on whether the vector was initialized to 0 or 1
d. v[v.end()-1]
e. v[v.end()]
Definition
a. v[v.size()-1]
Term
30. A vector v stores
a. values sequentially
b. duplicate values
c. different value types
d. a and b
e. a and c
Definition
d. a and b
Term
31. vector v(8);
a. means v is a vector containing the value 8
b. means vector is a double accessed using v[8]
c. means v is a vector of 8 doubles
d. means each double in v is initialized to 8
e. none of the above
Definition
c. means v is a vector of 8 doubles
Term
32. To add x to the end of vector w you may use
a. w[w.size()+1] = x;
b. w.push_back(x);
c. x.push_back(w);
d. any of the above
e. none of the above
Definition
b. w.push_back(x);
Term
33. Syntax errors
a. are detected by the run-time library
b. are detected by the STL
c. are detected by the linker
d. may not be detected until run time
e. none of the above
Definition
e. none of the above
Term
34. Misspelling sqrt like this:
double sqrrt(double);
double y = sqrrt(2.5);
would most likely result in
a. a compile-time error
b. a linker error
c. an exception
d. all of the above
e. none of the above
Definition
b. a linker error
Term
Leaving out a closing } will most likely result in
a. a compile-time error
b. a linker error
c. an exception
d. all of the above
e. none of the above
Definition
a . a compile-time error
Term
36. To inspect a block of code for run time exceptions, use
a. return exit_code;
b. try {…} catch {…}
c. return -1;
d. error("run time exception");
e. all of the above
Definition
b. try {…} catch {…}
Term
37. The purpose of debugging is
a. to make the source code more readable
b. to eliminate compile-time errors
c. to test the code for correct operation
d. to find and correct logic errors
e. to remove errors in the specification
Definition
d. to find and correct logic errors
Term
38. A token is
a. used where an argument list is unknown
b. one digit of a number
c. composed of an operator and its operands
d. a meaningful value, not divisible into smaller tokens
e. all of the above
Definition
d. a meaningful value, not divisible into smaller tokens
Term
39. A grammar contains
a. rules to generate syntactically correct expressions
b. rules to determine syntactically valid expressions
c. rules to specify the precedence of operations
d. a and b, but not c
e. a, b, and c
Definition
d. a and b, but not c
Term
40. A constructor
a. has the same name as its class or struct
b. has a return type of its class or struct
c. must be defined inside its class or struct
d. all of the above
e. none of the above
Definition
a. the same name as its class or struct
Term
Functions must be
a. defined before they are declared
b. declared before they are called
c. defined before they are called
d. called before they are defined
e. none of the above
Definition
b. declared before they are called
Term
42. Real programs
a. are written from beginning to end in one sitting
b. evolve under pressure of requirements and constraints
c. grow using calls to standard library functions
d. are always large and complicated
e. none of the above
Definition
b. evolve under pressure of requirements and constraints
Term
43. Symbolic constants
a. are not allowed in C++
b. are recommended only for strings
c. are recommended for special values like 0 and 1
d. all of the above
e. none of the above
Definition
e. none of the above
Term
44. Testing tries to
a. handle program errors systematically
b. trace a program’s execution after cleaning up the code
c. break a program by getting it to misbehave
d. all of the above
e. none of the above
Definition
44. Testing tries to
c. break a program by getting it to misbehave
Term
45. Release 1.0 of a program
a. contains all needed feature refinements
b. contains last minute changes to the specification
c. contains fixes to key bugs found during testing
d. a and b
e. b and c
Definition
c. contains fixes to key bugs found during testing
Term
46. Comments in the source code
a. should correctly reflect what the compiler does
b. should be adequate for a reader (not necessarily the original programmer)
c. should be verbose so as to prevent program complexity
d. should restate in English what code does
e. answer not given
Definition
b. should be adequate for a reader (not necessarily the original programmer)
Term
47. An algorithm
a. is a C++ program
b. is a sequence of steps to solve a problem
c. tells what to do in a programming language
d. a and b
e. a and c
Definition
b. is a sequence of steps to solve a problem
Term
48. C++ strings are delimited using
a. matching quotes (“…”)
b. matching quotes (‘…’)
c. matching quotes (“…”)
d. matching quotes (‘…’)
e. none of the above
Definition
e. none of the above
Term
49. C++ function definitions
a. have a return type
b. have a name
c. have a parameter list
d. have a body of instructions to perform
e. all of the above
Definition
e. all of the above
Term
50. End of file
a. is signalled by Ctrl-Z on UNIX or Linux
b. is signalled by Ctrl-Z on Windows
c. is signalled by Ctrl-D on UNIX or Linux have a parameter list
d. a and b
e. b and c
Definition
e. b and c
Term
1. On a graphical window 800 wide by 600 high the lower right-hand corner is at coordinates
a. (600, 0)
b. (0, 800)
c. (799, 599)
d. (599, 799)
e. none of the above
Definition
c. (799, 599)
Term
2. The code in Graph.h
a. gives us access to our graphics library facilities
b. calls FLTK routines
c. must be compiled and linked with our graphics programs
d. all of the above
e. none of the above
Definition
d. all of the above
Term
3. void f(int x); tells us
a. f returns an object of type void
b. f returns an object of type int
c. f returns an object of type x
d. f does not return a value
e. none of the above
Definition
d. f does not return a value
Term
User-defined types
a. are indicated by class or struct
b. are not allowed in C++
c. can only be declared in a header file
d. can only be defined in a header file
e. none of the above
Definition
a. are indicated by class or struct
Term
5. Arguments to a function may be
a. by value
b. by reference
c. by const reference
d. any of the above
e. none of the above
Definition
d. any of the above
Term
6. Classes Line, Axis, Polygon, etc. derive from class Shape
a. so they can share common code
b. so class Window doesn't have to be changed to draw a new shape
c. because they all have line style and color data members
d. all of the above
e. none of the above
Definition
d. all of the above
Term
7. Having the first argument almost always be a Point is an example of
a. particularity
b. regularity
c. precision
d. accuracy
e. none of the above
Definition
b. regularity
Term
8. Public members of a class or struct
a. are visible from the point they are declared to the end of the class
b. are visible anywhere in the class, even above the declaration
c. are visible from the point they are declared to the end of the source file
d. all of the above
e. none of the above
Definition
b. are visible anywhere in the class, even above the declaration
Term
9. An expression which changes the value of a variable
a. may not contain an =
b. may not be on the right-hand side of an =
c. may not be on the left-hand side of an =
d. should not read or write the variable twice
e. none of the above
Definition
c. may not be on the left-hand side of an =
Term
A constructor
a. has the same name as its struct or class
b. does not have a return type
c. leaves an object with a valid value
d. all of the above
e. none of the above
Definition
d. all of the above
Term
Attaching graphical objects to a Simple_window
a. must be done in the correct order if they overlap
b. must be done before wait_for_button() is called
c. enables them to be drawn on the screen
d. all of the above
e. none of the above
Definition
d. all of the above
Term
using namespace std;
a. tells the compiler to look for std::foo if foo is not defined
b. tells the linker to look for foo if std::foo is not defined
c. can also be written as using std namespace;
d. all of the above
e. none of the above
Definition
a. tells the compiler to look for std::foo if foo is not defined
Term
An invariant
a. is a rule for what constitutes a valid value
b. is indicated by the keyword inv
c. can change when operator++ is invoked
d. a and b
e. b and c
Definition
a. is a rule for what constitutes a valid value
Term
A function activation record
a. contains a count of how many times the function has been called
b. does not contain the function's local variables
c. does not contain the function's arguments
d. is created when a function is called that is not inlined
e. none of the above
Definition
d. is created when a function is called that is not inlined
Term
Given the code
enum Month{jan=1,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec};
Month f(Month& m){return Month((m%12) + 1);}
what does f(Month::dec) return?
a. Month::dec
b. Month::jan
c. Month::feb
d. Month::mar
e. none of the above
Definition
b. Month::jan
Term
The keyword static on a local variable
a. indicates that it contains a random garbage value
b. indicates that it is created every time the function is entered
c. indicates that it is only created the first time the function is entered
d. is only allowed inside a class definition
e. none of the above
Definition
c. indicates that it is only created the first time the function is entered
Term
Default initialization
a. is automatically provided for string and vector
b. is not guaranteed for built-in types
c. for global variables is 0
d. all of the above
e. none of the above
Definition
d. all of the above
Term
The scope resolution operator is
a. :
b. ::
c. ;
d. ;;
e. none of the above
Definition
b. ::
Term
Another name for free store is
a. stack
b. heap
c. non-recyclable memory
d. read-only memory
e. none of the above
Definition
b. heap
Term
A vector header
a. contains slots for all the data
b. contains the number of items in the vector
c. contains a reference to the data
d. contains the minimum and maximum legal values for an item
e. none of the above
Definition
e. none of the above
Term
double f(double);
a. declares a double variable f initialized by a double
b. declares double to be a function of one double
c. defines a function f of one double returning a double
d. declares a function f of one double returning a double
e. is not a legal declaration since the f should also be in parentheses
Definition
d. declares a function f of one double returning a double
Term
A const member function
a. is not allowed to change the data members
b. is allowed to change const data members
c. must be defined inside the class
d. all of the above
e. none of the above
Definition
a. is not allowed to change the data members
Term
An operator== should generally return
a. a bool
b. a double
c. a char
d. any of the above
e. none of the above
Definition
a. a bool
Term
For questions 24-30 answer "a" for "declaration but not definition" and
"b" for "declaration and also definition."
24. class Bad_area;
25. class Bad_area{};
26. int x;
27. extern int x;
28. void f(double);
29. void f(double){};
30. struct Point;
Definition
24. class Bad_area; "a"
25. class Bad_area{}; "b"
26. int x; "b"
27. extern int x; "a"
28. void f(double); "a"
29. void f(double a){}; "b"
30. struct Point; "a"
Term
31. A destructor is called
a. when an object goes out of scope
b. when an object is created
c. when an object is initialized
d. all of the above
e. none of the above
Definition
a. when an object goes out of scope
Term
Global variables
a. are visible everywhere
b. are visible everywhere except where there is another variable with the same name
c. are recommended by professional programmers
d. are not allowed in C++
e. none of the above
Definition
b. are visible everywhere except where there is another variable with
the same name
Term
Private data members of a class
a. are visible from the point they are declared to the end of the class
b. are visible only inside the class definition
c. are visible to all members of the class, including function members defined outside the class definition
d. all of the above
e. none of the above
Definition
c. are visible to all members of the class, including function members defined outside the class.
Term
Function arguments are visible
a. only in the function body
b. to the main which calls the function
c. unless there is a global variable with the same name
d. all of the above
e. none of the above
Definition
a. only in the function body
Term
To perform input and output, our program interfaces directly
a. to a keyboard, a display, a disk drive, etc.
b. to an input/output library
c. to a device driver
d. all of the above
e. none of the above
Definition
b. to an input/output library
Term
An input stream takes characters sequentially from a buffer and
a. converts them into values of various types
b. writes values to a console, a file, main memory, etc.
c. returns an error state
d. a and c
e. b and c
Definition
d. a and c
Term
Standard stream operators >> and <<
a. are type safe
b. format values
c. are extensible to user defined types
d. all of the above
e. none of the above
Definition
d. all of the above
Term
A disk and a flash drive are ideal to store files because
a. file streams can be repositioned using seekg() and seekp()
b. files are really just byte sequences
c. these devices retain their data when power is off
d. data loss can never occur on these devices
e. their cost-per-byte to performance ratio is better than main memory
Definition
c. these devices retain their data when power is off
Term
Assume the following code:

struct Reading {
int hour;
double temp;
ostream& operator << (ostream& os, const Reading& rng) {
return os << '(' << _____ << ',' << _____ << ')';
}
};

To override << for the user defined type Reading, the two blanks should be
a. os.hour and os.temp
b. rng.hour and rng.temp
c. hour and temp
d. any of the above
e. none of the above
Definition
b. rng.hour and rng.temp
Term
Assume the following code:
void skip_to_int() {
if(cin.fail()) {
cin.clear();
char ch;
while (cin >> ch) {
if (isdigit(ch)) {
cin.unget();
return;
}
}
}
}

The purpose of the while loop in the above code is to
a. consume characters in the standard input stream and return
b. clear the fail state of the standard input stream
c. return as soon as a non-digit is located in the standard input stream
d. put all digit characters back into the standard input stream
e. point the standard input stream to the first digit in the stream and return
Definition
e. point the standard input stream to the first digit in the stream and return
Term
An important question to repeatedly ask in software development is
a. Why am I doing this?
b. How can I make the code run faster?
c. What do we really want the code to do?
d. When is enough coding enough?
e. Where is the best place to locate functions?
Definition
e. Where is the best place to locate functions?
Term
Customizing input/output refers to
a. changing default outputs to match user preferences
b. changing default inputs to match user preferences
c. accommodating existing file specifications
d. any of the above
e. none of the above
Definition
d. any of the above
Term
The endl output manipulator is equivalent to
a. '\n'
b. "\n"
c. '\n' << flush
d. flush
e. all of the above
Definition
c. '\n' << flush
Term
The setw(n) manipulator controls how much space a value takes up
a. by setting a maximum of n output characters for the field width
b. by setting a minimum of n output characters for the field width
c. by not setting a maximum of n output characters for the field width
d. by not setting a minimum of n output characters for the field width
e. none of the above
Definition
b. by setting a minimum of n output characters for the field width
Term
Using the open flags ios::in|ios::out|ios::binary opens a file for
a. appending input, truncating output, binary format
b. binary input/output
c. truncation of binary input/output
d. adding binary input/output at the end of the file
e. none of the above
Definition
b. binary input/output
Term
The output of cout << scientific << setprecision(4) << 12.3456; is
a. 1.2346e+001
b. 12.2345
c. 1.2345e+001
d. 12.35
e. 0.124e+002
Definition
a. 1.2346e+001
Term
Knowing the bit pattern for the text character '4' has a decimal value of 52, which choice pertains to a text file and not a binary file?
a. 01010010
b. 00000100
c. 00110100
d. any of the above
e. none of the above
Definition
c. 00110100
Term
A default constructor
a. is automatically supplied if there are no constructors defined
b. is a constructor with no arguments
c. should be defined if there is a non-default constructor defined
d. all of the above
e. none of the above
Definition
d. all of the above
Term
To convert a double value x to a string in a program use
a. string s; ostringstream oss(s); oss << x;
b. istringstream iss(x); string s; iss >> s;
c. string s = x;
d. any of the above
e. none of the above
Definition
a. string s; ostringstream oss(s); oss << x;
Term
A const variable
a. is illegal in C++
b. may be assigned to, but not initialized
c. may be initialized, but not assigned to
d. may only be assigned to inside a constructor
e. none of the above
Definition
c. may be initialized, but not assigned to
Term
Which pair of values is the same in a C++ program?
a. 0x10 and A
b. 010 and 12
c. 0x4 and 04
d. 0xAA and 1010
e. none of the above
Definition
c. 0x4 and 04
Supporting users have an ad free experience!