C语言点餐系统

点餐系统(c语言) #include<iostream> #include<cstring> #include<stdio.h> #include<string.h> #include<stdlib.h> #include<cstring> #include<conio.h> using namespace std; typedef struct member { char username[20];//用户名 char pa 阅读详情

C语言点餐系统

这是一个很简单的点餐系统,用到的知识也不复杂,所以对新手学习还是很有作用,贴上来给大家参考下。

完成了如下功能:

 1.显示餐厅提示语;

 2.打印菜单(输出菜品分类:主食、甜点、饮料、主菜、开胃菜);

 3.选择ID进入菜品分类子目录;

 4.进行具体选择(可重复选择同一样菜);

 5.返回上级菜单(进行其他分类的选择);

 6.完成点餐;

 7.打印点餐信息(菜名、单价、数量、价格)。

代码如下:

  1. #include <stdio.h>  
  2.   
  3. void main_munu(){  
  4.     //打印主菜单  
  5.     char a[6][20]={"菜单","凉菜","热销菜","主食","饭后甜点","饮料"};  
  6.     int i;  
  7.     printf("%s\n",a[0]);  
  8.     for(i=1;i<6;i++)  
  9.     {  
  10.         printf("\t%d.%s\n",i,a[i]);  
  11.     }  
  12.     printf("\t0.点餐结束\n");  
  13. }  
  14.   
  15. void menu_liangcai(){  
  16.     //凉菜类打印  
  17.     char a[3][20]={"木耳辣根","姜汁皮蛋","肉丝苦菊"};//定义字符数组,存放菜名  
  18.     printf("请具体选择菜品:\n");  
  19.     for (int i = 0; i < 3; i ++) {  
  20.         printf("\t\t%d.%s\n",i+1,a[i]);  
  21.     }  
  22.     printf("\t\t0.返回上层菜单\n");  
  23. }  
  24.   
  25. void menu_rexiao(){  
  26.     //热销菜打印  
  27.     char a[3][20]={"葱烧排骨","麻婆豆腐","香辣小河虾"};//定义字符数组,存放菜名  
  28.     printf("请具体选择菜品:\n");  
  29.     for (int i = 0; i < 3; i ++) {  
  30.         printf("\t\t%d.%s\n",i+1,a[i]);  
  31.     }  
  32.     printf("\t\t0.返回上层菜单\n");  
  33. }  
  34.   
  35. void menu_zhushi(){  
  36.     // 主食类打印  
  37.     char a[3][20]={"香肠焖饭","海鲜炒面","玉米馒头"};//定义字符数组,存放菜名  
  38.     printf("请具体选择菜品:\n");  
  39.     for (int i = 0; i < 3; i ++) {  
  40.         printf("\t\t%d.%s\n",i+1,a[i]);  
  41.     }  
  42.     printf("\t\t0.返回上层菜单\n");  
  43. }  
  44.   
  45. void menu_tiandian(){  
  46.     //甜点类打印  
  47.     char a[3][20]={"草莓冰淇淋","懒人布丁","香橙果冻"};//定义字符数组,存放菜名  
  48.     printf("请具体选择菜品:\n");  
  49.     for (int i = 0; i < 3; i ++) {  
  50.         printf("\t\t%d.%s\n",i+1,a[i]);  
  51.     }  
  52.     printf("\t\t0.返回上层菜单\n");  
  53. }  
  54.   
  55. void menu_yinliao(){  
  56.     //饮料类打印  
  57.     char a[3][20]={"倾橙汁恋","可口可乐","秘制凉茶"};//定义字符数组,存放菜名  
  58.     printf("请具体选择菜品:\n");  
  59.     for (int i = 0; i < 3; i ++) {  
  60.         printf("\t\t%d.%s\n",i+1,a[i]);  
  61.     }  
  62.     printf("\t\t0.返回上层菜单\n");  
  63. }  
  64.   
  65. int main(int argc, const char * argv[]) {  
  66.     printf("***** 法克招牌快餐店 *****\n");  
  67.     printf(" *****  欢迎您点餐 *****\n");  
  68.     int M;//定义用户选择的分类代号为M;  
  69.     int n;//定义用户输入子菜单下的菜品代号为n;  
  70.     int x[5][3] = {0};//定义每类菜品被点数量  
  71.     int price1[5][3] = {0};//每种菜品的价格总价  
  72.     int price[5][3] = {{12,15,13},{25,20,30},{5,5,10},{6,5,3},{3,4,5}};//定义每样菜品单价  
  73.     int total = 0;//定义所有菜品总价 初始化为0;  
  74.     char name[5][3][20] = {{"木耳辣根","姜汁皮蛋","肉丝苦菊"},{"葱烧排骨","麻婆豆腐","香辣小河虾"},{"香肠焖饭","海鲜炒面","玉米馒头"},{"草莓冰淇淋","懒人布丁","香橙果冻"},{"倾橙汁恋","可口可乐","秘制凉茶"}};  
  75.     while (1) {  
  76.         main_munu();  
  77.         scanf("%d",&M);//接收用户输入的菜品分类代号  
  78.         if (M == 0) {  
  79.             break;  
  80.         }  
  81.         switch (M) {  
  82.             case 1:  
  83.             {  
  84.                 menu_liangcai();  
  85.                 while (1) {  
  86.                     scanf("%d",&n);  
  87.                     if (n == 0) {  
  88.                         //如果输入为0,跳出循环(程序中表现为:跳出本菜单下的菜品选择);  
  89.                         break;  
  90.                     }  
  91.                     //统计 每样菜品总价格 与被点次数  
  92.                     price1[0][n-1] += price[0][n-1];  
  93.                     x [0][n-1] ++;   
  94.                 }  
  95.             }  
  96.                 if(n == 0)break;//如果输入为0,结束选菜;  
  97.             case 2:  
  98.             {  
  99.                 menu_rexiao();  
  100.                 while (1) {  
  101.                     scanf("%d",&n);  
  102.                     if (n == 0) {  
  103.                         //如果输入为0,跳出循环(程序中表现为:跳出本菜单下的菜品选择);  
  104.                         break;  
  105.                     }  
  106.                     price1[1][n-1]+=price[1][n-1];  
  107.                     x[1][n-1]++;  
  108.                 }  
  109.             }  
  110.                 if(n == 0)break;//如果输入为0,结束选菜;  
  111.             case 3:  
  112.             {  
  113.                 menu_zhushi();  
  114.                 while (1) {  
  115.                     scanf("%d",&n);  
  116.                     if (n == 0) {  
  117.                         //如果输入为0,跳出循环(程序中表现为:跳出本菜单下的菜品选择);  
  118.                         break;  
  119.                     }  
  120.                     price1[2][n-1] += price[2][n-1];  
  121.                     x[2][n-1]++;  
  122.                 }  
  123.             }  
  124.                 if(n == 0)break;//如果输入为0,结束选菜;  
  125.             case 4:  
  126.             {  
  127.                 menu_tiandian();  
  128.                 while (1) {  
  129.                     scanf("%d",&n);  
  130.                     if (n == 0) {  
  131.                         //如果输入为0,跳出循环(程序中表现为:跳出本菜单下的菜品选择);  
  132.                         break;  
  133.                     }  
  134.                     price1[3][n-1] += price[3][n-1];  
  135.                     x[3][n-1]++;  
  136.                 }  
  137.             }  
  138.                 if(n == 0)break;//如果输入为0,结束选菜;  
  139.             case 5:  
  140.             {  
  141.                 menu_yinliao();  
  142.                 while (1) {  
  143.                     scanf("%d",&n);  
  144.                     if (n == 0) {  
  145.                         //如果输入为0,跳出循环(程序中表现为:跳出本菜单下的菜品选择);  
  146.                         break;  
  147.                     }  
  148.                     price1[4][n-1] += price[4][n-1];  
  149.                     x[4][n-1]++;  
  150.                 }  
  151.             }  
  152.                   
  153.                 if(n == 0)break;//如果输入为0,结束选菜;  
  154.         }  
  155.           
  156.     }  
  157.       
  158.     //打印相关信息  
  159.     printf("菜名\t\t\t单价(元)\t数量\t总价格(元)\n-----------------------------------\n");  
  160.     for (int i = 0; i < 5; i++) {  
  161.         for (int j = 0; j < 3; j++) {  
  162.             if (price1[i][j] != 0) {//用价格判断顾客是否选择 确认打印  
  163.                 printf("%s\t\t%3d\t\t%3d\t%3d\n",name[i][j],price[i][j],x[i][j],price1[i][j]);  
  164.                 total += price1[i][j];//计算总价格  
  165.             }  
  166.         }  
  167.     }  
  168.     printf("总价格:\t\t\t\t\t%3d\n",total);  
  169.     printf("祝您用餐愉快,期待您的下次光临!\n");  
  170.     return 0;  
  171. }  
Xcode中运行结果如下图:

到这里,这个项目的内容就展示完毕了,新学习的朋友可以研究下,相信会帮得到你们。


 
 
用c语言编写简单的餐厅点餐系统(带后台) 简单交互程序,c语言,指针,结构体 阅读详情

相关推荐

C语言结课设计:餐饮管理与点餐系统

一、项目简介 1、本程序实现了用户的点餐功能,共包含五类菜品:凉菜、热菜、锅仔、主食、饮品。还有查看所点菜品与结束等功能。 2、后台管理员:按a可进入,主页面并未提示。 3、合理运用getch函数,清屏与暂停函数,页面整洁清爽。 4、菜品与txt文件对应,可实现对程序与txt的同步增删改查等功能。 5、使用了C语言很多基础语法:函数、指针、结构体、文件等。 二、程序说明 想运行本程序,需要在.C同...

子奕°的博客 3万+

C语言程序设计-餐厅点餐系统

经过以上对本系统的调研及可行性分析后,下面将对系统在功能上以及性能上进行进一步的需求分析。功能:运行开始出现菜单模块,其中有四个选项,可以按相关的数字进行操作。2)点餐信息录入功能(点餐信息用文件保存)——输入;3)点餐信息浏览功能——输出;4)查询和结算功能——算法;1.设计题目:餐厅点餐系统。1)系统以菜单方式工作;

