Ai
1 Star 2 Fork 0

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

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Widget.cpp 1.61 KB
一键复制 编辑 原始数据 按行查看 历史
/* 点击一个‘猫叫’按钮,弹出‘喵’的提示框 */
#pragma execution_character_set("utf-8")
#include "Widget.h"
#include "ui_widget.h"
#include <QMessageBox>
#include "Cat.h"
#include "Dog.h"
#include "Cattle.h"
#include "Sheep.h"
#include "MachineCat.h"
#include "StoneMonkey.h"
#include "IChange.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
setWindowTitle("动物运动会");
}
void Widget::on_catBtn_clicked()
{
Cat cat("小咪");
cat.setShoutNum(5);
QMessageBox::information(this, " ", cat.Shout());
}
void Widget::on_dogBtn_clicked()
{
Dog dog("旺财");
dog.setShoutNum(5);
QMessageBox::information(this, " ", dog.Shout());
}
void Widget::on_animalRegistBtn_clicked()
{
animalList.append(new Cat("小花"));
animalList.append(new Dog("阿毛"));
animalList.append(new Cattle("小黑"));
animalList.append(new Sheep("娇娇"));
animalList.append(new Cat("咪咪"));
animalList.removeAt(1);
animalList.removeAt(1);
}
void Widget::on_shoutCompareBtn_clicked()
{
for (int i = 0; i < animalList.count(); i++) {
QMessageBox::information(this, " ", animalList[i]->Shout());
}
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_changeBtn_clicked()
{
MachineCat mcat("小叮当");
StoneMonkey wukong("孙悟空");
QList<IChange*> array;
array.append(&mcat);
array.append(&wukong);
QMessageBox::information(this, " ", array[0]->ChangeThing("各种各样的东西!"));
QMessageBox::information(this, " ", array[1]->ChangeThing("各种各样的东西!"));
}
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

搜索帮助