C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Iron Speed
 
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:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old May 6th, 2008, 12:49 AM
rcmango rcmango is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 11 rcmango User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 54 m 51 sec
Reputation Power: 0
Please help with this merchant class.

Okay, i've built the class, anyone who can help me understand how to implement the actual functions. Also, if there is anything wrong with my class so far.

..and for the balance function, are the objects the actual variables that store the int of a merchant? or do i have to make those?

does every merchant have 1000?

thanks alot.


heres what I have to do:



Define a class ‘merchant’ for handling merchant-like objects. The class should have a public interface with the following members.

merchant — a parameterless constructor initializing to 1000 the number of items each merchant possesses.
sell — a two-parameter function transferring a specified number of items to a specified merchant. The function should not put any restriction on the order of its input values.
buy — a two-parameter function transferring a specified number of items from a specified merchant. The function should not put any restriction on the order of its input values.
balance — a parameterless function which writes out the number of items in the possession of its merchant.


Code:
class merchant
{
public: 
  merchant(); //merchant constructor
  
  ~merchant(); //merchant destructor
 
  int sell(int x, int y);
  int buy (int p, int q);
  void balance ();
};

merchant::merchant()
{
  //need to initialize to 1000???
}

merchant::~merchant()
{
  //destructor accepting no arguments.
}

int merchant::sell (int x, int y)
{
  ///should implement here, ..calls the sell member function which will sell a certain amount of what it has to the other merchant which is what?    
  ///// return something?
}

int merchant::buy (int p, int q)
{
  ///should implement here, could be similiar to the sell member function. 
  
      // return something?
}

void merchant::balance()
{
  // this should probably be an integer return type, but how??
}

int main(){ 
  merchant a, b, c; 
  a.sell(50,b); 
  a.sell(c,50); 
  c.buy(70,b); 
  a.balance(); 
  b.balance(); 
  c.balance(); 
  return 0; 
} 

Last edited by rcmango : May 6th, 2008 at 12:51 AM. Reason: added stuff.

Reply With Quote
  #2  
Old May 7th, 2008, 04:33 AM
MaHuJa MaHuJa is offline
Contributing User
Click here for more information.
 
Join Date: Dec 2007
Posts: 338 MaHuJa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 14 h 13 m 10 sec
Reputation Power: 1
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
I'll do a few changes, and highlight them.
Code:
class merchant
{
private:
  int stock;
public: 
  merchant(); //merchant constructor
  
  ~merchant(); //merchant destructor
 
  void sell(int x, merchant& y);
  void sell(merchant& y, int x) { sell(x,y); }
  // Same needs to happen with buy  
  int buy (int p, int q);

  void balance() { std::cout << stock;  }
};

merchant::merchant()
{
  //need to initialize to 1000???
  stock=1000;
}


The specification is for the public interface. What happens "further in", specifically in your functions and in the private section of the class, is totally up to you, so long as you get it working. That does mean you have to fill it out with something.

So far you've probably just been told to write this piece of code like this and that piece of code like that. Now you're being let loose to decide how you want to implement it.

Reply With Quote
  #3  
Old Yesterday, 12:42 AM
rcmango rcmango is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 11 rcmango User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 54 m 51 sec
Reputation Power: 0
hey thanks for this help muhaja,

well had a question about this part:
Quote:
void sell(int x, merchant& y);
void sell(merchant& y, int x) { sell(x,y); }
// Same needs to happen with buy


i see how your actually just creating the function right inside the class there right? with the brackets?

also, i see how the type for y is merchant& which is a reference. Can this only happen inside the class, just a little confused here about that part, i may need to read another class tut on that part.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Please help with this merchant class.


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway