943,640 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 316
  • C++ RSS
Apr 15th, 2009
0

new to c++ need help

Expand Post »
i have following code, i am starting a college project and need help
C++ Syntax (Toggle Plain Text)
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5. class ba146{
  6.  
  7. private:
  8. int capacity;
  9. int totalSeatWindow;
  10. int totalSeatAisle;
  11. int totalSeatMiddle;
  12.  
  13. public:
  14. string timeOfArrival;
  15. string timeOfDeparture;
  16. string departureCity;
  17. string arrivalCity;
  18. string flight;
  19. string seatType;
  20. int occupiedSeatWindow ;
  21. int occupiedSeatAisle;
  22. int occupiedSeatMiddle;
  23.  
  24. ba146(){ //Constructor
  25.  
  26. capacity=120;
  27. totalSeatWindow=40;
  28. totalSeatAisle=40;
  29. totalSeatMiddle=40;
  30. occupiedSeatWindow=0;
  31. occupiedSeatAisle=0;
  32. occupiedSeatMiddle=0;
  33. };
  34. int freeSeat(){
  35.  
  36. return capacity-(occupiedSeatWindow+occupiedSeatAisle+occupiedSeatMiddle);
  37. }
  38.  
  39.  
  40.  
  41. };
  42. int main(int argc, char* argv[])
  43. {
  44. printf("Hello World!\n");
  45. ba146 fly;
  46. fly.timeOfArrival="Dublin\n";
  47.  
  48. cout<<fly.timeOfArrival;
  49.  
  50. cout<<fly.freeSeat;
  51.  
  52. return 0;
  53. }
but it gives me a warning , and doesnt print out the 120 like i thought it should.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SmokyMo is offline Offline
8 posts
since Oct 2007
Apr 15th, 2009
1

Re: new to c++ need help

>cout<<fly.freeSeat;
freeSeat is a function. Even if there are no arguments, you still need the (empty) parameter list:
C++ Syntax (Toggle Plain Text)
  1. cout<< fly.freeSeat() <<'\n';
Last edited by Narue; Apr 15th, 2009 at 1:32 pm.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Apr 15th, 2009
0

Re: new to c++ need help

Change this line:
cout<<fly.freeSeat;
to this:
cout<<fly.freeSeat(); Remember that freeSeat is a function .

Edit: I guess Narue was faster
Last edited by unbeatable0; Apr 15th, 2009 at 1:32 pm.
Reputation Points: 42
Solved Threads: 13
Junior Poster in Training
unbeatable0 is offline Offline
90 posts
since Sep 2008
Apr 15th, 2009
0

Re: new to c++ need help

thanks a lot for quick reply, it works . really amatuer mistake but i will get lot of them. java seems so simple compare to c++, maybe thats why they say java is kinder garden stuff
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SmokyMo is offline Offline
8 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Confuse with traverse
Next Thread in C++ Forum Timeline: How to make Visual Studio 2005 C++ MSI?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC