new to c++ need help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2007
Posts: 8
Reputation: SmokyMo is an unknown quantity at this point 
Solved Threads: 0
SmokyMo SmokyMo is offline Offline
Newbie Poster

new to c++ need help

 
0
  #1
Apr 15th, 2009
i have following code, i am starting a college project and need help
  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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,847
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: new to c++ need help

 
1
  #2
Apr 15th, 2009
>cout<<fly.freeSeat;
freeSeat is a function. Even if there are no arguments, you still need the (empty) parameter list:
  1. cout<< fly.freeSeat() <<'\n';
Last edited by Narue; Apr 15th, 2009 at 1:32 pm.
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 90
Reputation: unbeatable0 is an unknown quantity at this point 
Solved Threads: 12
unbeatable0 unbeatable0 is offline Offline
Junior Poster in Training

Re: new to c++ need help

 
0
  #3
Apr 15th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 8
Reputation: SmokyMo is an unknown quantity at this point 
Solved Threads: 0
SmokyMo SmokyMo is offline Offline
Newbie Poster

Re: new to c++ need help

 
0
  #4
Apr 15th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC