Who think is goog in c++ rezolve this.
Any solution ,send me: istynet@yahoo.com
General C++ questions
1. What is the difference between const, inline and #define?
a. What is the problem with #define directive?
Please explain the disadvantages of using a macro as follows:
#define MAX(a,b) ((a) > (b) ? (a) : (b))
b. How can you re-write the above macro using inline and templates?
c. How can you use the preprocessor to simulate templates?
2. How to avoid hiding global new?
a. Consider the example below. What’s wrong with it?
typedef void (*PEHF)();
class X {
public:
void f();
// operator new allowing specification of
// error-handling function
void *operator new(size_t size, PEHF pehf);
};
void specialErrorHandler(); //definition omitted
X *xp1 = new (specialErrorHandler) X;
X *xp2 = new X;
How to avoid the problem?
3. Is the order of variables in the initialization list important?
a. Consider the following class. What’s the problem with it?
class Array {
private:
int *data;
unsigned size;
int lBound, hBound;
What about static data member initialization? When does it happen?
4. What should be the return vales of operator= and why?
a. Consider the following class:
class String {
private:
char *data;
public:
String(const char *value = 0);
};
b. Please write operator= for this class. One that accepts String objects, the second that takes char*.
c. What is the signature of the default version?
d. Which one of the following snippets is right? Why?
What happens in the second case?
5. Why it is a good choice to avoid data members in the public interface?
a. Please explain it with ‘consistency’ and accessibility!
b. What is the third reason (probably the biggest advantage) not to have data members in the public interface?
(Hint: functional abstraction)
6. Why to use const if possible?
a. Please consider the following declarations. Please explain the meaning of the const keyword.
e. What does it mean for a member function to be const?
(Hint: bit wise, conceptual)
f. Consider the following example. What is the problem and how would you resolve it?
(Hint: cast away ‘constness’)
class String {
private:
char *data;
unsigned dataLength;
unsigned lengthIsValid:1;
b. Does B still have the value “Hello world” or has it changed into a mother’s greeting? What is the correct implementation of String::operator char*?
9. What are inline functions good for?
a. Does inline functions have any influence on the size of the code?
b. Is ‘inline’ a hint or a command to the compiler, i.e. can the compiler ignore inline directive?
c. What happens (if possible at all) if the compiler chooses not to inline a function in the following situation?
// This is file example.h
inline void f() { . . . };
. . .
// This is file source1.cc
#include “example.h” //includes definition of f
// This is file source2.cc
#include “example.h” // also includes definition
// of f
d. What happens in the following situation with an inline function? How does the compiler resolve the problem?
inline f() { . . . };
void (*pf)() = f; // pf points to f
main()
{
f(); // an inline call to f
pf(); // a non-inline call to f
}
e. Can you tell a couple examples why inline functions can be hard to manage?
(Hint: debugging)
10. What is the purpose of a multithreaded program?
a. Where is it appropriate to use multithreaded applications?
b. How would you make a thread waiting?
Why it is a bad idea to write endless loops in a multithreaded environment
Sorry dearie, but you must be new on this forum and that's why you probably don't know that we don't do other peoples' homework, let alone solve their exams. If you have a specific question about a program you're writing by yourslef, you're welcome to ask for our advice. If it's plain cheating, then I'm sorry but this is the wrong place. This thread is closed, with reason.
Bookmarks