神秘博客

C++ Primer Plus [第六版]第10章复习题答案

5

#ifndef BANK_H_
#define BANK_H_
#include <string>

class Bank
{
private:
  std::string name;
  std::string cardNumber;
  double money;
public:
  Bank();
  Bank(const std::string &str, const std::string &n, const double &m);
  void inBank(const double &m);
  void outBank(const double &m);
};


#endif

7

#include <iostream>
#include "bank0.h"

Bank::Bank()
{
  name = "no name";
  cardNumber = "0";
  money = 0.0;
}

Bank::Bank(const std::string &str, const std::string &n, const double &m)
{
  name = str;
  cardNumber = n;
  money = m;
}

void Bank::inBank(const double &m)
{
  money += m;
}

void Bank::outBank(const double &m)
{
  if (money < m)
    std::cout << "取现金额超限\n";
  else
    money -= m;
}

9

#ifndef STOCK20_H_
#define STOCK20_H_
#include <string>

class Stock
{
private:
  std::string company;
  int shares;
  double share_val;
  double total_val;
  void set_tot() { total_val = shares * share_val; }
public:
  Stock();        
  Stock(const std::string & co, long n = 0, double pr = 0.0);
  ~Stock();       
  void buy(long num, double price);
  void sell(long num, double price);
  void update(double price);
  void show()const;
  const Stock & topval(const Stock & s) const;
  const std::string &co_name() const { return company; }
  int numshares() const { return shares; }
  double shareval() const { return share_val; }
  double totalval() const { return total_val; }
};

#endif

 

版权说明:
点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注

觉得文章有用就请我吃包辣条吧

微信扫一扫打赏