日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

智能家居 (2) ——设计模式的引入

發(fā)布時間:2023/12/10 asp.net 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 智能家居 (2) ——设计模式的引入 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

目錄

  • 設(shè)計(jì)模式的概念引入
  • 工廠模式的實(shí)現(xiàn)
    • animal.h
    • mainPro.c
    • cat.c
    • dog.c
    • person.c
  • 工廠模式的功能驗(yàn)證
  • 往期文章

設(shè)計(jì)模式的概念引入

工廠模式的實(shí)現(xiàn)

所有代碼最好在Source Insight下編寫,并將所有代碼進(jìn)行關(guān)聯(lián),方便讀寫。

animal.h

#include <stdio.h>struct Animal{char name[128];int age;int sex;int others;void (*peat)();void (*pbeat)();void (*test)();struct Animal *next;};struct Animal* putPersonInLink(struct Animal *phead);//先聲明 struct Animal* putCatInLink(struct Animal *phead); struct Animal* putDogInLink(struct Animal *phead);

mainPro.c

#include "animal.h" #include <string.h>struct Animal* findUtilByName(char* str, struct Animal* phead)//結(jié)構(gòu)體查詢 {struct Animal *tmp= phead;if(phead== NULL){printf("空\n");return NULL;}else{while(tmp != NULL){if(strcmp(tmp->name,str) == 0){return tmp;}tmp=tmp->next;}return NULL;} }int main() {char buf[128]={'\0'};struct Animal *phead = NULL;struct Animal *ptmp;phead = putCatInLink(phead);phead = putDogInLink(phead);phead = putPersonInLink(phead);//至此已經(jīng)組合完成整個鏈表while(1){printf("please input:Tom,ahuang, xiaoming\n"); //鏈表的查詢scanf("%s",buf);ptmp = findUtilByName(buf,phead);if(ptmp != NULL){ptmp->pbeat();ptmp->peat();}memset(buf, '\0',sizeof(buf)); //此處不能用strlen}return 0; }

cat.c

#include "animal.h"void catEat() {printf("cat eat fish\n"); }void catBeat() {printf("cat bite your little brother\n"); }struct Animal cat = {.name = "Tom",.peat = catEat,.pbeat = catBeat};struct Animal* putCatInLink(struct Animal *phead) {if(phead == NULL){phead = &cat;return phead;}else{cat.next = phead; //頭插法phead = &cat;return phead; //返回最新的頭} }

dog.c

#include "animal.h"void dogEat() {printf("dog eat shi\n"); }void dogBeat() {printf("dog bite your little brother\n"); }struct Animal dog = {.name = "ahuang",.peat = dogEat,.pbeat = dogBeat};struct Animal* putDogInLink(struct Animal *phead) {if(phead == NULL){phead = &dog;return phead;}else{dog.next = phead;phead = &dog;return phead;} }

person.c

#include "animal.h"void personEat() {printf("person eat rice\n"); }void personBeat() {printf("person bite your brother\n"); }struct Animal person = {.name = "xiaoming",.peat = personEat,.pbeat = personBeat};struct Animal* putPersonInLink(struct Animal *phead) {if(phead == NULL){phead = &person;return phead;}else{person.next = phead;phead = &person;return phead;} }

工廠模式的功能驗(yàn)證

將上述代碼放到ubuntu下運(yùn)行,效果如下:

用Source Insight編寫代碼會有一些編碼格式問題,拿過來放到ubuntu上運(yùn)行會出現(xiàn)亂碼,最好不要有中文。

如若想在鏈表上加入其它的animal,直接新建編寫一個.C文件,然后加入到鏈表中。
這樣就完成類似不斷給智能家居加入新功能,同時也有助于代碼的維護(hù)。

往期文章

智能家居 (1) ——智能家居整體功能框架
智能家居 (2) ——設(shè)計(jì)模式的引入
智能家居 (3) ——工廠模式繼電器控制燈
智能家居 (4) ——工廠模式火焰報(bào)警
智能家居 (5) —— LD3320語音模塊二次開發(fā)
智能家居 (6) ——語音識別線程控制
智能家居 (7) ——網(wǎng)絡(luò)服務(wù)器線程控制
智能家居 (8) ——智能家居項(xiàng)目整合(網(wǎng)絡(luò)控制線程、語音控制線程,火災(zāi)報(bào)警線程)
網(wǎng)絡(luò)編程知識預(yù)備(1) ——了解OSI網(wǎng)絡(luò)模型
網(wǎng)絡(luò)編程知識預(yù)備(2) ——淺顯易懂的三次握手與四次揮手
網(wǎng)絡(luò)編程知識預(yù)備(3) ——SOCKET、TCP、HTTP之間的區(qū)別與聯(lián)系
網(wǎng)絡(luò)編程知識預(yù)備(4) ——了解HTTP協(xié)議與HTTPS協(xié)議
網(wǎng)絡(luò)編程知識預(yù)備(5) ——libcurl庫簡介及其編程訪問百度首頁
智能家居 (9) ——人臉識別攝像頭安裝實(shí)現(xiàn)監(jiān)控功能
智能家居 (10) ——人臉識別祥云平臺編程使用
智能家居 (11) ——樹莓派攝像頭捕捉人臉并識別
智能家居 (12) ——人臉識別整合到智能家居系統(tǒng)
智能家居 (13) ——智能家居加入手機(jī)app端控制

總結(jié)

以上是生活随笔為你收集整理的智能家居 (2) ——设计模式的引入的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。