class

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2007
Posts: 16
Reputation: bis student is an unknown quantity at this point 
Solved Threads: 0
bis student's Avatar
bis student bis student is offline Offline
Newbie Poster

class

 
0
  #1
Mar 31st, 2008
hi ,
my program calculate the area of rectangle , and I have some errors , and dont know how to correct them .
this is the program ,
  1. #include<iostream>
  2. using namespace std;
  3. class Rectangle {
  4. private:
  5. double length ,width ;
  6. public:
  7. double getW();
  8. double getL();
  9. void setW();
  10. void setL(); double findArea(double&;double&);
  11. void display();
  12. };
  13. double Rectangle::getW(){
  14. return width ;
  15. }
  16. double Rectangle::getL(){
  17. return length ;
  18. }
  19.  
  20.  
  21.  
  22. void Rectangle::setW(double num1){
  23.  
  24. width=num1;
  25. }
  26. void Rectangle::setL(double num2){
  27. length=num2;
  28. }
  29. double Rectangle::findArea(double &w;double &l){
  30. int area;
  31. w=width;
  32. l=length;
  33. area=length*width;
  34. return area ;
  35.  
  36. void Rectangle::display(){
  37. cout<<length<<endl;
  38. cout<<width<<endl;
  39. }
  40. int main (){
  41. double x=8.3,y=5.8;
  42. Rectangle rec ;
  43. rec.setW(x);
  44. rec.setL(y);
  45. rec.getW();
  46. rec.getL();
  47. rec.findArea(x,y);
  48. rec.display();
  49. }
  50. return 0 ;
  51. }
Last edited by bis student; Mar 31st, 2008 at 10:19 am.
there are always hope
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 444
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 68
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Re: class

 
0
  #2
Mar 31st, 2008
To start with change

findArea(double&;double &)

to

findArea(double&,double &)

replace the ';' with ','

arguments in a function defn n decl are separated by comma not semi-colon
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 16
Reputation: bis student is an unknown quantity at this point 
Solved Threads: 0
bis student's Avatar
bis student bis student is offline Offline
Newbie Poster

Re: class

 
0
  #3
Mar 31st, 2008
but it is still have errors,
there are always hope
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 147
Reputation: Laiq Ahmed will become famous soon enough Laiq Ahmed will become famous soon enough 
Solved Threads: 20
Laiq Ahmed Laiq Ahmed is offline Offline
Junior Poster

Re: class

 
0
  #4
Mar 31st, 2008
set the prototype of functions
like this
  1. void setW();
  2. void setL();
replace above two with
  1. void setW(double num1)
  2. void setL(double num2)

remember to add semicolon where required.
Last edited by Laiq Ahmed; Mar 31st, 2008 at 10:44 am. Reason: Hinting
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 30
Reputation: BlackJavaBean is an unknown quantity at this point 
Solved Threads: 7
BlackJavaBean's Avatar
BlackJavaBean BlackJavaBean is offline Offline
Light Poster

Re: class

 
0
  #5
Mar 31st, 2008
  1. #include<iostream>
  2. using namespace std;
  3. class Rectangle {
  4. private:
  5. double length ,width ;
  6. public:
  7. double getW();
  8. double getL();
  9. void setW(); //<-Needs to pass a double
  10. void setL(); //<- Needs to pass a double
  11. double findArea(double&;double&); //<-See chandra.rajat's post
  12. void display();
  13. };
  14. double Rectangle::getW(){
  15. return width ;
  16. }
  17. double Rectangle::getL(){
  18. return length ;
  19. }
  20.  
  21.  
  22.  
  23. void Rectangle::setW(double num1){//<-Doesn't match prototype
  24.  
  25. width=num1;
  26. }
  27. void Rectangle::setL(double num2){//<-Doesn't match prototype
  28. length=num2;
  29. }
  30. double Rectangle::findArea(double &w;double &l){//<-See chandra.rajat's post
  31. int area;
  32. w=width;
  33. l=length;
  34. area=length*width;
  35. return area ;
  36. /*} <-Missing a closing curly brace here*/
  37.  
  38. void Rectangle::display(){
  39. cout<<length<<endl;
  40. cout<<width<<endl;
  41. }
  42. int main (){
  43. double x=8.3,y=5.8;
  44. Rectangle rec ;
  45. rec.setW(x);
  46. rec.setL(y);
  47. rec.getW();
  48. rec.getL();
  49. rec.findArea(x,y);
  50. rec.display();
  51. }//<-Extra curly brace
  52. return 0 ;
  53. }

Aside from chandra.rajat's observations, there are just a couple of prototype mismatches and a missing/hanging curly brace.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC