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

📄 zhang.cpp

📁 类的继承和派生,觉得很有用,放上来一起分享
💻 CPP
字号:
#include <string>
#include <iostream.h>
#include "stack.h"

void main()
{
  CStack <int>  stack1;       //定义int类型栈对象stack1
  int i,iData;
  
  cout<<"请输入5个整数:"<<endl;
  for(i=0;i<5;i++)
    {
	   cin>>iData;
	   stack1.Push(iData);
	}
  
  cout<<"栈中的数据为:"<<endl;
  while(stack1.Pop(iData))    //循环提取栈中各结点并输出
      cout<<iData<<"  ";

  CStack <Staff>  stack2;     //定义Staff类型栈对象stack2
  Staff staff;
  
  
  
  cout<<"\n   请输入5个员工的信息:"<<endl;
  for(i=0;i<5;i++)
    {
	   cout<<"  姓名: ";
	   cin>>staff.m_strName;
	   cout<<"  性别: ";
	   cin>>staff.m_strSex;
	   cout<<"  年龄: ";
	   cin>>staff.m_iAge;
	   cout<<"  工资: ";
	   cin>>staff.m_fSalary;
	   cout<<endl;
	   stack2.Push(staff);
	}

	cout<<"栈中的数据为:"<<endl;
	while(stack2.Pop(staff))    //循环提取栈中各结点并输出
	 {
	   cout<<"  姓名:  "<<staff.m_strName<<",";
	   cout<<"  年龄:  "<<staff.m_iAge<<",";
	   cout<<"  工资:  "<<staff.m_fSalary<<",";
	   cout<<"  性别:  "<<staff.m_strSex<<endl;
	 }
}

⌨️ 快捷键说明

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