⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 10_333_5.cpp

📁 我学习C++ Primer Plus过程中写下的课后作业的编程代码
💻 CPP
字号:
/*
5.考虑下面的结构声明:
stuct customer {
char	fullname[35];
double	payment;
};
编写一个程序,它从堆栈中添加和删除customer结构(堆栈用Stack类声明表示).
每次customer结构被删除时,其payment的值都被加入到总数中,并报告总数.注意:
应该可以直接使用Stack类而不作修改;只需修改typedef声明,使Item的类型为customer,
而不是unsigned long即可.
*/

#include <iostream>
#include <cctype>
#include "stack.h"

using namespace std;

int main()
{
	Stack	customer_stack;
	double	payment_total = 0.0;
	customer temp;
	
	cout<<"push 10 Items"<<endl;
	
	char choose;
	cout<<"按任意键添加客户名单,按Q退出添加!\n";
	while(cin>>choose && ( choose=toupper(choose) ) != 'Q')
	{
		cout<<"添加customer: "<<endl;
		cout<<"fullname: ";
		while(cin.get() != '\n')
			continue;
		cin.getline(temp.fullname,35);
		cout<<endl;
		
		cout<<"payment: ";
		cin>>temp.payment;
		cout<<endl;
		if( !customer_stack.isfull() )
		{
			customer_stack.push(temp);
		}
		else
			break;
		cout<<"按任意键继续添加,按Q退出添加!"<<endl;
	}
	
	for(int i = 0; i<10; i++)
	{
		if( !customer_stack.ismpty() )
		{
			customer_stack.pop(temp);
			payment_total +=temp.payment;
			cout<<temp.fullname<<"----"<<temp.payment<<endl;
			cout<<"总报酬: "<<payment_total<<endl;
		}
		else
			break;
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -