program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bhanusharma
    New Member
    • Feb 2007
    • 30

    program

    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.


    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;	
    }
  • bhanusharma
    New Member
    • Feb 2007
    • 30

    #2
    I got it first one.

    Comment

    • bhanusharma
      New Member
      • Feb 2007
      • 30

      #3
      now i am getting an error.
      C:\cd250\thrott le.cpp(54) : error C2447: missing function header (old-style formal list?)

      throttle::throt tle()

      {
      top_position = 1;
      position = 0;
      }

      i did not understand this part too.

      Comment

      • bhanusharma
        New Member
        • Feb 2007
        • 30

        #4
        please help meeeeeeeee

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Code:
          bool throttle::is_on() const[b];[/b]
          // Precondition: None
          // Postcondition: false if position is zero, true otherwise
          {
          	
          
          return (postion > 0);
          }
          You have a ; after the function header.

          You have also misspelled position in a couple of places leaving out the first i.


          It is not 100% clear if this is a coursework question or not, however if it is then you should not have posted the full source of your program. Please read the Posting Guidelines

          Comment

          • bhanusharma
            New Member
            • Feb 2007
            • 30

            #6
            Thank u .I got it

            Comment

            Working...