m0_54570435的博客 9762

大一C语言图形界面点餐系统

C语言课设

qq_38240445的博客 3965

c语言点餐怎么变量相加营业额,C语言实现餐饮管理与点餐系统

本文实例为大家分享了C语言实现餐饮管理与点餐系统的具体代码,供大家参考,具体内容如下一、项目简介1、本程序实现了用户的点餐功能,共包含五类菜品:凉菜、热菜、锅仔、主食、饮品。还有查看所点菜品与结束等功能。2、后台管理员:按a可进入,主页面并未提示。3、合理运用getch函数,清屏与暂停函数,页面整洁清爽。4、菜品与txt文件对应,可实现对程序与txt的同步增删改查等功能。5、使用了C语言很多基础语...

weixin_39834678的博客 447

c语言程序设计 点菜系统,C语言点餐系统

这是一个很简单的点餐系统,用到的知识也不复杂,所以对新手学习还是很有作用,贴上来给大家参考下。完成了如下功能:1.显示餐厅提示语;2.打印菜单(输出菜品分类:主食、甜点、饮料、主菜、开胃菜);3.选择ID进入菜品分类子目录;4.进行具体选择(可重复选择同一样菜);5.返回上级菜单(进行其他分类的选择);6.完成点餐;7.打印点餐信息(菜名、单价、数量、价格)。代码如下:#include void ...

weixin_36207513的博客 4072

c语言单链表餐厅点餐系统

餐厅点餐系统,允许用户录入顾客信息、点菜、结账等。用户可以通过主菜单选择不同的操作,包括录入顾客信息、搜索菜品、结算账单、录入菜品、搜索订单等。

