自助取款机系统(C#)

C#银行ATM程序--练习 个人更喜欢后面的 WinForm程序 (第二个),功能更多也更美观,使用起来也比控制台直观。这个WinForm程序写的很有成就感哈哈^~^(来自一个菜鸟的内心独白,大佬多多指点)—— WinForm的程序下载(解决方案)见文末 目录 控制台程序 WinForm应用程序(控制台的改进)—— 新添加 事件、委托、自定义异常等 功能描述 具体代码实现 控制台程序 具体代码:(可能有错,... 阅读详情

ATM(自动取款机)系统向用户提供一个方便、简单、及时、随时随地可以随心所欲存取款的、互联的、计算机化的网络系统 ,可以大大减少工作人员,节约人力资源的开销;同时,由于手续减少,减轻了业务员的工作负担,有效地提高了整体的工作效率和精确度,减少了用户办理业务的等待时间;用户可以随时随地存取款,并且操作简单;用户还可以自主选择在柜台办理业务或自己在自助取款机办理业务。

打开Visual Studio 2022,点击创建新项目。

 在创建新项目中,选择C#--Windows--控制台,选择控制台应用(.NET Framework) ,点击下一步。

配置新项目,在项目名称是Automatic-Teller-Machine,然后点击创建。

创建新项目以后:

1、帐号类

帐号类(Account)包含所有的账号信息,负责所有的账号操作。基本的帐号信息包括账号名(name)、账号密码(password)、账号余额(balance)。主要的账号操作包括登录(Login)、存款(Deposit)、取款(Withdraw)、查询余额(Get_Balance)、修改密码(ChangePassword)。

鼠标指针放在Automatic-Teller-Machine的字样,点击右键,选择“添加”,再选择“类”。

 在添加新项上,名称修改,输入是Account.cs,点击添加。

 添加新项之后:

 代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Automatic_Teller_Machine
{
    internal class Account
    {
        protected string name;
        protected string password;
        protected decimal balance;
        public decimal Banlance
        {
            get
            {
                return balance;
            }
        }
        public string Name
        {
            get 
            { 
                return name; 
            }
        }

        //构造函数
        public Account(string name, string password)
        {
            this.name = name;
            this.password = password;
            this.balance = 0;
        }
        public bool Deposit(decimal amount)
        {
            if(amount<=0)
            {
                return false;
            }
            balance += amount;
            return true;
        }
        //存款的三种重载方法
        public bool Deposit(double amount)
        {
            return Deposit((decimal)amount);
        }
        public bool Deposit(int amount)
        {
            return Deposit((decimal)amount);
        }
        public bool Deposit(decimal amount,out decimal balance)
        {
            bool succeed=Deposit(amount);
            balance = this.balance;
            return succeed;
        }
        public bool Withdraw(decimal amount)
        {
            if(amount>balance||amount<=0)
            { return false; 
            }
            balance -= amount;
            return true;
        }
        //取款的三种重载方法
        public bool Withdraw(double amount)
        {
            return Withdraw((decimal)amount);
        }
        public bool Withdraw(int amount)
        {
            return Withdraw((decimal)amount);
        }
        public bool Withdraw(decimal amount,out decimal balance)
        {
            bool succeed = Withdraw(amount);
            balance = this.balance;
            return succeed;
        }
        //修改密码
        public bool ChangePassword(string oldPassword, string newPassword)
        {
            if(oldPassword!=password)
            {
                return false;
            }
            password = newPassword;
            return true;
        }
        //进入系统
        public bool Login(string name,string password)
        {
            return (this.name == name && this.password == password);
        }

        

    }
}

2、银行类

银行类(Bank)的本质就是一组账号的组合,并负责管理账号。基本的银行信息包括银行名(name)、已经开户的账号数(usedAccountNum)、可以容纳的最大账户数(MaxAccountNum)、账号集(accounts)。主要的银行操作包括开户(OpenAccount)、登录账号(LoginAccount)。

鼠标指针放在Automatic-Teller-Machine的字样,点击右键,选择“添加”,再选择“类”。

在添加新项上,名称修改,输入是Bank.cs,点击添加。

添加新项之后:

  代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Automatic_Teller_Machine
{
    internal class Bank
    {
        protected string name;
        protected const int MaxAccountNum = 2048;
        protected int usedAccountNum;
        protected Account[] accounts;
        public string Name
        {
            get
            {
                return name;
            }
        }
        public Bank(string name)
        {
            this.name = name;
            this.usedAccountNum = 0;
            accounts= new Account[MaxAccountNum];
        }
        public bool LoginAccount(string name,string password, out Account account)
        {
            account= null;
            for(int i=0;i<usedAccountNum;++i)
            {
                if (accounts[i].Login(name,password))
                {
                    account = accounts[i];
                    return true;
                }
            }
            return false;
        }
        public bool OpenAccount(string name,string password,out Account account)
        {
            account = null;
            for(int i=0;i<usedAccountNum;++i)
            {
                if (accounts[i].Name==name)
                {
                    return false;
                }
            }
            account = new Account(name, password);
            accounts[usedAccountNum++] = account;
            return true;
        }

    }
}

3、ATM类

ATM类与银行类之间存在一对一的关联关系,ATM提供用户界面,并将用户的请求提交给银行,将银行的反馈提交给用户。主要的ATM操作包括启动(Start)、开户(OpenAccount)、登录账号(LoginAccount)、管理账号(ManageAccount)、一些显示不同信息的辅助操作(Print、Pause等)。

鼠标指针放在Automatic-Teller-Machine的字样,点击右键,选择“添加”,再选择“类”。

在添加新项上,名称修改,输入是ATM.cs,点击添加。

 添加新项之后:

 代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Automatic_Teller_Machine
{
    internal class ATM
    {
        private const string quitcode = "5";
        private Bank bank;
        public ATM(Bank bank)
        {
            this.bank = bank;
        }
        //开始页面
        public void Start()
        {
            while(true)
            {
                //主界面
                Console.WriteLine();
                Console.WriteLine("  ******************************");
                Console.WriteLine("  *-----------1.开户-----------*");
                Console.WriteLine("  *-----------2.登录-----------*");
                Console.WriteLine("  *-----------3.退出-----------*");
                Console.Write("请输入您的选择(回车结束):");
                string code=Console.ReadLine();
                if(code==quitcode)
                { 
                    return;
                }
                if(code=="1")
                {
                    OpenAccount();
                }
                else if(code=="2")
                {
                    LoginAccount();
                }
                else if(code=="3")
                {
                    Console.WriteLine("按一下任意键直接退出...");
                    Console.ReadKey();
                    return;
                }
            }
        }

        //账号登录方法
        private void LoginAccount()
        {
            Console.Clear();
            Console.WriteLine("  *      您已进入登录界面             *");
            Console.WriteLine("  =====================================");
            Console.WriteLine("  *   请输入您的账号的用户名和密码    *");
            Console.WriteLine("  =====================================");
            string name = Input("用户名(回车结束):");
            string password = Input("密  码(回车结束):");
            //登录账号
            Account account;
            if(!bank.LoginAccount(name,password, out account))
            {
                Console.WriteLine("---登录错误,请检查用户名和密码是否正确。按Enter键继续---");
                Console.Read();
            }
            else
            {
                ManageAccount(ref account);
            }

        }
        //开户方法
        private void OpenAccount()
        {
            Console.WriteLine("  =====================================");
            Console.WriteLine("  *   请输入您的帐号的用户名和密码    *");
            Console.WriteLine("  =====================================");
            string name = Input("用户名(回车结束):");
            string password = Input("密  码(回车结束):");
            //登录账号
            Account account;
            if (!bank.OpenAccount(name, password, out account))
            {
                Console.WriteLine("  *开户错误,用户名和密码已经存在。按Enter键继续---*");
                Console.Read();
            }
            else
            {
                Print("开户",0,account);
                ManageAccount(ref account);
            }

        }

        //账号管理方法
        private void ManageAccount(ref Account account)
        {
            Console.Clear();
            Console.WriteLine("  ******************************");
            Console.WriteLine("  *-----------1.存款------------");
            Console.WriteLine("  *-----------2.取款------------");
            Console.WriteLine("  *-----------3.查询余额--------");
            Console.WriteLine("  *-----------4.修改密码--------");
            Console.WriteLine("  *-----------5.回到主页--------");
            Console.WriteLine("  ******************************");
            Console.Write("您的选择是(回车结束):");
            while(true)
            {
                //管理账号界面
                Console.WriteLine("");
                string code = Console.ReadLine();
                //string s:
                decimal amount;
                bool succeed;
                switch(code)
                {
                    case "1":
                        amount = InputNumber("\n 请输入存款数目");
                        succeed=account.Deposit(amount);
                        if(succeed)
                        {
                            Print("存入", amount, account);
                        }
                        else
                        {
                            Console.WriteLine("存款失败!");
                        }
                        Pause();
                        break;
                    case "2":
                        amount = InputNumber("\n 请输入取款数目:");
                        succeed = account.Withdraw(amount);
                        if(succeed)
                        {
                            Print("取出", amount, account);
                        }
                        else
                        {
                            Console.WriteLine("取款失败!");
                        }
                        Pause();
                        break;
                    case "3":
                        break;
                    case "4":
                        string oldPassword = Input("当前密码(回车结束):");
                        string newPassword = Input("新密码(回车结束):");
                        succeed=account.ChangePassword(oldPassword, newPassword);
                        if(succeed)
                        {
                            Console.WriteLine("密码修改成功!");
                        }
                        else
                        {
                            Console.WriteLine("密码修改失败!");
                        }
                        Pause();
                        break;
                    case "5":
                        Console.Clear();
                        break;
                    default:
                        break;
                }                    
            }
        }
        //输出信息

        private string Input(string prompt)
        {
            Console.Write(prompt);
            string str=Console.ReadLine();
            while(str=="")
            {
                Console.Write("不能为空, {0}",prompt);
                str= Console.ReadLine();
            }
            return str;
        }
        private decimal InputNumber(string prompt)
        {
            Console.WriteLine(prompt);
            string s=Console.ReadLine();
            decimal amount = Decimal.Parse(s);
            return amount;
        }

        //打印辅助信息
        private void Pause()
        {
            Console.WriteLine("按Enter继续...");
            Console.Read();
        }

        //打印信息
        private void Print(string operation,decimal amount,Account account)
        {
            Console.WriteLine("  =====================================");
            Console.WriteLine("  *姓名:"+account.Name);
            Console.WriteLine("  *"+operation+":"+amount);
            Console.WriteLine("  *余额:" + account.Banlance);
            Console.WriteLine("              " + operation + "成功");
            Console.WriteLine("  =====================================");
        }
        private void Print(Account account)
        {
            Console.WriteLine("  =====================================");
            Console.WriteLine("  *姓名:{0}" , account.Name);
            Console.WriteLine("  *余额:{0}", account.Banlance);
            Console.WriteLine("  =====================================");
        }
    }
}

4、启动程序类

启动程序类(Program)的唯一功能就是创建银行类和ATM类的实例,并将它们关联起来,然后启动ATM(执行ATM对象的Start方法)。因此,该类仅仅是包含程序 的入口点Main方法。

鼠标指针放在Automatic-Teller-Machine的字样,点击右键,选择“添加”,再选择“类”。

在添加新项上,名称修改,输入是Account.cs,点击添加。

 添加新项之后:

 代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Automatic_Teller_Machine
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("  ******************************");
            Console.WriteLine("  *      欢迎登录中国银行      *");
            Console.WriteLine("  ******************************");
            //实例化Bank类
            Bank bank = new Bank("ATM自助取款机");
            //实例化ATM类
            ATM atm=new ATM(bank);
            atm.Start();
        }
    }
}

【C++实验】模拟实现一个ATM自助存取款机 一、实验平台 Visual C++ 6.0 二、问题分析 2.1 需求分析 本次实验有如下四条需求: (1)要求程序界面友好且能对操作是否成功进行判断; (2)要求输入密码时以星号(***)显示; (3)要求存取款只能以整百金额进行,并对出现的各种情况进行判断; (4)要求转账时只能对于已有的五个账号(1234567891234567891……)操作。 根据以上四点需求,至少应有菜单(Menu)、... 阅读详情

相关推荐

分享一个模拟ATM取款机的DEMO

这是一个模拟ATM取款机的DEMO(C#版)的,还算比较完整。我现在就给大家分享下把。下面是使用说明 本系统采用的是sql2005的数据库 平台是.net3.5   注: 帐号密码都默认为:123456 密码连续输错三次将被自动锁号 密码输入时间不得多余30秒,否则自动退卡 每次取钱不得多余2000元 每天取钱不得多余20000元 每次运行系统,默认为20万的金额

winerdaxian的专栏 6790

C#之银行ATM实例-Part1

一、题目要求: 在下面银行ATM示例的基础上,利用所学的面向对象的思想及语法,进行改进。要求如下: 1. 使用面向对象的思想,模拟现实世界中的银行、账号、ATM等对象,其中类中有字段、方法; 2. 在程序中适当的地方,使用属性、索引,注意使用修饰符; 3. 使用继承,继承账号(Account类)得到一个子类(如信用账号),增加字段(如信用额度)、属性、方法,覆盖(override)一些方法(如WithdrawMoney)。 4. 根据程序的需要(可选做),使用C#的其他语法成分,诸如:接口、结构、

Ashely的博客 3592

C#编程实践:模拟ATM取款机系统

在C#中,类是一种定义对象结构和行为的蓝图。它定义了对象将拥有的字段、属性和方法。类是创建对象的模板。一个类的定义以关键字class开始,后面跟着类的名称。// 字段(Fields)// 属性(Properties)// 方法(Methods)在上面的代码中,Person类有两个字段name和age,它们被声明为private,这意味着它们只能在类的内部访问。同时,有两个对应的公共属性Name和Age,允许外部代码获取和设置这些值。Greet。

weixin_35973118的博客 864

c#ATM之功能篇(存钱,取钱,转账,交易明细)完结篇

c#ATM之功能篇(存钱,取钱,转账,交易明细)完结篇带详细注释 一个七个功能,不难,代码还有优化空间,之后再发一篇ATM之优化篇 首先先添加一条命名空间 using System.Data.SqlClient; public Form3() { InitializeComponent(); } pub...

Izrj的博客 7298

C#语言构建的ATM系统模拟与实战

在面向对象编程中,类是定义对象属性和行为的蓝图。在C#中,一个类由关键字class定义,并包含数据成员(属性)和成员函数(方法)。对象是类的实例,通过使用new关键字来创建。例如:set;set;// 实例化类在上述代码中,我们定义了一个Person类,它有两个属性:Name和Age,以及一个方法Greet。创建类的实例person是通过实现的。接口定义了一组方法规范,但不提供这些方法的实现。类可以实现多个接口,实现接口意味着要提供接口方法的具体实现。

weixin_35756892的博客 921

C#编程实现基础ATM系统

本文还有配套的精品资源,点击获取 简介:本项目通过C#编程语言实现了一个基本的自动取款机(ATM)系统,涵盖了银行账户管理、用户身份验证、交易处理、安全性、并发控制和错误处理等方面。设计模式的应用和图形用户界面(GUI)的创建也是项目的一部分。项目不仅涉及编程技巧,还包括对银行业务流程的深入理解,以及用户交互设计的实践。 1. C#语言实现ATM系统 在当今数字...

weixin_31776191的博客 915

2025毕设springboot ATM自动取款机系统论文+源码

通过这些功能的集成与优化,旨在构建一个既满足当前用户需求,又具备良好扩展性的ATM系统框架,为后续的升级与维护奠定坚实基础。同时,随着移动支付和互联网金融的兴起,ATM系统也面临着转型升级的挑战,研究如何在保障安全的前提下,融入更多创新功能,如无卡取款、人脸识别等,对于适应市场变化、满足用户新需求具有深远意义。[11]刘小玲,李慧云,殷珊珊,贾少华,许杰辉,郝颖.一种基于软件测试任务的信息化管理系统的原型设计[J].现代信息科技,2024,8(12):91-95。

嘉佑学姐--毕设 1003

模拟ATM取款机源码(C#版)完整版

是对我另个一个上传项目的补充,这个包括完整的数据库,C#代码(有打包处理),系统说明文档等

atm取款机 oracle实战训练_分享一个模拟ATM取款机的DEMO

这是一个模拟ATM取款机的DEMO(C#版)的,还算比较完整。我现在就给大家分享下把。下面是使用说明本系统采用的是sql2005的数据库平台是.net3.5注:帐号密码都默认为:123456密码连续输错三次将被自动锁号密码输入时间不得多余30秒,否则自动退卡每次取钱不得多余2000元每天取钱不得多余20000元每次运行系统,默认为20万的金额提供了两个版本1.JOJOATM1.3(打包了.net3...

weixin_39615257的博客 256

ATM在线自助系统(C#窗体应用程序)

使用C# windows窗体应用程序。包括了开户、登陆、系统管理等功能。

C#课程设计——自助取款机软件设计

C#课程设计——自助取款机软件设计,20个字真的很难!

基于asp.net066自助银行模拟系统

自助银行是 Automatic Teller Machine 的缩写,意为自动柜员机。它是一种高度精密的机电一体化设备,利用磁卡或智能IC卡储存用户信息并通过加密键盘(EPP)输入密码然后通过银行内部网络验证并进行各种交易的金融自助设备。自助银行的功能主要包括:现金取款、现金存款、现金存取款、余额查询、本行或异行转账、修改密码等基本功能;有些多功能自助银行还提供诸如存折打印、对账单打印、支票存款、信封存款、缴费、充值等一系列便捷服务。由此看来,自助银行的管理是十分重要的。而人们在使用自助银行前很重要的一个环

m0_50936939的博客 349

从传统扫描到SSN:Tessent数据包技术如何减少90%测试时间

本文深入探讨了Tessent流式扫描网络(SSN)如何通过其核心的数据包技术,彻底改变芯片测试范式。该技术将测试数据封装成标准化数据包,在共享总线上进行智能路由与分发,实现了动态带宽分配与核心独立测试,从而将复杂SoC(如AI芯片)的总体测试时间大幅削减90%,并显著提升测试灵活性与可扩展性。

meat5的博客 490

自动取款机

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace 自动取款机 { class Program { static void Main(string[] args)

Blankj 1599

Android dex, odex, oat, vdex, art文件介绍

下图可以简化将Java源转换为OAT的过程: .dex Dalvik虚拟机字节码文件 .vdex 其中包含APK的未压缩DEX代码,以及一些旨在加快验证速度的元数据 .odex .oat // JIT,Just-in-time,即时编译,边运行边编译; // AOT,Ahead Of Time,提前编译,指运行前编译。 其中包含APK中已经过AOT编译的方法代码。 原始DEX文件(例如classes.dex)被转换为另一个包含本机代码的文件。这个新文件通常具有.odex。.oat扩展名,并由ELF格式

he980725866的博客 3620

BUCK降压电路设计实战:从理论到PCB的完整指南

本文详细介绍了BUCK降压电路的设计实战,从基础原理到PCB布局的完整指南。通过关键部件选型、PCB布局黄金法则和调试技巧,帮助工程师高效设计稳定可靠的开关电源。特别针对电感、MOSFET和电容选型提供实用公式和避坑指南,并分享高温环境下的工程经验与测试方法。

weixin_33744141的博客 452

ATM自动取款机终端系统(基于visual studio 2015与Sql server 2014平台的C#项目)

一、项目要求: 创建一个ATM自动取款机终端系统二、项目需求: 1.数据信息存储在sql server数据库之中 2.通过终端系统进行数据的操作三、项目实现: 1.sql server数据库与表的创建 通过sql server 2014创建数据库ATM,在数据库中分别创建个人信息表、存储金额表、取款金额表、交易信息表。数据库建立如下图所示:个人信息

原勿的博客 3079

UWB芯片DW3000之PDOA测向实现源码

本文详细介绍如何基于UWB芯片DW3000之PDOA测向的源码实现。

DT程序员的博客 2615

C#中{get;set;}

http://blog.sina.com.cn/s/blog_82526aa60100txtx.html 在程序中经常碰到get、set,不甚明白,在网上查询时也说的迷迷糊糊,所以整理下,以学的明白透彻点。 有两个类person: public class person { public string name; } public class person { public ...

qq_40091720的博客 5万+

Open Dynamics Engine(ODE)物理引擎教程(1)--下载与安装准备

引言 ODE是一个免费的工业级库,用于模拟关节式刚体动力学,例如地面车辆、腿部生物和虚拟现实环境中的移动对象。它具有快速、灵活、健壮和独立于平台的特点,具有先进的关节、摩擦接触和内置的碰撞检测功能。 项目主页:http://www.ode.org/ 线上手册:http://ode.org/wiki/index.php?title=Manual 本教程为博主亲自亲测过程的总结,转载请注明出处! ...

腿足机器人领域 2216

DISM进行系统修复,进度条卡在63.2%的解决方法

一时用不了软件,安装修复的时候也出现问题 DISM一直卡在63.2%,等了好久时间,直接强制退出寻找最终的解决方案

码农研究僧的博客 1万+

C#多线程开发8:线程同步之Mutex类

以下代码模拟“从自动取款机中取钱”的操作:当账户余额大于等于1000时,取出1000放入口袋。代码中使用两个线程同时执行取钱操作,若不进行同步处理,可能会存在两个线程同时进入取钱逻辑,导致最终取出2000的错误结果。所以代码中使用Mutex类同步线程访问取钱逻辑(临界资源)。 using System; using System.Threading; namespace MutexExample

三五月儿的专栏 4229

《电磁兼容设计》专栏说明

本专栏自2024年1月起开始更新,仅设此一个电磁兼容相关知识专栏,并将一直持续更新下去,无期限

linkking27的博客 791

【C#】get和set详解

原文链接:http://blog.sina.com.cn/s/blog_82526aa60100txtx.html   在程序中经常碰到get、set,不甚明白,在网上查询时也说的迷迷糊糊,所以整理下,以学的明白透彻点。   有两个类person: public class person { public string name; } public class person

习惯成自然 2万+

京东运维面试题及参考答案

cgroup(Control Group)是 Linux 内核提供的一种可以限制、控制与分离一个进程组群的资源(如 CPU、内存、磁盘 I/O 等)的机制。通过 cgroup,可以为不同的进程或进程组分配特定的资源配额,实现资源的隔离和管理。比如,在一个服务器上运行多个容器时,可以使用 cgroup 来限制每个容器对 CPU 和内存的使用,防止某个容器占用过多资源而影响其他容器的运行。cgroup 还可以对进程进行优先级设置,确保关键进程能够优先获得资源。

大模型大数据攻城狮的专栏 1236

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

关于C#中{get;set;}的使用浅谈

属性在调用者看来就像一个普通的变量,但作为类的设计者,你可以利用属性来隐藏你类中的一些字段,使外界只能通过属性来访问你的字段,你可以通过属性来限制外界对你的字段的存取,就利用get、set。C#中get、set用法中,类的set和get成员是外部程序访问类内部属性的唯一方法,就像你去银行取钱,你不能直接从银行的保险柜里拿钱,而是银行营业人员把钱取出来给你的。}的具体使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。

xiaoweids的博客 3251

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

上一篇: Windows计算器的制作(C#)
下一篇: 扫雷游戏(C#)(未做完)
DXB2021
博客等级 码龄5年 307粉丝 289原创
评论 12
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值