Last CLASS method needs help... PAIR::area()

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

Join Date: Oct 2005
Posts: 20
Reputation: ToySoldier is an unknown quantity at this point 
Solved Threads: 0
ToySoldier's Avatar
ToySoldier ToySoldier is offline Offline
Newbie Poster

Last CLASS method needs help... PAIR::area()

 
1
  #1
Sep 28th, 2006
Been working on this project for last 2 nights. Cant get rid of this error message on my last method PAIR::area() . It's defined at the bottom of my program.

Everything else compiles... builds... executes just fine. Rusty on the basics and trying to figure out methods.... here is my error message:

error C2601: 'area' : local function definitions are illegal
Error executing cl.exe.

It sounds obvious but I think I'm just a little blurry eyed. Project is due tonight (Thur) at 6pm. I think I need to go start at chapter one again It's has to be something dumb I'm doing.

Any help appreciated.

  1. class PAIR
  2.  
  3. {private:
  4. int a;
  5. int b;
  6.  
  7. public:
  8.  
  9. void print();
  10. PAIR();
  11. PAIR(int);
  12. PAIR(int,int);
  13. ~PAIR();
  14.  
  15. void swap();
  16. int diff();
  17. int big();
  18. int area();
  19. };
  20.  
  21. int main()
  22. {
  23. PAIR c, d(2), e(12,13);
  24.  
  25. int ans;
  26. c.print();
  27. d.print();
  28. e.print();
  29.  
  30.  
  31. d.swap();
  32. d.print();
  33. e.swap();
  34. e.print();
  35.  
  36. ans = c.diff();
  37. cout << "\nThe answer to c.diff() is " << ans << endl;
  38.  
  39. int big = e.big () ;
  40. cout << "\nThe larger number of e.big() is " << big << endl << endl;
  41.  
  42. return 0;
  43. }
  44.  
  45. PAIR::PAIR()
  46. {
  47. a = 2;
  48. b = 3;
  49. }
  50.  
  51. void PAIR::print()
  52. {cout << a << " " << b << endl;}
  53.  
  54. PAIR:: ~PAIR()
  55. {
  56. cout << "Display Destructor Message" << endl;
  57. }
  58.  
  59. PAIR::PAIR(int p1)
  60. {a=p1;
  61. b=p1;}
  62.  
  63. PAIR::PAIR(int p1,int p2)
  64. {
  65. a=p1;
  66. b=p2;
  67. }
  68.  
  69. void PAIR::swap()
  70. {
  71. int c;
  72. c=a;
  73. a=b;
  74. b=c;
  75. }
  76.  
  77. int PAIR::diff()
  78. {
  79. return b - a;
  80. }
  81.  
  82. int PAIR::big()
  83. {
  84. if (a > b)
  85. {
  86. return a;
  87. }
  88. else
  89. {
  90. return b;
  91. }
  92.  
  93. int PAIR::area()
  94. {
  95. int z;
  96. z=(a*b);
  97.  
  98. {
  99. return z;
  100. }
  101. }
  102.  
  103. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,629
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Last CLASS method needs help... PAIR::area()

 
1
  #2
Sep 28th, 2006
Originally Posted by ToySoldier View Post
.

class PAIR
 
{private:
 int a;
 int b;
 
public:
 
 void print();
 PAIR();
 PAIR(int);
 PAIR(int,int);
 ~PAIR();

 void swap();
 int diff();
 int big();
 int area();
};

int main()
{
PAIR c, d(2), e(12,13);

int ans;
c.print();
d.print();
e.print();


d.swap();
d.print();
e.swap();
e.print();

ans = c.diff();
cout << "\nThe answer to c.diff() is  " << ans << endl;

int big = e.big () ;
cout << "\nThe larger number of e.big() is  " << big << endl << endl;

return 0;
}

PAIR::PAIR() 
{
a = 2;
b = 3;
}

void PAIR::print()
{cout << a << " " << b << endl;}

PAIR:: ~PAIR()
{
  cout << "Display Destructor Message" << endl;
}

PAIR::PAIR(int p1)
{a=p1;
b=p1;}

PAIR::PAIR(int p1,int p2)
{
a=p1;
b=p2;
}

void PAIR::swap()
{
 int c;
 c=a;
 a=b;
 b=c;
}

int PAIR::diff()
{
    return b - a;
}

int PAIR::big()
{
    if (a > b)
    {
        return a;
    }
    else 
    {
        return b;
    }
} // this was missing

int PAIR::area()
    { 
                int z;
    z=(a*b);
        
    {
    return z;
    }
}
    
// } 
// this is extra brace
The things marked in red by me are the culprits. WHy dont u format the code properly so that typographic errors will be minimised. Do you write your code in Notepad. If so grab your self a syntax highlighter code editor which makes automatically proper indentations like Code::BLocks or Dev Bloodshed.

The links for the above IDE can be found at teh top of this forum in the thread named "Starting C".

Hope it helped, bye.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 20
Reputation: ToySoldier is an unknown quantity at this point 
Solved Threads: 0
ToySoldier's Avatar
ToySoldier ToySoldier is offline Offline
Newbie Poster

Re: Last CLASS method needs help... PAIR::area()

 
0
  #3
Sep 28th, 2006
Thanks... cleaned it up and turned it in.

Gonna take my time with our next program.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
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