weixin_64055968的博客 1067

智能点餐系统

基于使用c++封装类来实现智能点餐系统

hjvft的博客 1996

C语言开发的点餐系统实战指南

数组是一种基础且广泛使用的数据结构,它能够存储一系列相同类型的数据项,通过索引快速访问元素。在点餐系统中,数组常用于存储菜单项、订单详情和用户购物车信息。数组的主要优势在于其快速的随机访问能力和简洁的内存布局。例如,在菜单管理中,可以通过数组存储每个菜品的信息,并通过菜品编号快速查询菜品价格、描述等属性。// 示例:使用数组存储菜单项"宫保鸡丁","鱼香肉丝","清蒸鲈鱼",// ...在上述代码中,我们定义了一个字符串数组menuItems来存储菜单项名称。

weixin_42360733的博客 484

C/C++餐厅自动化点餐系统

【代码】C/C++餐厅自动化点餐系统。

2301_76817904的博客 2508

外卖系统C语言

C语言控制台编写外卖系统

C语言实现外卖管理系统

主要为大家详细介绍了C语言实现外卖管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

小学期项目(C语言)————外卖点餐系统(功能齐全)

纯C语言编写的外卖点餐系统,包含商家、客户、骑手三个对象,每个对象功能齐全,对象之间信息想通

yjz1314andyou的博客 3565

告别地图偏移!手把手教你用MapOnline V1.2在ArcGIS里加载无偏谷歌影像和历史影像

本文详细介绍了如何使用MapOnline V1.2插件在ArcGIS中加载无偏谷歌影像和历史影像,解决GIS工程师长期面临的地图偏移问题。通过三步安装配置、无偏影像加载和时空分析功能,提升地理信息数据的精确度和工作效率,特别适用于城市规划、环境监测等场景。

weixin_29252171的博客 232

用c语言程序写一个电子点餐系统,基于C语言代码实现点餐系统

这是一个很简单的点餐系统,用到的知识也不复杂,所以对新手学习还是很有作用,贴上来给大家参考下。完成了如下功能:1.显示餐厅提示语;2.打印菜单(输出菜品分类:主食、甜点、饮料、主菜、开胃菜);3.选择ID进入菜品分类子目录;4.进行具体选择(可重复选择同一样菜);5.返回上级菜单(进行其他分类的选择);6.完成点餐;7.打印点餐信息(菜名、单价、数量、价格)。代码如下:#include void ...

weixin_31034309的博客 3191

遥感SCI期刊模板下载教程———IEEE TGRS、GRSL、JSTARS

IEEE下的期刊模板下载,以IEEE TGRS 为例。

海淀小天的blog 2万+

VSCode + Clangd 配置避坑实录:从‘红波浪线’到完美代码提示的完整心路

本文详细记录了VSCode与Clangd配置过程中的常见问题及解决方案,从编译数据库生成到参数调优,帮助C++开发者快速解决代码提示失效、头文件找不到等问题,实现完美代码补全体验。重点介绍了Clangd与LLDB的集成配置及性能优化技巧,适用于Linux和跨平台开发环境。

weixin_28829479的博客 491

c语言点餐系统的优缺点,一个简单C语言点餐系统的学习心得

软件工程综合实践专题个人博客第一次作业,这个系统来自https://blog.youkuaiyun.com/sinat_16590595/article/details/48245347,这是用c语言编写的一个点餐系统。首先附上源代码:1 #include 23 voidmain_munu(){4 //打印主菜单5 char a[6][20]={"菜单","凉菜","热销菜","主食","饭后...

weixin_39854369的博客 545

RDMA性能调优实战:如何用ib_*命令榨干你的Mellanox网卡带宽?

本文深入探讨了如何利用ib_*命令工具集对RDMA网络进行深度性能调优,以充分释放Mellanox网卡的带宽潜力。文章从理解Send/Write/Read三种核心通信原语的差异入手,逐步指导读者通过调整消息大小、队列深度、内联数据等关键参数,并结合系统级的NUMA绑定、中断亲和性等优化策略,实现从基准测试到逼近硬件极限的性能提升。

weixin_29306011的博客 88

c语言点餐系统感悟,一个简单C语言点餐系统的学习心得

首先附上源代码:1 #include 23 voidmain_munu(){4 //打印主菜单5 char a[6][20]={"菜单","凉菜","热销菜","主食","饭后甜点","饮料"};6 inti;7 printf("%s\n",a[0]);8 for(i=1;i<6;i++)9 {10 printf("\t%d.%s\n"...

weixin_35893552的博客 612

海康Visionmaster-全局脚本:VM 加载方案后自动执行 的方法,如何让VM在方案加载后自动执行流程?

海康Visionmaster-全局脚本:VM 加载方案后自动执行 的方法,如何让VM在方案加载后自动执行流程?

视觉人机器视觉的博客 2038

【全网首发】2026华为OD双机位C卷 机考真题题库含考点说明以及在线OJ (Java)

如果你收到的是双机位C卷考试通知,需要针对性地调整备考策略。自2025年11月19日起,华为OD机试已正式从双机位A卷切换至。复杂度明显提升,需要组合多个算法点。题面相对简单,直接考查编程基本功。考查问题分析、算法选择和优化能力。通常为1-2个核心算法点的应用。

算法大师! 169

c语言点餐程序,C语言实现点餐系统

#includeusing namespace std;typedef struct member{char username[20];//用户名char password[20];//密码}Member;typedef struct product{char name[20];//菜品名int price;int num;//销售数量}Product;/*菜单函数区*/void menu1();...

weixin_42497633的博客 1892

Dify智能体开发:Dify文件上传

相较于聊天文本,文档文件能够承载大量的信息,例如学术报告、法律合同。受限于 LLM 自身仅能够支持文件或图片,难以获取文件内更加丰富的上下文信息,应用的使用者不得不手动复制粘贴大量信息与 LLM 对话,增加了许多不必要的使用成本。

王国平的博客 2591

一个简单C语言点餐系统的学习心得

软件工程综合实践专题个人博客第一次作业,这个系统来自https://blog.youkuaiyun.com/sinat_16590595/article/details/48245347,这是用c语言编写的一个点餐系统。 首先附上源代码: 1 #include <stdio.h> 2 3 void main_munu(){ 4 //打印主菜单 5 cha...

weixin_30555515的博客 1528

在 ABAP Cloud 中玩转 CL_ABAP_PARALLEL 并行处理:从原理到实战

ABAP并行处理框架CL_ABAP_PARALLEL解析 本文系统介绍了SAP ABAP环境中实现并行处理的CL_ABAP_PARALLEL框架。该框架通过封装异步RFC和对话进程,为开发者提供了面向对象的API,显著提升大批量数据处理的效率。 文章首先分析了ABAP环境需要并行处理的原因:传统的串行处理在面对百万级数据时效率低下。然后详细介绍了CL_ABAP_PARALLEL的设计思路,它是一个"小型线程池"式的同步并行框架,适用于批量计算场景。此外,文章重点讲解了控制并行任务的关键参

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 341

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

c语言实训论文 点餐系统,数据结构实训报告c语言点餐系统net.docx

北京联合大学数据结构实训报告课程名称 项目名称 学 院 姓 名 指导老师数据结构实训餐厅点餐系统管理学院业:信息管理与信息系统2011年1月13日目录TOC \o "1-5" \h \z 北京朕合大学1\o "Current Document" 数据结构实训报告1\o "Current Document" 一、实践题目3\o "Current Document" 二、实践目的3\o "Curren...

weixin_36312603的博客 1076

深度学习工具包 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")

上一篇: 使用安装在linux端的loadgenerator,在controller加载并发人数受限的问题解决
下一篇: OC第一个程序的解释
Aurora Polaris
博客等级 码龄17年 384粉丝 91原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值