Exercises
- The inclusion guard statements for the header file STRING.H would be:
#ifndef STRING_H
#define STRING_H
...
#endif - The following is one possible answer:
0: #include
1:
2: using namespace std;
3: #ifndef DEBUG
4: #define ASSERT(x)
5: #elif DEBUG == 1
6: #define ASSERT(x) \
7: if (! (x)) \
8: { \
9: cout << “ERROR!! Assert “ << #x << “ failed” << endl; \
10: }
11: #elif DEBUG == 2
12: #define ASSERT(x) \
13: if (! (x) ) \
14: { \
15: cout << “ERROR!! Assert “ << #x << “ failed” << endl; \
16: cout << “ on line “ << LINE << endl; \
17: cout << “ in file “ << FILE << endl; \
18: }
19: #endif - The following is one possible answer:
#ifndef DEBUG
#define DPRINT(string)
#else
#define DPRINT(STRING) cout << #STRING ;
#endif - The following is one possible answer:
class myDate
{
public:
// stuff here...
private:
unsigned int Month : 4;
unsigned int Day : 8;
unsigned int Year : 12;
}
874 Appendix D
32 0672327112_app_d.qxd 11/19/04 12:30 PM Page 874