Ai
1 Star 2 Fork 0

Apphao/大话设计模式C++版

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.cpp 2.03 KB
一键复制 编辑 原始数据 按行查看 历史
#include <iostream>
using namespace std;
class TestPaper {
public:
virtual string Answer1() = 0;
virtual string Answer2() = 0;
virtual string Answer3() = 0;
virtual void TestQuestion1() {
cout << "杨过得到,后来给郭靖,炼成倚大剑、屠龙刀的玄铁可能是():" << endl;
cout << "a.球磨铸铁 b.马口铁 c.高速合金钢 d.碳素纤维" << endl;
cout << "答案: " << Answer1() << endl;
}
virtual void TestQuestion2() {
cout << "杨过、程英、陆无双铲除了情花,造成():" << endl;
cout << "a.使这种植物不再害人 b.使一种珍稀物种灭绝 c.破坏了那个生物圈的生态平衡 d.造成该地区沙漠化" << endl;
cout << "答案: " << Answer2() << endl;
}
virtual void TestQuestion3() {
cout << "蓝凤凰致使华山师徒、桃吞六仙呕吐不止,如果你是大夫,会给他们开什么药():" << endl;
cout << "a.阿司匹林 b.牛黄解毒片 c.氟哌酸 d.让他们喝大量的生牛奶 e.以上全不对" << endl;
cout << "答案: " << Answer3() << endl;
}
};
//学生甲抄的试卷
class TestPaperA : public TestPaper {
public:
virtual string Answer1() {
return "b";
}
virtual string Answer2() {
return "a";
}
virtual string Answer3() {
return "c";
}
};
//学生乙抄的试卷
class TestPaperB : public TestPaper {
public:
virtual string Answer1() {
return "d";
}
virtual string Answer2() {
return "b";
}
virtual string Answer3() {
return "a";
}
};
int main(int argc, char *argv[])
{
cout << "学生甲抄的试卷: " << endl;
shared_ptr<TestPaper> studentA(new TestPaperA());
studentA->TestQuestion1();
studentA->TestQuestion2();
studentA->TestQuestion3();
cout << "学生乙抄的试卷: " << endl;
shared_ptr<TestPaper> studentB(new TestPaperB());
studentB->TestQuestion1();
studentB->TestQuestion2();
studentB->TestQuestion3();
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/apphao/dahua-design-mode---version-cpp.git
git@gitee.com:apphao/dahua-design-mode---version-cpp.git
apphao
dahua-design-mode---version-cpp
大话设计模式C++版
master

搜索帮助