第十章编程练习(1)
2016-02-01 22:44
330 查看
ff.h
#pragma once #ifndef ff_H_ #define ff_H_ #include <string> using namespace std; const int MAX = 6; class Sudio { string name; char number[MAX]; double money; public: Sudio(); ~Sudio(); void set(const string & str, const char * num, double mon); void need(double mon); }; #endif
function.cpp<pre class="cpp" name="code">#include <iostream> #include "ff.h" #include <cstdlib> #include <string> extern const int MAX; int main() { Sudio su; char ch[MAX] = "12345"; su.set("asd", ch, 3.2); cout << "Need\n"; su.need(2.1); system("pause"); return 0; }
main.cpp
#include <iostream> #include "ff.h" extern const int MAX; using namespace std; Sudio::Sudio() { name = "Error"; number[MAX] = 0; money = 0; } void Sudio::set(const string & str, const char * num, double mon) { name = str; int j = 1; for (int i = 0; i < MAX; i++) number[i] == num[i]; j++; if (j == MAX); if(mon >= 0) money += mon; else { cout << "Error!\n"; return; } cout << "The balance on your account is: $ " <<money<< endl; } void Sudio::need(double mon) { if (money >= mon) { money -= mon; cout << "The balance on your account is: $ " << money << endl; } else { cout << "Insufficient balance on the account you!" << endl; } } Sudio::~Sudio() { }
相关文章推荐
- 字符串的比较 java
- 构建一个基于 Spring 的 RESTful Web Service
- Java 异步通信 程序
- Spring jdbcTemplate
- 一个倒排索引(inverted index)的python实现
- python使用代理访问服务器
- Java 阻塞的概念
- ADT Bundle 理解开发环境 & Eclipse工具使用技巧
- Python 10.4 struct
- python学习笔记Day3
- FTP服务器架设(2)vsftpd 安装
- 《笨办法学Python》 第30课手记
- 从头认识Spring-1.13 注入properties与null
- Python装饰器
- QT 5 初学1 多窗口切分
- Your First Java Program
- m3u文件转pls文件(go语言实现)
- JAVA-事件处理
- QT5.5.0版本添加icon图标步骤
- QT5.5.0版本添加icon图标步骤