blob: 18b0b6ae48efd10c535268bae4fd2a0e20b887b2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
// FILE: throttle.cxx
// CLASS IMPLEMENTED: throttle (See throttle.h for documentation.)
#include <cassert> // Provides assert
#include "throttle.h" // Provides the throttle class definition
using namespace std; // Allows all Standard Library items to be used
namespace main_savitch_2A
{
throttle::throttle( )
{ // A simple on-off throttle
top_position = 1;
position = 0;
}
throttle::throttle(int size)
// Library facilities used: cassert
{
assert(size > 0);
top_position = size;
position = 0;
}
void throttle::shift(int amount)
{
position += amount;
if (position < 0)
position = 0;
else if (position > top_position)
position = top_position;
}
}
|