Question: Two simple questions: 1./2. Modify the definition on page 35 to creat a new.... PROGRAMMING ExAMPLE: The Throttle Class the throttle class Our first example





Two simple questions: 1./2. Modify the definition on page 35 to creat a new....
PROGRAMMING ExAMPLE: The Throttle Class the throttle class Our first example of a class is a new data type to store and manipulate the status of a simple throttle. Classes such as our throttle class appear in programs that Classes and Members 35 simulate real-world objects. For instance, a flight simulator might include classes for the plane and various parts of the plane such as the engines, the rudder, the altimeter, and even the throttle. The simple throttle that we have in mind is a lever that can be moved to con- trol fuel flow. The throttle we have in mind has a single shutoff point (where there is no fuel flow) and a sequence of six on positions where the fuel is flowing at progressively higher rates. At the topmost position, the fuel flow is fully on At the intermediate positions, the fuel flow is proportional to the location of the lever. For example, with six possible positions, and the lever in the fourth posi- 5 FAST 2 SLOW OFF tion, the fuel flows at 7 of its maximum rate. One function provided with the class permits a program to initialize a throttle PROGRAMMING ExAMPLE: The Throttle Class the throttle class Our first example of a class is a new data type to store and manipulate the status of a simple throttle. Classes such as our throttle class appear in programs that Classes and Members 35 simulate real-world objects. For instance, a flight simulator might include classes for the plane and various parts of the plane such as the engines, the rudder, the altimeter, and even the throttle. The simple throttle that we have in mind is a lever that can be moved to con- trol fuel flow. The throttle we have in mind has a single shutoff point (where there is no fuel flow) and a sequence of six on positions where the fuel is flowing at progressively higher rates. At the topmost position, the fuel flow is fully on At the intermediate positions, the fuel flow is proportional to the location of the lever. For example, with six possible positions, and the lever in the fourth posi- 5 FAST 2 SLOW OFF tion, the fuel flows at 7 of its maximum rate. One function provided with the class permits a program to initialize a throttle
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
