| I l @ ve RuBoard |
14.6 The Meaning of staticThe keyword static has many different meanings in C++. Table 14-1 is a complete list of the various ways static can be used. Table 14-1. The meanings of static
|
| I l @ ve RuBoard |
| I l @ ve RuBoard |
14.7 Programming ExercisesExercies 14-1: Two classes share a file. Other areas of the program need to know when this file is busy. Create a function that returns 1 when the file is being used by either of these two classes. Exercies 14-2: You are asked to write a booking program for the veterinarian; Dr. Able Smith, PHD (Pigs, Horses, Dogs). Define a class type for each animal. Each class should keep track in a private static variable of the number of animals that have been defined using that class. Define a function that returns the total number of animals (all three types combined). Exercies 14-3: Write a class in which each instance of the class can access a stack ”not one stack per instance, but one stack, period. Any instance of the class can lock the stack for its own exclusive use and unlock it later. Define member functions to perform the lock and unlock functions. As an added attraction, make the unlock function check to see that the current instance of the class was the same instance that locked the stack in the first place. Exercies 14-4: You need to supply some I/O routines for handling lines in a file. The basic definition of the line-number class is:
class line_number {
public:
void goto_line(int line);
int get_current_line( );
long int get_char_pos( );
}
The member functions are defined as:
Several
line_number
classes may be in use at any time. The class maintains its own internal list so that it
For example, suppose there are four active
line_number
You wish to move
current_location
to line 90. The
goto_line
function would search the list for the line nearest the new location (in this case
chapter_start
) and use it to jump to line 87. It then would read the file, character by character, until it saw three end-of-line
|
| I l @ ve RuBoard |