By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

program

P: 30
hi, i am getting two error. i have three separate files throttle.h, throttle.cpp, usingthrottle.cpp

--------------------Configuration: usingthrottle - Win32 Debug--------------------
Compiling...
throttle.cpp
C:\cd250\throttle.cpp(45) : error C2065: 'top_postion' : undeclared identifier
C:\cd250\throttle.cpp(54) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.


Expand|Select|Wrap|Line Numbers
  1. //FILE: throttle.h
  2. //CLASS HEADER FILE of throttle
  3.  
  4. class throttle
  5. {
  6. public:
  7.     // CONSTRUCTOR & DESTRUCTOR
  8.     throttle();
  9.     //fill in precondition and postcondition
  10.  
  11. throttle(int size);
  12.     // Precondition:  size > 0;
  13. // Postcondition: Throttle has size positions above the shutoff position, and its current position is off.
  14.  
  15.  
  16.     // MODIFICATION MEMBER FUNCTIONS
  17.     void shut_off();
  18.     //fill in precondition and postcondition
  19.  
  20. void shift(int amount);
  21.     // Precondition: None
  22. // Postcondition: Throttle’s position is moved by amount (but not below 0 or above top position).  
  23. // If amount would move throttle beyond 0, set to 0.  If amount would move throttle beyond top position, 
  24. // set throttle to top position.
  25.  
  26.     // CONSTANT MEMBER FUNCTIONS
  27.     bool is_on() const;
  28. // Precondition: None
  29. // Postcondition: false if position is zero, true otherwise
  30.  
  31. private:
  32.     int top_position;
  33.     int position;
  34. };






Expand|Select|Wrap|Line Numbers
  1. // FILE: throttle.cpp
  2. // CLASS IMPLEMENTION FILE of throttle
  3.  
  4. #include "throttle.h"
  5. #include <cassert> 
  6. throttle::throttle()
  7. //fill in precondition and postcondition
  8.  
  9. //precondition: none
  10. //postcondition: 
  11. {
  12.     top_position = 1;
  13.     position = 0;
  14. }
  15.  
  16. throttle::throttle(int size)
  17. // Precondition:  size > 0;
  18. // Postcondition: Throttle has size positions above the shutoff position, and its current position is off.
  19. {
  20.     //fill in correct code
  21.  
  22. assert(size > 0);
  23. top_position = size;
  24. position = 0;
  25.  
  26. }
  27.  
  28. void throttle::shut_off()
  29. //fill in precondition and postcondition
  30. //precondition: none
  31. //postcondition: the throttle has been turned off.
  32. {
  33.     position = 0;
  34. }
  35.  
  36. void throttle::shift(int amount)
  37. // Precondition: None
  38. // 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.
  39. {
  40.     // fill in correct code
  41. position += amount;
  42. if (position <0 )
  43.    position = 0;
  44. else if (position > top_position)
  45. position = top_postion;
  46.  
  47.  
  48.  
  49. }
  50.  
  51. bool throttle::is_on() const;
  52. // Precondition: None
  53. // Postcondition: false if position is zero, true otherwise
  54. {
  55.  
  56.  
  57. return (postion > 0);
Expand|Select|Wrap|Line Numbers
  1. #include "throttle.h"
  2. #include <iostream>
  3. using namespace std;
  4. //creates two throttles and shifts the second throttle an inputted amount.
  5. void main(){
  6.     throttle t1;
  7.     int value;
  8.     cout << "Type in a throttle size." << endl;
  9.     cin >> value;
  10.     throttle t2(value);
  11.     cout<< "Type in a shift amount" << endl;
  12. cin >> value;
  13.     t2.shift(value);
  14.     if (t2.is_on())
  15.         cout << "Throttle on" << endl;
  16.     else
  17.         cout << "Throttle off" << endl;    
  18. }
Feb 21 '07 #1
Share this Question
Share on Google+
5 Replies


P: 30
I got it first one.
Feb 22 '07 #2

P: 30
now i am getting an error.
C:\cd250\throttle.cpp(54) : error C2447: missing function header (old-style formal list?)

throttle::throttle()

{
top_position = 1;
position = 0;
}

i did not understand this part too.
Feb 22 '07 #3

P: 30
please help meeeeeeeee
Feb 22 '07 #4

Banfa
Expert Mod 5K+
P: 8,916
Expand|Select|Wrap|Line Numbers
  1. bool throttle::is_on() const;
  2. // Precondition: None
  3. // Postcondition: false if position is zero, true otherwise
  4. {
  5.  
  6.  
  7. 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
Feb 22 '07 #5

P: 30
Thank u .I got it
Feb 23 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.