C++ Midterm Flashcards
(37 cards)
State the following C/C++ expression below abbreviates:
a[8] ______________
- (a + 8)
Expand the Acronym RTTI
Run time Type Identification
Briefly describe ‘reflection’ in java
The ability to learn at runtime the class to which an object belongs, and properties of that class. Basic tools: getClass(), instanceOf
T/F java allows multiple inheritance
F
T/F java does not allow pointer arithmetic
T
C allows branching into the middle of a block but c++ does not
F
in c++ an int must contain precisely 32 bits in binary
F
C++ allows the statement 17;
T
in C++ a struct can contain both fields and member functions
T
Java and C++ have precisely three access modes
F
the object class is inherited by each java class
T
Assume a class declared as class stuff { string a,b;} provide a single constructor for stuff which works as follows: the constructor can be called with two, one or zero parameters.
public stuff(string c = "", string d = ""){ a = c; b = d; }
Assume a class declared as class stuff { string a,b;} provide a copy constructor for this class which does not result in 'sharing' of the string value for the two copies
stuff(const staff &s) { stuff temp = new staff(); temp a = s *a; temp b = s *b; return temp;}
Assume a class ‘rational’ for rational number. Give two prototypes for an override of +, one a friend function, and the other not. Indicate how each is called by giving example code snippets.
friend rational operator + (rational r1, rational r2)
rational operator + (rational r)
first called by roat = r1 + r2; [r + (r1,r2)]
2nd called by roat = r1+(r2) [or r1+r2]
Suppose we have, assuming a rational number class,
const rational half = new rational (1,2);
Given the half is constant, what kind of messages can be sent to half? Indicate the syntax of a valid method being use this way.
Message must be “constant member function”
foo(___) const{____}
Briefly discuss whether Java or C++ is better about allowing a user to write his own exception handlers for runtime exceptions
Java is better: user can control dozens of checked exception handlers using catch
Describe a specific runtime exception in c++ where the user can redo the default exception handler
heap underflow
In C using the static modifier on a global constant affects scope: Explain
Changes scope from program scope to file scope
In C++ the scope resolution operator can be used as a unary operator (one input) although it usually has two. What is the unary version good for?
;;a is used to refer to a global entity named ‘a’
How was the io class fstream used in an example given in class? What ‘kind’ of io was it used for?
The two uses are random io and update io class example was random io
What is the main difference between a C++ parametrized macro and a C++ inline method that is declared in a class but defined external to a class? Give very short examples of each
Big difference is absense of type checking with a macro Ex: #define foo(a,b) (a+b)/2
inline int foo(int i, int i){
return (i +i)/2}
State how to determine, by looking at the code, if a class is C++ is an abstract class.
It should contain at least one pure fn,
ex: void foo() = 0;
Describe briefly the difference between an abstract Java class and a Java interface.
Abstract class can contain variables and defined methods, Interfaces only constants and method prototypes. Also can only inherit one abstract class, but can implement many interfaces
If subclass sub privately inherits public variable x from class super, state the accessibility of x within sub
private