程序12.6:独立实践2.cpp
来自「学习C++的一些范例」· C++ 代码 · 共 63 行
CPP
63 行
/* 程序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 + =
减小字号Ctrl + -
显示快捷键?