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

📄 程序12.6:独立实践2.cpp

📁 学习C++的一些范例
💻 CPP
字号:
/* 程序12.6:独立实践2.cpp:*/
#include<iostream>		//包含头文件
#include<string>		//包含头文件
using namespace std;	//使用名字空间std
class Furniture
{
protected:
	int numberOfLegs;
	int height;
	int width;
	int length;
public:
	virtual void display()=0;
};
class Chair:public Furniture
{
public:
	void display()
	{
		cout<< "显示Chair"<<endl;
	}
};
class Table:public Furniture
{
public :
	void display()
	{
		cout<< "显示Table"<<endl;
	}
};
int main()
{
	Furniture *furniture;
	char choice;
reEnter:
	cout<<"C: for chair"<<endl;
	cout<<"T: for table"<<endl;
	cout<<"Q: to quit"<<endl;
	cout<<"please Enter C,T or Q :";
	cin>>choice;
	while(choice!='q'&&choice!='Q')
	{
		switch(choice)
		{
		case 'c':
		case 'C':
			furniture=new Chair;
			break;
		case 't':
		case 'T':			
			furniture=new Table;
			break; 
		default:
			cout<<"Invalid option. Enter C,T or Q"<<endl;
			goto reEnter;
		}
	furniture->display();
	break;
	}
	return 0;
}

⌨️ 快捷键说明

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