【10.5】c++ primer plus 课后编程答案
来源:互联网 发布:网络购物狂欢节 编辑:程序博客网 时间:2024/06/05 03:47
C++ PRIMER PLUS 课后答案
使用IDE为window7系统下的VS2010
/*user.h*/#ifndef USERSH_H_#define USERSH_H_#include <string> struct customer{ char fullname[85]; double payment;}; typedef customer item; class Stack{private: enum{max=5}; item items[max]; int top; public: Stack(); ~Stack(){}; bool isempty() const; bool isfull() const; bool push(const item & item); bool pop(item & item);}; #endif
/*userfucntion.cpp*/#include "usersh.h"#include <iostream>using std::cout;using std::cin;Stack::Stack(){ top=0;} bool Stack::isempty()const{ return top==0;} bool Stack::isfull() const{ return top==max;} bool Stack::push(const item & item){ if(top<max) { items[top++]=item; return true; } else return false;} bool Stack::pop(item & item){ if(top>0) { item=items[--top]; return true; } else return false;}
/*main*/#include <iostream>#include <Windows.h>#include "usersh.h"#include <string>#include <cctype>using std::cout;using std::cin;double total=0.0;int main(){ Stack st; char ch; item pre; cout<<"pleaseenter A to add a purchase order ,\n" <<"Pto process a Po, or Q to quit.\n"; while(cin>>ch&& toupper(ch)!='Q') { while(cin.get()!='\n') continue; if(!isalpha(ch)) { cout<<'\a'; continue; } switch(ch) { case'A': case'a': if(st.isfull()) { cout<<"stackalrady full\n"; break; } else cout<<"Enter pre information toadd:\n"; cout<<"the full name:" ; cin>>pre.fullname; cout<<"thepayment:"; cin>>pre.payment; st.push(pre); break; case'P': case'p':if (st.isempty()) cout<<"stackalrady empty \n"; else{ total+=pre.payment; st.pop(pre); cout<<"st#"<<pre.payment<<"POPPED\n"; } cout<<"\ntotal:"<<total<<'\n'; break; } cout<<"pleaseenter A to add a purchase order ,\n" <<"Pto process a Po, or Q to quit.\n"; } cout<<"BYE!"; system("pause"); return 0;}
阅读全文
0 0
- C++primer plus第六版课后编程题答案10.5
- C++primer plus第六版课后编程练习答案10.5
- 【10.5】c++ primer plus 课后编程答案
- C++PRIMER PLUS第六版课后编程答案 4.1-4.5
- C++PRIMER PLUS第六版课后编程答案 4.6-4.10
- C++PRIMER PLUS第六版课后编程答案 5.1-5.5
- C++PRIMER PLUS第六版课后编程答案 5.6-510
- C++primer plus第六版课后编程题答案 6.1
- C++primer plus第六版课后编程题答案 6.2
- C++primer plus第六版课后编程题答案 6.3
- C++primer plus第六版课后编程题答案 6.4
- C++primer plus第六版课后编程题答案 6.5
- C++primer plus第六版课后编程题答案 6.6
- C++primer plus第六版课后编程题答案 6.7
- C++primer plus第六版课后编程题答案 6.8
- C++primer plus第六版课后编程题答案 6.9
- C++primer plus第六版课后编程题答案7.1
- C++primer plus第六版课后编程题答案7.2
- CSS3属性border-radius参数详解
- 守护进程的实现
- HTML5基本伪类
- 第五章 变量
- JavaScript:获取系统时间
- 【10.5】c++ primer plus 课后编程答案
- java springmvc的普通接口和跨域接口
- 获得RGB图像三种颜色分量并进行条件筛选
- Rasterio 安装
- 【10.6】c++ primer plus 课后编程答案
- 关于private继承
- 《算法分析与设计》Week 16
- 省队集训DAY6
- TB