数据结构、算法与应用 (C++描述) 第二版 1.16

货币类设计与实现
按照惯例,分了三个部分(头文件,头文件实现,main)来写。
只是按照他的要求粗略的写了一下,没有优化。
            **仅供有需要的人以参考,如有错误请纠正我**

头文件:currency.h

#ifndef CURRENCY_H_
#define CURRENCY_H_

#include<iostream>
#include<exception>
enum signType { plu, minu };

class currency
{
private:
    signType sign;
    long amount;
public:
    currency(signType theSign = plu, unsigned long theDollars = 0, unsigned int theCents = 0);
    ~currency() { }
    void setValue(signType theSign, unsigned long Dollars, unsigned int Cents);
    void setValue(double theAmount);
    signType getSign() const;
    unsigned long getDollars() const;
    unsigned int getCents() const;
    currency operator+(const currency & x) const;
    friend std::ostream & operator<<(std::ostream & out, const currency &x);
    void input();
    void subtract(double x);
    currency & percent(double x);
    currency & multiply(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值