C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 19th, 2006, 02:16 AM
2cool 2cool is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 4 2cool User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 41 sec
Reputation Power: 0
Angry Simple c++ class help

need help, this is my 2nd prog. I'm trying to create a class and use it to find the area and length of boundary. I got no errors but 3 warnings and the calculation came out wrong...please help

#include <cstdlib>
#include <iostream>

using namespace std;

//==================class begins=========
class plot {
private:
int length;
int widht;

public:
int area(int, int);
int boundary(int, int);

};

//======================ends class=======

//==========================plot constructor initiate===================
plot::area(int x, int y)
{return x*y;}

plot::boundary(int x, int y)
{return 2*(x+y);}

//=========plot constructor end============
//========main=================
int main()
{
plot z;
int x=7;
int y=9;
cout<<"Area is: "<<z.area<<endl;
cout<<"Length of boundary is: "<<z.boundary<<endl;
cout<<"\n";
return 0;
}

Reply With Quote
  #2  
Old January 19th, 2006, 10:28 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Click here for more information. Click here for more information
 
Join Date: Sep 2005
Posts: 735 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 3 Days 12 h 16 m 2 sec
Reputation Power: 4
Post

Changing this:
cpp Code:
Original - cpp Code
  1. plot::area(int x, int y)
  2.   {return x*y;} 
  3. plot::boundary(int x, int y)
  4.   {return 2*(x+y);}

into:
cpp Code:
Original - cpp Code
  1.  
  2. int plot::area(int x, int y)
  3.   {return x*y;} 
  4. int plot::boundary(int x, int y)
  5.   {return 2*(x+y);}

and this:
cpp Code:
Original - cpp Code
  1. cout<<"Area is: "<<z.area<<endl; cout<<"Length of boundary is: "<<z.boundary<<endl;

into:
cpp Code:
Original - cpp Code
  1. cout<<"Area is: "<<z.area(x,y)<<endl; cout<<"Length of boundary is: "<<z.boundary(x,y)<<endl;


worked for me.

Reply With Quote
  #3  
Old January 19th, 2006, 12:54 PM
2cool 2cool is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 4 2cool User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 41 sec
Reputation Power: 0
Quote:
Originally Posted by Icon
Changing this:
cpp Code:
Original - cpp Code
  1. plot::area(int x, int y)
  2.   {return x*y;} 
  3. plot::boundary(int x, int y)
  4.   {return 2*(x+y);}

into:
cpp Code:
Original - cpp Code
  1.  
  2. int plot::area(int x, int y)
  3.   {return x*y;} 
  4. int plot::boundary(int x, int y)
  5.   {return 2*(x+y);}

and this:
cpp Code:
Original - cpp Code
  1. cout<<"Area is: "<<z.area<<endl; cout<<"Length of boundary is: "<<z.boundary<<endl;

into:
cpp Code:
Original - cpp Code
  1. cout<<"Area is: "<<z.area(x,y)<<endl; cout<<"Length of boundary is: "<<z.boundary(x,y)<<endl;


worked for me.




will I be good like you one day? How long have you been doing what you're doing? I just feel so overwhelming sometimes. Thank you very much.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Simple c++ class help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT