第三周作业

# 第一题 手写单例模式代码

# 第二题 组合模式的代码练习

## 题目

## 设计

## 代码实现

//----cat Button.h-------
/**
 * Project Untitled
 */

#ifndef _BUTTON_H
#define _BUTTON_H

#include "WindowComponent.h"

class Button:public WindowComponent {
 public:
     Button(string str):WindowComponent(str){}

	void display();
};

#endif				//_BUTTON_H
//----cat Button.cpp-------
/**
 * Project Untitled
 */


#include "Button.h"

/**
 * Button implementation
 */


/**
 * @return void
 */
void Button::display() {
    cout<<"print Button("<<content<<")"<<endl;
    return;
}
//----cat CheckBox.h-------
/**
 * Project Untitled
 */

#ifndef _CHECKBOX_H
#define _CHECKBOX_H

#include "WindowComponent.h"

class CheckBox:public WindowComponent {
 public:
     CheckBox(string str):WindowComponent(str){}

	void display();
};

#endif				//_CHECKBOX_H
//----cat CheckBox.cpp-------
/**
 * Project Untitled
 */


#include "CheckBox.h"

/**
 * CheckBox implementation
 */


/**
 * @return void
 */
void CheckBox::display() {
    cout<<"print CheckBox("<<content<<")"<<endl;
    return;
}
//----cat ComponentList.h-------
/**
 * Project Untitled
 */

#ifndef _COMPONENTLIST_H
#define _COMPONENTLIST_H

#include "WindowComponent.h"
#include <list>
#include <memory>
using std::list;
using std::unique_ptr;


class ComponentList:public WindowComponent {
 public:
     ComponentList(string str):WindowComponent(str){}
     virtual ~ComponentList(){ 
         
     }

	virtual void display() = 0;

/**
 * @param com
 */
	void AddComponent(unique_ptr<WindowComponent>&&  com);
 protected:
	 list < unique_ptr<WindowComponent> > vec;
};

#endif				//_COMPONENTLIST_H
//----cat ComponentList.cpp-------
/**
 * Project Untitled
 */


#include "ComponentList.h"

/**
 * ComponentList implementation
 */


/**
 * @return void
 */
void ComponentList::display() {
    for(const auto& i:vec)
        i->display();
    return;
}

/**
 * @param com
 */
void ComponentList::AddComponent(unique_ptr<WindowComponent>&& com) {
    vec.push_back(std::move(com));
}
//----cat Frame.h-------
/**
 * Project Untitled
 */

#ifndef _FRAME_H
#define _FRAME_H

#include "ComponentList.h"

class Frame:public ComponentList {
 public:
     Frame(string str):ComponentList(str){}

	void display();
};

#endif				//_FRAME_H
//----cat Frame.cpp-------
/**
 * Project Untitled
 */


#include "Frame.h"

/**
 * Frame implementation
 */


/**
 * @return void
 */
void Frame::display() {
    cout<<"print Frame("<<content<<")"<<endl;
    ComponentList::display();
    return;
}
//----cat LinkLable.h-------
/**
 * Project Untitled
 */

#ifndef _LINKLABLE_H
#define _LINKLABLE_H

#include "WindowComponent.h"

class LinkLable:public WindowComponent {
 public:
     LinkLable(string str):WindowComponent(str){}

	void display();
};

#endif				//_LINKLABLE_H
//----cat LinkLable.cpp-------
/**
 * Project Untitled
 */


#include "LinkLable.h"

/**
 * LinkLable implementation
 */


/**
 * @return void
 */
void LinkLable::display() {
    cout<<"print LinkLable("<<content<<")"<<endl;
    return;
}
//----cat PasswordBox.h-------
/**
 * Project Untitled
 */

#ifndef _PASSWORDBOX_H
#define _PASSWORDBOX_H

#include "WindowComponent.h"

class PasswordBox:public WindowComponent {
 public:
     PasswordBox(string str):WindowComponent(str){}

	void display();
};

#endif				//_PASSWORDBOX_H
//----cat PasswordBox.cpp-------
/**
 * Project Untitled
 */


#include "PasswordBox.h"

/**
 * PasswordBox implementation
 */


/**
 * @return void
 */
void PasswordBox::display() {
    cout<<"print PasswordBox("<<content<<")"<<endl;
    return;
}
//----cat Picture.h-------
/**
 * Project Untitled
 */

#ifndef _PICTURE_H
#define _PICTURE_H

#include "WindowComponent.h"

class Picture:public WindowComponent {
 public:
     Picture(string str):WindowComponent(str){}

	void display();
};

#endif				//_PICTURE_H
//----cat Picture.cpp-------
/**
 * Project Untitled
 */


#include "Picture.h"

/**
 * Picture implementation
 */


/**
 * @return void
 */
void Picture::display() {
    cout<<"print Picture("<<content<<")"<<endl;
    return;
}
//----cat SimpleLabel.h-------
/**
 * Project Untitled
 */

#ifndef _SIMPLELABEL_H
#define _SIMPLELABEL_H

#include "WindowComponent.h"

class SimpleLabel:public WindowComponent {
 public:
     SimpleLabel(string str):WindowComponent(str){}

	void display();
};

#endif				//_SIMPLELABEL_H
//----cat SimpleLabel.cpp-------
/**
 * Project Untitled
 */


#include "SimpleLabel.h"

/**
 * SimpleLabel implementation
 */


/**
 * @return void
 */
void SimpleLabel::display() {
    cout<<"print Label("<<content<<")"<<endl;
    return;
}
//----cat TextBox.h-------
/**
 * Project Untitled
 */

#ifndef _TEXTBOX_H
#define _TEXTBOX_H

#include "WindowComponent.h"

class TextBox:public WindowComponent {
 public:
     TextBox(string str):WindowComponent(str){}

	void display();
};

#endif				//_TEXTBOX_H
//----cat TextBox.cpp-------
/**
 * Project Untitled
 */

#include "TextBox.h"

/**
 * TextBox implementation
 */

/**
 * @return void
 */
void TextBox::display()
{
    cout<<"print TextBox("<<content<<")"<<endl;
	return;
}
//----cat WindowComponent.h-------
/**
 * Project Untitled
 */
#include <string>
#include <iostream>
using std::string;
using std::cout;
using std::endl;

#ifndef _WINDOWCOMPONENT_H
#define _WINDOWCOMPONENT_H

class WindowComponent {
 public:
     WindowComponent(string str):content(str) {}
     virtual ~WindowComponent(){}

	virtual void display() = 0;
 protected:
	string content;
};

#endif				//_WINDOWCOMPONENT_H
//----cat WindowComponent.cpp-------
/**
 * Project Untitled
 */


#include "WindowComponent.h"

/**
 * WindowComponent implementation
 */


/**
 * @return void
 */
void WindowComponent::display() {
    return;
}
//----cat WinForm.h-------
/**
 * Project Untitled
 */

#ifndef _WINFORM_H
#define _WINFORM_H

#include "ComponentList.h"

class WinForm:public ComponentList {
 public:
     WinForm(string str):ComponentList(str) {}

	void display();
};

#endif				//_WINFORM_H
//----cat WinForm.cpp-------
/**
 * Project Untitled
 */


#include "WinForm.h"

/**
 * WinForm implementation
 */


/**
 * @return void
 */
void WinForm::display() {
    cout<<"print WinForm("<<content<<")"<<endl;
    ComponentList::display();
    return;
}
//----cat main.cpp--------
#include <iostream>
#include <memory>
#include "Button.h"
#include "CheckBox.h"
#include "ComponentList.h"
#include "Frame.h"
#include "LinkLable.h"
#include "PasswordBox.h"
#include "Picture.h"
#include "SimpleLabel.h"
#include "TextBox.h"
#include "WindowComponent.h"
#include "WinForm.h"

#include<utility>

template<typename T, typename... Ts>
std::unique_ptr<T> make_unique(Ts&&... params)
{
	return std::unique_ptr<T>(new T(std::forward<Ts>(params)...));
}

int main()
{
    unique_ptr<ComponentList> root = make_unique<WinForm>("WINDOWS窗口");
    root->AddComponent(make_unique<Picture>("LOGO图片"));
    root->AddComponent(make_unique<Button>("登录"));
    root->AddComponent(make_unique<Button>("注册"));
    unique_ptr<ComponentList> container = make_unique<Frame>("FRAME1");
    container->AddComponent(make_unique<SimpleLabel>("用户名"));
    container->AddComponent(make_unique<TextBox>("文本框"));
    container->AddComponent(make_unique<SimpleLabel>("密码"));
    container->AddComponent(make_unique<PasswordBox>("密码框"));
    container->AddComponent(make_unique<CheckBox>("复选框"));
    container->AddComponent(make_unique<TextBox>("记住用户名"));
    container->AddComponent(make_unique<LinkLable>("忘记密码"));
    root->AddComponent(std::move(container));
    root->display();

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你好!改善深层神经网络的方法有很多,以下是一些常见的方法: 1. 使用更好的激活函数:传统的激活函数如Sigmoid、tanh等可能存在梯度消失或爆炸的问题。可以尝试使用ReLU、Leaky ReLU、ELU等激活函数,以减轻这些问题。 2. 使用批标准化(Batch Normalization):批标准化对网络的输入进行标准化,有助于加快网络的训练速度,并且可以缓解梯度问题,使得更深层的网络也能够训练得更好。 3. 使用残差连接(Residual Connections):残差连接可以帮助信息在网络中更好地流动,从而减轻梯度消失的问题。通过将某些层的输与输入相加,可以使得网络更易于训练。 4. 使用更好的优化算法:传统的梯度下降算法如随机梯度下降(SGD)可能存在训练速度慢、易陷入局部最优等问题。可以尝试使用更高级的优化算法如Adam、RMSprop等,以加快模型的收敛速度。 5. 添加正则化:过拟合是深层神经网络常见的问题之一。可以通过添加正则化项如L1正则化、L2正则化等来限制模型的复杂度,防止过拟合的发生。 6. 数据增强:通过对训练数据进行一些随机的变换,如平移、旋转、缩放等,可以增加模型的泛化能力,防止过拟合。 这些方法只是改善深层神经网络的一部分,具体的选择和调整需要根据具体问题和数据集来进行。希望对你有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值