943,850 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 739
  • C++ RSS
Mar 31st, 2008
0

class

Expand Post »
hi ,
my program calculate the area of rectangle , and I have some errors , and dont know how to correct them .
this is the program ,
C++ Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bis student is offline Offline
16 posts
since Dec 2007
Mar 31st, 2008
0

Re: class

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
Featured Poster
Reputation Points: 431
Solved Threads: 116
Practically a Master Poster
Agni is offline Offline
654 posts
since Dec 2007
Mar 31st, 2008
0

Re: class

but it is still have errors,
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bis student is offline Offline
16 posts
since Dec 2007
Mar 31st, 2008
0

Re: class

set the prototype of functions
like this
C++ Syntax (Toggle Plain Text)
  1. void setW();
  2. void setL();
replace above two with
C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 113
Solved Threads: 20
Junior Poster
Laiq Ahmed is offline Offline
147 posts
since Jun 2006
Mar 31st, 2008
0

Re: class

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 13
Solved Threads: 7
Light Poster
BlackJavaBean is offline Offline
38 posts
since Feb 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: deleting a random node from a singly linked list
Next Thread in C++ Forum Timeline: Converting Integer to double





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


Follow us on Twitter


© 2011 DaniWeb® LLC