(C++)设计模式

news/2024/4/23 16:15:03/

1、设计原则

(1)开放封闭原则:类的改动是通过增加代码进行的,而不是修改代码
(2)依赖倒置原则:依赖于抽象,不要依赖于具体的实现(类),也就是针对接口编程

#include <iostream>
using namespace std;class BankWorker   //抽象类
{public:virtual void Worker() = 0;};class GetMoney:public BankWorker 
{public:void Worker()                   //虚函数重写{cout<<"取款业务"<<endl;}};class SaveMoney:public BankWorker 
{public:void Worker(){cout<<"存款业务"<<endl;}};int main(int argc, char const *argv[])
{BankWorker *b = new GetMoney; b->Worker();delete b;b = new SaveMoney;b->Worker();delete b;return 0;
}

2、依赖倒置原则

实列:电脑:硬盘、CPU

#include <iostream>
using namespace std;class HardDisk
{public:virtual void Work() = 0;
};class CPU
{public:virtual void Work() = 0;
};class AHardDisk:public HardDisk
{public:void Work(){cout<<"AHard Disk work"<<endl;}
};class ACPU:public CPU
{public:void Work(){cout<<"ACPU work"<<endl;}
};class Computer
{private:HardDisk *m_h;CPU *m_c;public:Computer(HardDisk *h, CPU *c){m_h = h;m_c = c;}void work(){m_h->Work();m_c->Work();}
};int main(int argc, char const *argv[])
{CPU *c = new ACPU;                 //c指向 ACPU,相当于可以操作里面的publicHardDisk *h = new AHardDisk;       //h指向 AHardDisk,相当于可以操作里面的publicComputer *com = new Computer(h,c);  //将两个指针传给 m_h, m_c, 他们自然可以操作work();com->work();return 0;
}

3、单例模式-懒汉式

单例模式:保证一个类只生成唯一的实例对象,也就是说,整个程序空间中,只存在一个实例对象。

#include <iostream>
#include <unistd.h>
#include <pthread.h>
using namespace std;class Singleton
{private:static Singleton *m_instance;static int count;Singleton(){}public:static Singleton *GetInstance(){if (NULL == m_instance){printf("分配空间\n");usleep(1000000);m_instance = new Singleton;}count++;return m_instance;}static int GetCount(){return count;}void Release(){count--;if (count == 0 && m_instance != NULL){delete m_instance;}}
};Singleton * Singleton::m_instance = NULL;
int Singleton::count = 0;int main(int argc, char const *argv[])
{Singleton *s1 = Singleton::GetInstance();Singleton *s2 = Singleton::GetInstance();Singleton *s3 = Singleton::GetInstance();Singleton *s4 = Singleton::GetInstance();cout<<Singleton::GetCount()<<endl;if (s1 == s2){cout<<"equal"<<endl;}s1->Release();return 0;
}

加入线程!

#include <iostream>
#include <unistd.h>
#include <pthread.h>
pthread_mutex_t mutex;
using namespace std;class Singleton
{private:static Singleton *m_instance;static int count;Singleton(){}public:static Singleton *GetInstance(){if (NULL == m_instance){printf("分配空间\n");usleep(1000000);m_instance = new Singleton;}count++;return m_instance;}static int GetCount(){return count;}void Release(){count--;if (count == 0 && m_instance != NULL){delete m_instance;}}
};void *CreateInstance(void *arg)
{/*int ret = pthread_mutex_trylock(&mutex);if (ret == 0){cout<<"锁没有被使用"<<endl;Singleton *s = Singleton::GetInstance();cout<<s<<endl;pthread_mutex_unlock(&mutex);}else if (EBUSY == ret){cout<<"锁正在被使用"<<endl;}*/pthread_mutex_lock(&mutex);Singleton *s = Singleton::GetInstance();cout<<s<<endl;pthread_mutex_unlock(&mutex);return NULL;
}Singleton * Singleton::m_instance = NULL;
int Singleton::count = 0;int main(int argc, char const *argv[])
{/* Singleton *s1 = Singleton::GetInstance();Singleton *s2 = Singleton::GetInstance();Singleton *s3 = Singleton::GetInstance();Singleton *s4 = Singleton::GetInstance();cout<<Singleton::GetCount()<<endl;if (s1 == s2){cout<<"equal"<<endl;}s1->Release();*/pthread_mutex_init(&mutex, NULL);int ret;pthread_t tid[10];for (int i = 0; i < 10; i++){ret = pthread_create(&tid[i],NULL,CreateInstance,NULL);if (ret != 0){perror("pthread_create");}}void *status;for (int i = 0; i < 10; i++){pthread_join(tid[i],&status);}pthread_mutex_destroy(&mutex);return 0;
}

4、单例模式-饿汉式

先分配空间,在按照单例模式,只分配一次空间。

#include <iostream>
#include <unistd.h>
#include <pthread.h>
pthread_mutex_t mutex;
using namespace std;class Singleton
{private:static Singleton *m_instance;static int count;Singleton(){}public:static Singleton *GetInstance(){/*if (NULL == m_instance){printf("分配空间\n");usleep(1000000);m_instance = new Singleton;}*/count++;return m_instance;}static int GetCount(){return count;}void Release(){count--;if (count == 0 && m_instance != NULL){delete m_instance;}}
};Singleton * Singleton::m_instance = new Singleton;  //先分配空间
int Singleton::count = 0;int main(int argc, char const *argv[])
{Singleton *s1 = Singleton::GetInstance();Singleton *s2 = Singleton::GetInstance();Singleton *s3 = Singleton::GetInstance();Singleton *s4 = Singleton::GetInstance();cout<<Singleton::GetCount()<<endl;if (s1 == s2){cout<<"equal"<<endl;}s1->Release();return 0;
}

5、工厂模式

(1)简单工厂模式

#include <iostream>
using namespace std;class Fruit
{public:virtual void show() = 0;};class Apple:public Fruit
{public:void show(){cout<<"this is apple....."<<endl;}
};class Banana:public Fruit
{public:void show(){cout<<"this is banana....."<<endl;}
};class Pear:public Fruit
{public:void show(){cout<<"this is pear....."<<endl;}
};class Factory
{public:Fruit* CreateApple(){return new Apple;}Fruit* CreateBanana(){return new Banana;}Fruit* CreatePear(){return new Pear;}};int main(int argc, char const *argv[])
{Factory *f = new Factory;Fruit *Fruit;Fruit = f->CreateApple();Fruit->show();delete Fruit;Fruit = f->CreateBanana();Fruit->show();delete Fruit;return 0;
}

(2)工厂模式

#include <iostream>
using namespace std;class Fruit
{public:virtual void show() = 0;};class Apple:public Fruit
{public:void show(){cout<<"this is apple....."<<endl;}
};class Banana:public Fruit
{public:void show(){cout<<"this is banana....."<<endl;}
};class Pear:public Fruit
{public:void show(){cout<<"this is pear....."<<endl;}
};class Factory
{public:virtual Fruit* Create() = 0;
};class AppleFactory:public Factory
{public:Fruit* Create(){return new Apple;}
};class BananaFactory:public Factory
{public:Fruit* Create(){return new Banana;}
};class PearFactory:public Factory
{public:Fruit* Create(){return new Pear;}
};int main(int argc, char const *argv[])
{Factory *f = new AppleFactory;Fruit *Fruit;Fruit = f->Create();Fruit->show();delete f;delete Fruit;f = new BananaFactory;Fruit = f->Create();Fruit->show();delete f;delete Fruit;return 0;
}

(3)抽象工厂模式

#include <iostream>
using namespace std;class Fruit
{public:virtual void show() = 0;};class NorthApple:public Fruit
{public:void show(){cout<<"this is northapple....."<<endl;}
};class SouthApple:public Fruit
{public:void show(){cout<<"this is southapple....."<<endl;}
};class NorthBanana:public Fruit
{public:void show(){cout<<"this is northbanana....."<<endl;}
};class SouthBanana:public Fruit
{public:void show(){cout<<"this is southbanana....."<<endl;}
};class NorthPear:public Fruit
{public:void show(){cout<<"this is northpear....."<<endl;}
};class SouthPear:public Fruit
{public:void show(){cout<<"this is southpear....."<<endl;}
};class Factory
{public:virtual Fruit* CreateApple() = 0;virtual Fruit* CreateBanana() = 0;virtual Fruit* CreatePear() = 0;};class NorthFactory:public Factory
{public:Fruit* CreateApple(){return new NorthApple;}Fruit* CreateBanana(){return new NorthBanana;}Fruit* CreatePear(){return new NorthPear;}
};class SouthFactory:public Factory
{public:Fruit* CreateApple(){return new SouthApple;}Fruit* CreateBanana(){return new SouthBanana;}Fruit* CreatePear(){return new SouthPear;}
};void Create(Factory *f)
{Fruit *fruit;fruit = f->CreateApple();fruit->show();delete fruit;fruit = f->CreateBanana();fruit->show();delete fruit;
}int main(int argc, char const *argv[])
{Factory *f = new SouthFactory;Create(f);delete f;f = new NorthFactory;Create(f);delete f;return 0;
}

6、建造者模式

(1)简单版

#include <iostream>
using namespace std;class House
{private:string wall;string window;string door;public:void SetWall(){wall = "WALL";}void Setwindow(){window = "WINDOW";}void Setdoor(){door = "DOOR";}
};class Builder
{private:House *house;public:Builder(House *h){house = h;}void Constructor(){house->Setdoor();house->SetWall();house->Setwindow();}
};int main(int argc, char const *argv[])
{House *h = new House;Builder *b = new Builder(h);b->Constructor();return 0;
}

(2)建造者模式

#include <iostream>
using namespace std;class House
{private:string wall;string window;string door;public:void SetWall(string w){wall = w;}void Setwindow(string w){window = w;}void Setdoor(string d){door = d;}
};class Builder
{protected:House *house;public:virtual void Constructor() = 0;
};class CommonBuilder:public Builder
{public:CommonBuilder(House *h){house = h;}void Constructor(){house->Setdoor("DOOR");house->SetWall("WALL");house->Setwindow("WINDOW");}
};class VillaBuilder:public Builder
{public:VillaBuilder(House *h){house = h;}void Constructor(){house->Setdoor("VILLADOOR");house->SetWall("VILLAWALL");house->Setwindow("VILLAWINDOW");}
};class Designer
{private:Builder *b;public:void SetBuilder(Builder *builder){b = builder;}void Constructor(){b->Constructor();}
};int main(int argc, char const *argv[])
{Designer *d = new Designer;House *h = new House;Builder *b = new CommonBuilder(h);d->SetBuilder(b);d->Constructor();delete b;return 0;
}

7、原型模式

#include <iostream>
#include <cstring>
using namespace std;class Person
{protected:char name[32];int age;public:Person(){}Person(char *n, int a){strcpy(name,n);age = a;}virtual void show() = 0;virtual Person* clone() = 0;
};class Student:public Person
{private:int id;public:Student(){}Student(char *n, int a, int i):Person(n,a){id = i;}void show(){cout<<"name = "<<name<<" age = "<<age<<" id = "<<id<<endl;}Person* clone(){Student *tmp = new Student;*tmp = *this;return tmp;}
};int main(int argc, char const *argv[])
{Person *p1 = new Student("aa",18,100);Person *p2 = p1->clone();p2->show();return 0;
}

8、组合模式

#include <iostream>
#include <list>
using namespace std;class iFile
{public:virtual string GetName() = 0;virtual int Add(iFile *file) = 0;virtual int Remove(iFile *file) = 0;virtual list<iFile*> *GetChild() = 0;
};class File:public iFile
{private:string name;public:File(string n){name = n;}string GetName(){return name;}int Add(iFile *file){return -1;}int Remove(iFile *file){return -1;}list<iFile *>*GetChild(){return NULL;}
};class Dir : public iFile
{private:string name;list<iFile *> *l;public:Dir(string n){name = n;l = new list<iFile *>;}string GetName(){return name;}int Add(iFile *file){l->push_back(file);return 1;}int Remove(iFile *file){l->remove(file);return 1;}list<iFile*> *GetChild(){return l;}
};void show(iFile *root, int gap)
{for (int i = 0; i < gap; i++){cout<<"---";}if (root != NULL){cout<<root->GetName()<<endl;}else{return;}list<iFile *> *l = root->GetChild();if (l != NULL){for (auto it = l->begin(); it != l->end(); it++){show(*it, gap+1);}}}int main(int argc, char const *argv[])
{iFile *dir1 = new Dir("home");iFile *dir2 = new Dir("day1");iFile *dir3 = new Dir("day2");iFile *file1 = new File("1.c");iFile *file2 = new File("2.c");iFile *file3 = new File("3.c");iFile *file4 = new File("4.c");iFile *file5 = new File("5.c");iFile *file6 = new File("6.c");dir1->Add(file1);dir2->Add(file2);dir2->Add(file3);dir3->Add(file4);dir3->Add(file5);dir3->Add(file6);dir3->Add(file6);dir1->Add(dir2);dir1->Add(dir3);show(dir1,0);return 0;
}

9、代理模式

#include <iostream>
using namespace std;class Sale
{public:virtual void SaleBook() = 0;
};class BookStore:public Sale
{private:static int count;public:void SaleBook(){cout<<"书店卖书"<<endl;count++;}static int GetCount(){return count;}
};int BookStore::count = 0;
class TaoBao:public Sale
{private:Sale *sale;public:TaoBao(Sale *s){sale = s;}void SaleBook(){cout<<"网上卖书"<<endl;sale->SaleBook();}
};int main(int argc, char const *argv[])
{Sale *store = new BookStore;Sale *taoBao = new TaoBao(store);store->SaleBook();taoBao->SaleBook();cout<<BookStore::GetCount()<<endl; return 0;
}

10、装饰模式

//把要添加的附加功能分别放在单独的类中,让这个类包含有装饰的对象

#include <iostream>
using namespace std;class Phone
{public:virtual void Function() = 0;
};class CallPhone:public Phone
{public:void Function(){cout<<"能打电话的手机"<<endl;}
};class PhotoPhone:public Phone
{private:Phone *phone;public:PhotoPhone(Phone *p){phone = p;}void Function(){phone->Function();cout<<"能拍照的手机"<<endl;}
};class MusicPhone:public Phone
{private:Phone *phone;public:MusicPhone(Phone *p){phone = p;}void Function(){phone->Function();cout<<"能听音乐的手机.."<<endl;}
};class IPhone:public Phone
{private:Phone *phone;public:IPhone(Phone *p){phone = p;}void Function(){phone->Function();cout<<"能上网的手机..."<<endl;}
};int main(int argc, char const *argv[])
{cout<<"***************打电话******************"<<endl;Phone *callPhone = new CallPhone();callPhone->Function();cout<<"***************拍照******************"<<endl;Phone *photoPhone = new PhotoPhone(callPhone);photoPhone->Function();cout<<"***************听音乐******************"<<endl;Phone *musicPhone = new MusicPhone(photoPhone);musicPhone->Function();cout<<"***************上网******************"<<endl;Phone *iPhone = new IPhone(musicPhone);iPhone->Function();return 0;
}

11、适配器模式

//适配器模式:改变已有类或外部类的接口形式

//适用情况:将一个类的接口转成客户所希望的另一个接口

#include <iostream>
using namespace std;class Current
{public:virtual int GetCurrent() = 0;
};class Current_220:public Current
{public:int GetCurrent(){return 220;}
};class Adapter:public Current
{private:Current *current;public:Adapter(Current *c){current = c;}int GetCurrent(){if (current->GetCurrent() == 220){return 12;}else{return 5;}}
};class Phone
{private:Current *current;public:Phone(Current *c){current = c;}void Start(){if (current->GetCurrent() == 220){cout<<"boom..."<<endl;}else if(current->GetCurrent() == 12){cout<<"手机充电中......"<<endl;}}
};int main(int argc, char const *argv[])
{Current *c = new Current_220;Current *a = new Adapter(c);Phone *p = new Phone(a);p->Start();return 0;
}

12、享元模式

#include <iostream>
#include <map>
using namespace std;class Student
{private:string name;int age;int id;public:Student(){}Student(string n, int a, int i){name = n;age = a;id = i;}string GetName(){return name;}int GetAge(){return age;}int GetId(){return id;}
};class FwFactory
{private:multimap<int, Student *> *m;public:FwFactory(){m = new multimap<int, Student*>;}~FwFactory(){while (!m->empty()){Student *tmp = m->begin()->second;delete tmp;m->erase(m->begin());}delete m;}void GetPerson(int id){string name;int age;multimap<int,Student *>::iterator it;it = m->find(id);if (it == m->end()){cout<<"input the name age...."<<endl;cin>>name>>age;Student *s = new Student(name, age, id);m->insert(make_pair(id,s));}else{Student *s = it->second;cout<<s->GetName()<<s->GetAge()<<s->GetId()<<endl;}}
};int main(int argc, char const *argv[])
{FwFactory *f = new FwFactory;f->GetPerson(1);f->GetPerson(2);f->GetPerson(3);cout<<"*******************"<<endl;f->GetPerson(3);return 0;
}

13、观察者模式

//当一个对象状态发生变化时,自动通知其它关联对象,自动解析对象状态

#include <iostream>
#include <list>
using namespace std;class Infom;
class Observer  //观察者
{public:virtual void Subscribe(Infom *l) = 0;   //订阅virtual void Unsubscribe(Infom *l) = 0;   //取消订阅virtual void Update(string str) = 0;   //更新状态
};class Infom  //通知者    秘书
{public:virtual void Add(Observer *o) = 0;virtual void Remove(Observer *o) = 0;virtual void Noftify(string str) = 0;
};class secretary:public Infom
{private:list<Observer *> l;public:virtual void Add(Observer *o){l.push_back(o);}virtual void Remove(Observer *o){l.remove(o);}virtual void Noftify(string str){for (auto it = l.begin(); it != l.end(); it++){(*it)->Update(str);}}
};class Staff:public Observer
{public:virtual void Subscribe(Infom *l)    //订阅{l->Add(this);}virtual void Unsubscribe(Infom *l)  //取消订阅{l->Remove(this);}virtual void Update(string str)   //更新状态{if (str == "WARNING"){cout<<"boss is coming"<<endl;}else{cout<<"continue to play games..."<<endl;}}
};int main(int argc, char const *argv[])
{Infom *i = new secretary;Observer *o1 = new Staff;Observer *o2 = new Staff;Observer *o3 = new Staff;Observer *o4 = new Staff;o1->Subscribe(i);o2->Subscribe(i);o3->Subscribe(i);o4->Subscribe(i);i->Noftify("WARNING");return 0;
}

14、桥接模式

#include <iostream>
using namespace std;class Phone
{public:virtual void func() = 0;
};class HUAWEL:public Phone
{public:void func(){cout<<"this is HUAWEI..."<<endl;}
};class Iphone:public Phone
{public:void func(){cout<<"this is Iphone..."<<endl;}
};class Soft
{protected:Phone *phone;public:virtual void func() = 0;
};class QQ:public Soft
{public:QQ(Phone *p){phone = p;}void func(){phone->func();cout<<"this is QQ...."<<endl;}
};class Vchat:public Soft
{public:Vchat(Phone *p){phone = p;}void func(){phone->func();cout<<"this is Vchat...."<<endl;}
};int main(int argc, char const *argv[])
{Phone *p = new HUAWEL;Soft *s = new QQ(p);s->func();return 0;
}

15、外观模式

#include <iostream>
using namespace std;class SystemA
{public:void func(){cout<<"this is A..."<<endl;}
};class SystemB
{public:void func(){cout<<"this is B..."<<endl;}
};class SystemC
{public:void func(){cout<<"this is C..."<<endl;}
};class Facade
{private:SystemA *a;SystemB *b;SystemC *c;public:Facade(){a = new SystemA;b = new SystemB;c = new SystemC;}~Facade(){delete a;delete b;delete c;}void func(){a->func();b->func();c->func();}};int main(int argc, char const *argv[])
{Facade *f = new Facade;f->func();return 0;
}


http://www.ppmy.cn/news/662051.html

相关文章

2021年下半年软考-网络工程师答案及解析(中级)

写在前面&#xff1a;哈哈&#xff0c;时间过得真快&#xff0c;马上毕业了&#xff0c;我想和你分享一下&#xff0c;网络工程师对我找工作的影响。2021年10月份向锐捷网络投了一份简历&#xff0c;第一轮笔试好像是行测&#xff0c;第二轮笔试是C语言相关的选择题&#xff0c…

datacom-HCIP之题库继续解析

1、 下面是路由器Huawei的部分配置信息&#xff0c;关于该配置信息描述错误的是: [HUAWEl] ip as-path-filter 2 permit _200 300 [HUAWEI] route-policy test permit node 10 [HUAWE-route-policy] if-match as-path-filter 2 &#xff08;单选题&#xff09; A: 该Route P…

第十五天笔记

企业网的三层架构---企业网搭建时的一个参考建议方案 园区---工厂&#xff0c;政府机关&#xff0c;商场&#xff0c;写字楼&#xff0c;校园&#xff0c;公园等这些公共场所为了实现数据互通而搭建的网络我们都可以称为园区网----“城市&#xff0c;除了街道&#xff0c;都是园…

HCIP第十五天

企业网的三层架构---企业网搭建时的一个参考建议方案 元x- ”&#xff0c;政府机关&#xff0c;商场&#xff0c;写字楼&#xff0c;校园&#xff0c;公园等这些公共场所为了实现数据互通而搭 建的网络我们都可以称为园区网---“城市&#xff0c;除了街道&#xff0c;都是园区…

计算机网络-路由器

软考每年必考&#xff0c;主要掌握路由器的工作原理&#xff0c;常用的路由协议&#xff1a;RIP、OSPF、ISIS、BGP等。 考试中直接涉及分值约10分&#xff0c;主要掌握路由器的动态路由协议RIP和OSPF的配置等。 涉及到的主要知识点有&#xff1a;RIP工作原理&#xff0c;RIP配置…

MFC学习笔记2--C++的重要性质

封装(encapsulation):类及其成员&#xff1a;属性&#xff0c;方法。 继承(Inheritance):基类(base class),派生类(derived class) this指针 虚函数与多态(Polymorphism) Object slicing与虚函数 静态成员(变量与函数) 构造函数与析构函数 四种不同的对象生成方式(in stack,int…

华为OJ题目 -- 初级篇(机试OJ平台)

华为OJ初级篇是本人搜集的一些题目&#xff0c;都run过OK&#xff0c;初级题我个人感觉必要在15-20min以内完成&#xff0c;不然时间不够用&#xff0c;一共三道&#xff0c;后两道中高级题目。 题目一&#xff1a; 操作系统任务调度问题。操作系统任务分为系统任务和用户任务…

一指闪付,Huawei Pay让钱包、银行卡和公交卡统统下岗

人们的出行将越来越便捷&#xff0c;带一部手机就能乘坐交通工具。只要你拥有一部华为Mate 9手机&#xff0c;搭配Huawei Pay使用&#xff0c;就能甩掉经常被忘带的钱包&#xff0c;让现金、银行卡和公交卡统统“下岗”。 Huawei Pay是华为开发的基于指纹NFCinSE安全芯片&#…

小米手环/华为手环复制无法识别的加密校园卡(可刷门禁,只需一张卡,最简单方式)

小米手环复制校园卡&#xff08;最简单方式&#xff09;&#xff0c;解决小米手环不能复制门禁卡。 注意&#xff0c;这里的校园卡是加密卡&#xff0c;一般不容易破解&#xff0c;这里只是读取并写入0扇区的第一行数据&#xff0c;只能够身份识别充当门禁卡&#xff0c;不能进…

cnpm : 无法加载文件 C:\Users\user\AppData\Roaming\npm\cnpm.ps1,因为在此系统上禁止运行脚本

问题描述 在VScode环境中运行cnpm命令时出现以下报错&#xff1a; cnpm : 无法加载文件 C:\Users\user\AppData\Roaming\npm\cnpm.ps1&#xff0c;因为在此系统上禁止运行脚本。 有关详细信息&#xff0c;请参阅 https:/go.microsoft.com/fwlink/?LinkID135170 中的 about_E…

jasny-bootstrap组件-文件上传

今天和大家分享jasny-bootstrap如何实现文件上传&#xff0c;以及同form表单同时提交处理。 目前各大网站关于jasny-bootstrap上传文件的案例demo少之又少&#xff0c;就连若依也只是一笔带过&#xff0c;只是做了一个纯效果展示。 经过博主的一番查阅文档&#xff0c;查找案例…

Vscode解决Setting.json报警告:Problems loading reference ... Unable to load schema from ...

一. 问题分析 在vscode中打开设置文件setting.json时&#xff0c;问题窗口会报警告&#xff0c;如下图所示。. Ctrl C 复制下警告信息&#xff0c;粘贴到txt中&#xff0c;显示如下&#xff1a; { “resource”: “/C:/Users/xu/AppData/Roaming/Code/User/settings.json”,…

【问题记录】Python出现NoneType.__format__的问题

问题记录&#xff1a; 调试程序时&#xff0c;发现报错&#xff1a; File "C:\Users\HP\PycharmProjects\pythonProject\StudentScoreManagerSystem\stusystem.py", line 297, in <module>main()File "C:\Users\HP\PycharmProjects\pythonProject\Studen…

Hbase练习1

第一大题&#xff1a;namespace的shell操作 1、创建一个命名空间myns,同时设置属性author为自己&#xff0c;time为2020-05-11 create_namespace myns,{author > 自己,time > 2020-05-11}2、为myns添加一个属性company为qianfeng alter_namespace myns,{METHOD > s…

HUAWEI+Eudemon1000E+防火墙+典型配置案例

当使用consol口登入Eudemon1000E 防火墙时&#xff0c;如果登入失败退出可能会被锁定&#xff0c;提示&#xff1a;User interface con0 is locked! 锁定的时间默认是10分钟&#xff0c;可以通过对con0 配置修改锁定值。 设置串口console0上所有用户登录鉴权次数为5。锁定时间…

openGaussDB 初体验(下)

作者 | JiekeXu 来源 | JiekeXu之路&#xff08;ID: JiekeXu_IT&#xff09; 转载请联系授权 | (微信ID&#xff1a;xxq1426321293) 大家好&#xff0c;我是 JiekeXu,很高兴又和大家见面了&#xff0c;今天分享下 openGaussDB 初体验(下)。本文首发于微信公众号【JiekeXu之路】…

OSPF实验

一&#xff1a;实验要求 一&#xff1a;R1-3为区域0, R3到R4为区域1&#xff0c;R1-R4都有环回&#xff0c;其中R3的环回也在区域0 二&#xff1a;R1-R3 R3为DR设备&#xff0c;没有BDR 三&#xff1a;R4环回地址已固定4.4.4.4/24&#xff0c;其他所有网段使用192.168.1.0/24进…

华为HCIP RS题库221 111-120题

Q111 中的哪些路由满足下面的 ACL 条件&#xff1f;&#xff08;多选&#xff09; acl number 2001 Rule 0 permit source 10.1.1.0 0.0.254.255 A.10.1.1.1/32 B.10.1.2.1/32 C.10.1.3.1/32 D.10.1.4.1/32 Answer: AC 解析&#xff1a; 通配符掩码转化为二进制是11111110&…

nrm : 无法加载文件 C:\Users\HUAWEI\AppData\Roaming\npm\nrm.ps1,因为在此系统上禁止运行脚本

管理员权限打开终端运行 Set-ExecutionPolicy -Scope CurrentUser RemoteSigned即可

华为无线AC添加SSID步骤

首先&#xff0c;规划好相关网段信息后&#xff0c;就可以在AC上创建对应的SSID了。 本次以下面两个网段信息来举例&#xff1a; vlan 10&#xff08;worker&#xff09;&#xff1a;10.10.10.0/24 vlan 20&#xff08;guest&#xff09;&#xff1a;20.20.20.0/24 1、进入…