hi, i am getting two error. i have three separate files throttle.h, throttle.cpp, usingthrottle.c pp
--------------------Configuration: usingthrottle - Win32 Debug--------------------
Compiling...
throttle.cpp
C:\cd250\thrott le.cpp(45) : error C2065: 'top_postion' : undeclared identifier
C:\cd250\thrott le.cpp(54) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.
--------------------Configuration: usingthrottle - Win32 Debug--------------------
Compiling...
throttle.cpp
C:\cd250\thrott le.cpp(45) : error C2065: 'top_postion' : undeclared identifier
C:\cd250\thrott le.cpp(54) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.
Code:
//FILE: throttle.h //CLASS HEADER FILE of throttle class throttle { public: // CONSTRUCTOR & DESTRUCTOR throttle(); //fill in precondition and postcondition throttle(int size); // Precondition: size > 0; // Postcondition: Throttle has size positions above the shutoff position, and its current position is off. // MODIFICATION MEMBER FUNCTIONS void shut_off(); //fill in precondition and postcondition void shift(int amount); // Precondition: None // Postcondition: Throttle’s position is moved by amount (but not below 0 or above top position). // If amount would move throttle beyond 0, set to 0. If amount would move throttle beyond top position, // set throttle to top position. // CONSTANT MEMBER FUNCTIONS bool is_on() const; // Precondition: None // Postcondition: false if position is zero, true otherwise private: int top_position; int position; };
Code:
// FILE: throttle.cpp // CLASS IMPLEMENTION FILE of throttle #include "throttle.h" #include <cassert> throttle::throttle() //fill in precondition and postcondition //precondition: none //postcondition: { top_position = 1; position = 0; } throttle::throttle(int size) // Precondition: size > 0; // Postcondition: Throttle has size positions above the shutoff position, and its current position is off. { //fill in correct code assert(size > 0); top_position = size; position = 0; } void throttle::shut_off() //fill in precondition and postcondition //precondition: none //postcondition: the throttle has been turned off. { position = 0; } void throttle::shift(int amount) // Precondition: None // Postcondition: Throttle’s position is moved by amount (but not below 0 or above top position). If amount would move throttle beyond 0, set to 0. If amount would move throttle beyond top position, set throttle to top position. { // fill in correct code position += amount; if (position <0 ) position = 0; else if (position > top_position) position = top_postion; } bool throttle::is_on() const; // Precondition: None // Postcondition: false if position is zero, true otherwise { return (postion > 0); }
Code:
#include "throttle.h" #include <iostream> using namespace std; //creates two throttles and shifts the second throttle an inputted amount. void main(){ throttle t1; int value; cout << "Type in a throttle size." << endl; cin >> value; throttle t2(value); cout<< "Type in a shift amount" << endl; cin >> value; t2.shift(value); if (t2.is_on()) cout << "Throttle on" << endl; else cout << "Throttle off" << endl; }
Comment