C++primer plus第六版课后编程练习答案10.5
2015-11-30 16:00
465 查看
头文件 #ifndef STACK_H_ #define STACK_H_ #include<iostream> using namespace std; struct customer{ char fullname[35]; double payment; }; typedef customer Item; class Stack { Item item[10]; double payment; int top; public: Stack(){top=0;payment=0;} bool isEmpty() const; bool isFull() const; bool push(const Item &t); bool pop(); void showpayment(){cout<<"payment="<<payment<<endl;} }; #endif
<pre name="code" class="cpp">#include<iostream> #include "stack.h" using namespace std; bool Stack::isEmpty()const { if(0==top) return true; else return false; } bool Stack::isFull()const { return top==10; } bool Stack::push(const Item &t) { if(isFull()) { cout<<"Error,stack is full!"<<endl; return false; } else { item[top]=t; top++; return 1; } } bool Stack::pop() { if(isEmpty()) { cout<<"Error,stack is empty!"<<endl; return 0; } else { top--; payment+=item[top].payment; return 1; } }
#include<iostream> #include "stack.h" using namespace std; void main() { Stack sc; customer c[5]={ {"I",10}, {"II",20}, {"III",40}, {"IV",50}, {"V",60} }; sc.pop(); sc.showpayment(); for(int i=0;i<5;i++) sc.push(c[i]); for(;i<10;i++) sc.push(c[i]); sc.push(c[0]); sc.showpayment(); sc.pop(); sc.showpayment(); }
相关文章推荐
- 64位系统下gcc按照32位编译c程序
- C++primer plus第六版课后编程练习答案10.4
- C语言_冒泡排序
- c++字符串分词
- 循环链表Josephus问题(c,cpp)
- C++primer plus第六版课后编程练习答案10.3
- 《C++ Primer 5th》读书笔记6---再谈初始化
- C++primer plus第六版课后编程练习答案10.2
- C++primer plus第六版课后编程练习答案10.1
- 【C++】位图
- C语言复习题1.1
- C++类和对象的概念
- C++ 类中指向函数的指针 以及 类模板
- c++的float类型包含的最值问题....
- C语言实现printf的部分功能
- 【C语言提高07】【指针铁律】铁律1:指针是一种数据类型
- VS中配置通用的VC++目录和lib目录
- C++抓包 分析IP头部数据
- c 中无符号数相减依然是无符号数
- 《c++ primer》 14.5 下标操作符