All pastes #928658 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-03-05 05:44 UTC
rendered paste body
////////Transaction.h
#include <string>
using namespace std;

class transaction
{
 private:
  string company;
  char buyorsell;
  int shares;
  double price;

 public:
  //Getters                                                                                                                                                          
  string getCompany(){return company;}
  char getBuyorsell(){return buyorsell;}
  int getShares(){return shares;}
  double getPrice(){return price;}

  //Setters                                                                                                                                                          
  void setCompany(int in_company){company = in_company;}
  bool setBuyorsell();
  bool setShares();
  bool setPrice();

  //Other functions                                                                                                                                                  
  void printTransaction();
  void getTransaction(string in_company, char in_buyorsell, int in_shares, double in_price);
};

///////////
///////////Transaction.cxx
#include "transaction.h"
#include <string>
using namespace std;

class transaction
{
public:

  //Setters                                                                                                                                                          
  bool transaction::setBuyorsell(char in_buyorsell)
  {
    if(in_buyorsell == 'b')
      {
        buyorsell = 'b';
        return true;
      }
    elseif(buyorsell == 's')
      {
        buyorsell = 's';
        return true;
      }
    return false;
  }

  bool transaction::setShares(int in_shares)
  {
    if(in_shares > 0 )
      {
        shares = in_shares;
        return true;
      }
    return false;
  }

  bool transaction::setPrice(double in_price)
  {
    if(in_price > 0)
      {
        price = in_price;
        return true;
      }
    return false;
  }

  //Other functions                                                                                                                                                  
  void printTransaction()
  {
    if(buyorsell == 'b')
      cout << "You bought ";
    elseif(buyorsell == 's')
      cout << "You sold ";
    cout << shares << " shares of " << company << " stock for $" << price << endl;
  }

  void getTransaction(string in_company, char in_buyorsell, int in_shares, double in_price)
  {
    setCompany(in_company);
    setBuyorsell(in_buyorsell);
    setShares(in_shares);
    setPrice(in_price);
  }
};