我是标题,今天是2018/11/19

@TOC@11/19 c++ primer plus10.7章 10.10, 10.11, 10.12

先来10.10的
#ifndef STACK_H_

#define STACK_H_
typedef unsigned long Item;
class Stack
{private:
enum { MAX = 10 };
Item items[MAX];
int top;
public:Stack();
bool isempty()const;
bool isfull()const;
bool push(const Item&item);
bool pop(Item&item);
};
#endif

然后10.11
// stdafx.cpp : 只包括标准包含文件的源文件
// s a f e p r o j e c t n a m e safeprojectname safeprojectname.pch 将作为预编译标头
// stdafx.obj 将包含预编译类型信息
#include “stdafx.h”
#include “stack.h”
Stack::Stack()
{
top = 0;
}
bool Stack::isempty() const
{ return top0;
}
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;
}
;

// TODO: 在 STDAFX.H 中引用任何所需的附加头文件,
//而不是在此文件中引用

最后10.12
// 11月19.cpp: 定义控制台应用程序的入口点。
//

#include “stdafx.h”
#include “stack.h”
#include “ctype.h”
#include “iostream”
using namespace std;
int main()
{
using namespace std;
Stack st;
char ch;
unsigned long po;
cout << “please enter Ato add a purchase order,\n”
<< “P to process a po,or 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’:cout << “Enter a PO number to add:”;
cin >> po;
if (st.isfull())
cout << “stack already full\n”;
else
st.push(po);
break;
case’p’:
case’P’:if (st.isempty())
cout << “stack aready empty\n”;
else {
st.pop(po);
cout << "PO " << po << “popped\n”;
}
break;
}
cout << "please enter A to add a purchase order ,\n "
<< “P to process a po ,or Q to quit.\n”;
}
cout << “Bye \n”;
return 0;
}
好啦,今天的节目就到这里了,相信大家都能看懂

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值