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

📄 shiti8_5_2.cpp

📁 为初学者提供的最佳的C++程序设计源程序库
💻 CPP
字号:
#include<iostream.h>
#include<stdio.h>
enum boolean {False,True};
class Base 
{
public:
	void GetName()
	{
		cout<<"Name:";
		cin>>name;
	}
	void Print(){cout<<"Name:"<<name<<endl;}
	virtual boolean IsGood()=0;
protected:
	char name[80];
};
class Book:public Base
{
public:
	void GetSold()
	{
		cout<<"The number of book is:";
		cin>>num;
	}
	boolean IsGood(){return(num>500)?True:False;}
private:
	int num;
};
class Journal:public Base
{
public:
	void GetSold()
	{
		cout<<"The number of Journal is:";
		cin>>num;
	}
	boolean IsGood(){return(num>2500)?True:False;}
private:
	int num;
};
void main()
{
	Base *p[50];
	Book *pBook;
	Journal *pJour;
	char ch;
	int count=0;
	do
	{
		cout<<"Input Book(b) or Journal(j):";
		cin>>ch;
		if(ch=='b')
		{
			pBook=new Book;
			pBook->GetName();
			pBook->GetSold();
			p[count++]=pBook;
		}
		else if(ch=='j')
		{
			pJour=new Journal;
				pBook->GetName();
			pBook->GetSold();
			p[count++]=pBook;
		}
		else
			cout<<"Input error."<<endl;
		cout<<"Input another?(y/n)";
		cin>>ch;
	}while(ch=='y');
	for(int i=0;i<count;i++)
		if(p[i]->IsGood()==True)
		{
			p[i]->Print();
			cout<<"Good."<<endl;
		}
}

⌨️ 快捷键说明

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