关于c#:为VisualStudio新建文件创建版权日期模板

1.为什么创立模板文件?在没有创立模板文件时,VisualStudio默认创立的文件是这样的。 能够看到,没有任何正文、版权信息和创立日期等。而在创立模板文件后,VisualStudio默认创立的文件是这样的。 这在后续批改代码文件或多人合作项目时有莫大的益处。上面就来说说怎么创立并批改默认模板。 2.新建模板文件留神:我所用环境为Visual Studio 2022,以下模板适宜C#10新语法,旧语法及旧版本以相似办法批改。2.1在空白目录创立以下三个文件: Class.cs // ----------------------------------------------------------------// Copyright ©$year$ ZhaiFanhua All Rights Reserved.// FileName:$safeitemname$// Guid:$guid1$// Author:$username$// Email:me@zhaifanhua.com// CreateTime:$time$// ----------------------------------------------------------------namespace $rootnamespace$;/// <summary>/// $safeitemrootname$/// </summary>public class $safeitemrootname${}Controller.cs 这里仅为ApiController // ----------------------------------------------------------------// Copyright ©$year$ ZhaiFanhua All Rights Reserved.// FileName:$safeitemname$// Guid:$guid1$// Author:$username$// Email:me@zhaifanhua.com// CreateTime:$time$// ----------------------------------------------------------------using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Mvc;namespace $rootnamespace$;/// <summary>/// $safeitemrootname$/// </summary>[Route("api/[controller]")][ApiController]public class $safeitemname$ : ControllerBase{}Interface.cs // ----------------------------------------------------------------// Copyright ©$year$ ZhaiFanhua All Rights Reserved.// FileName:$safeitemname$// Guid:$guid1$// Author:$username$// Email:me@zhaifanhua.com// CreateTime:$time$// ----------------------------------------------------------------namespace $rootnamespace$;/// <summary>/// $safeitemrootname$/// </summary>public interface $safeitemrootname${}2.2找到模板目录并复制例如装置的Visual Studio 2022在C盘,则对应的模板目录在: ...

April 16, 2022 · 1 min · jiezi

关于c:C语言学习笔记实现简单的猜数字小游戏

C语言实现简略的猜数字小游戏在咱们学习完C语言根本数据类型以及运算、分支构造、循环构造、函数的基础知识当前,能够尝试写一点乏味的小游戏,实现非常简单,大家能够一起入手尝试起来哦~游戏实现C语言实现的猜数字游戏非常简略,次要由以下三个模块组成: 菜单模块游戏模块主函数模块须要援用的头文件本程序调用rand函数,心愿大家看到不要慌乱,应用办法简略,将在主函数模块提及,大家模拟应用即可,除此之外该程序无任何难点,大家肯定要本人尝试写一下哦~ 菜单模块void menu(){ //打印游戏菜单 printf("###################################\n"); printf("###################################\n"); printf("##########输出1:游戏开始##########\n"); printf("##########输出0:游戏完结##########\n"); printf("###################################\n"); printf("###################################\n");}游戏菜单实现非常简单,次要应用输入函数打印一个动态繁难的菜单,置信大家写过第一个C语言程序HelloWorld的话也肯定会写这个。 菜单模块打印一个文本提醒,无返回值,所以函数类型为空类型(void),也不须要任何的函数参数。 游戏模块void game(){ //定义并初始化guess 用来寄存玩家猜想的数字 int guess = 0; //调用rand函数生成随机数,而后管制生成一个1-100之间的随机数m int m = rand()%100+1; //开始猜数字游戏 直到猜对数字完结本轮游戏 while (1) { printf("请输出你猜的数字\n"); //输出玩家猜的数字 scanf("%d", &guess); //玩家所猜数字比随机生成数小 if (guess < m) printf("猜小了\n"); //玩家猜对数字打印猜对并完结本轮游戏 else if (guess == m) { printf("猜对了\n"); break; } ////玩家所猜数字比随机生成数大 else printf("猜大了\n"); }}game函数无返回值,所以函数类型为空。 实现思路:定义guess变量寄存玩家所猜数字,而后调用rand函数生成一个随机数m,应用while循环进行判断guess和m大小,玩家依据游戏提醒一直输出数字,直到猜对数字完结本轮游戏 主函数模块int main(){ int input = 0; //在调用 rand 之前,必须应用 srand 函数为伪随机数生成器进行种子化(语言规定的,这里不了解能够本人去百度深刻理解rand函数) //生成随机数时调用了time函数 依据本地工夫生成一个随机数(精确的说应该是工夫戳,这里不了解能够本人去深刻百度理解time函数) //srand函数的类型是unsign int,而time返回值类型为int,所以要进行强制类型转换 srand((unsigned int)time(NULL)); do { //调用游戏菜单函数 menu(); //用户抉择开始或完结 printf("请输出一个数字抉择是否开始->:\n"); scanf("%d", &input); if (input == 1) //调用游戏函数 game(); else if (input == 0) printf("游戏完结\n"); else printf("非法输出\n"); } while (input); return 0;}主函数模块依据本地工夫生成随机数,应用do-while循环依据用户输出进行相应的操作提醒。须要援用的头文件#include<stdio.h>#include<stdlib.h>#include<time.h>rand函数须要援用第二个头文件,time函数须要援用第三个头文件。

April 15, 2022 · 1 min · jiezi

关于c#:5-堪比JMeter的Net压测工具-Crank-实战篇-接口以及场景压测

1. 前言通过之前的学习,咱们曾经把握了crank的配置以及对应http基准工具bombardier、wrk、wrk2的用法,本篇文章介绍一下如何将其用于实战,在理论的我的项目中咱们如何应用crank来实现压测工作。 2. 我的项目背景目前有一个我的项目,咱们心愿通过压测来理解其QPS、吞吐量、以及临界值,并通过压测来剖析出其瓶颈在哪里?并通过解决瓶颈问题以进步QPS、吞吐量等指标 先看下咱们手头把握了什么: 我的项目信息 我的项目中的接口根本都须要登录通过与开发沟通能够失去每个页面的接口信息以及参数信息环境信息 压测我的项目有独自的环境部署利用、Redis、数据库等根底配置此处我的项目名咱们暂定为ProjectA。 3. 如何发展首先咱们先回顾一下Agent、Controller的职责以及特点 Controller 做任务调度以及后果输入无需独自服务器,能够在本机执行发送命令,须要与Agent相通Agent 工作的理论执行者单任务执行,不能做到接管到多个工作并同时执行,先收到哪个工作,哪个工作会先执行雷同一个工作能够被多个Agent同时执行,最终指标后果会主动累加,能够通过晋升Agent来模仿更高的并发能力3.1. 思路先做好独自接口的压测,大略把握每个接口的指标状况同时压测多个接口,实现对场景的压测通过压测察看应用服务器、根底服务器的CPU、带宽、内存等指标,察看Redis、数据库、音讯队列等根底组件状况,依据压测的返回后果失去每个场景的根底指标通过剖析发现瓶颈、而后再思考如何冲破瓶颈,晋升QPS、吞吐量等3.2. 如何做?理解到单个Agent同时执行多个工作会进行排队,无奈做到多任务同时执行,那么咱们能够通过多个Agent同时执行不同的工作来模仿用户拜访页面。 3.2.1. 构建Agent之前与开发沟通失去每个页面最多可发送的申请是6个,那么咱们筹备6个Agent,别离为Agent1、Agent2、Agent3、Agent4、Agent5、Agent6 咱们这里应用Docker来启动Agent、Agent对内凋谢端口: 5010、对外端口随机,镜像应用咱们自建的: doddgu/crankagent:net5.0 并新建load.yml为之后压测应用: profiles: crankAgent1: jobs: load: endpoints: - http://localhost:5010 crankAgent2: jobs: load: endpoints: - http://localhost:5011 crankAgent3: jobs: load: endpoints: - http://localhost:5012 crankAgent4: jobs: load: endpoints: - http://localhost:5013 crankAgent5: jobs: load: endpoints: - http://localhost:5014 crankAgent6: jobs: load: endpoints: - http://localhost:5015load.yml 中记录了所有的压测机信息,其信息个别不做批改,咱们能够作为公共的配置来应用无需每个我的项目都独自保护一份新的3.2.2. 构建压测脚本在这里咱们抉择wrk2作为本次基准测试工具,抉择wrk2的起因是: 反对随机参数可反对设置恒定的吞吐量负载具备wrk的所有性能此时咱们针对ProjectA我的项目新建配置:project.profiles.yml,作为本次压测的环境配置来应用,其配置如下 imports: - https://raw.githubusercontent.com/doddgu/crank/sample/samples/wrk2/common/load.profiles.yml # 这边倡议应用近程load.profiles.yml地址。(如果输出的是本地门路、则需输出与以后命令所在门路的相对路径)profiles: local: # 本地环境 variables: serverAddress: localhost # 应用服务域 serverPort: 80 # 应用服务端口 connections: 256 # 每个线程解决时放弃关上的 HTTP 连贯总数 N = 连接数/线程数 threads: 32 # 线程数 warmup: 3 # 预热工夫: 3s duration: 180 # 测试时长: 3分钟 rate: # 吞吐量参数(每秒总申请数)project.profiles.yml中记录了指定我的项目的各环境的配置,我的项目本人独立保护即可除了我的项目信息、压测机配置之外,咱们还须要有中央保护咱们压测的接口信息,这边我的做法是将api独立拆分进去,每个yml只配置一个接口的压测信息,至于为什么不放到一块,而要独自拆离开呢? ...

April 15, 2022 · 3 min · jiezi

关于c:跟着Redis学编程之字符串转长整数

前言作为C语言根底,在面试的时候,常常会被要求实现数值到字符串、或者字符串到数值的转换函数。尽管难度不大,然而很容易在一些细节上呈现纰漏。刚好最近在深度剖析Redis7.0源代码。空闲之余,顺带把这部分代码摘录进去,进行剖析、注解。作为一个学习记录的同时也不便后来者疾速理解Redis外部是如何实现的。日后面试兴许能用的上。 Redis实现形式代码片段正文int string2ll(const char *s, size_t slen, long long *value) { const char *p = s; //指向s开始地位 size_t plen = 0; // int negative = 0; //正数 unsigned long long v; /* 如果传递示意字符串长度参数为0,则无需转换,间接返回 0 */ if (plen == slen) return 0; /* 非凡状况, 只有一个字符,并且是0字母 */ if (slen == 1 && p[0] == '0') { if (value != NULL) *value = 0; return 1; } /* 字符串可能是示意带符号的整数,那么须要先解决符号。 */ /* 解决正数:仅仅是设置负号,而后就相似负数的解决形式进行解决 . 结束后转换成正数 */ if (p[0] == '-') { negative = 1; p++; plen++; /* 只有负号,即字符串是这样:"-", 这种字符串间接,异样退出 */ if (plen == slen) return 0; } /* 第一个字符必须是1-9,否则字符串应该是0 */ if (p[0] >= '1' && p[0] <= '9') { v = p[0]-'0';//转成整数 p++; plen++; } else { return 0; } /* 剖析剩下的所有字符,并且每一个步都查看是否溢出。 如果遇到非字符,则循环退出:p[0] <'0' || p[0] > '9' 字符串剖析结束,则循环退出:plen >= slen */ while (plen < slen && p[0] >= '0' && p[0] <= '9') { if (v > (ULLONG_MAX / 10)) /* 先判断溢出,在累加。如果计算后再判断,这时候曾经溢出掉了. */ return 0; v *= 10; if (v > (ULLONG_MAX - (p[0]-'0'))) /* 情理同上,这里咱们能够借鉴:判断溢出的形式. */ return 0; v += p[0]-'0'; p++; plen++; } /* 还有字符没有解决完,到这里其实就是下面的while循环条件, p[0]不是0-9的数字 */ if (plen < slen) return 0; /* 转换为正数,并且要查看溢出 */ /* 整个转换都是应用unsigned long long 作为长期值,最初保留的后果是有符号的,须要转换为 * long long ,这样在赋值和正数转变时候须要做溢出判断。 */ if (negative) { if (v > ((unsigned long long)(-(LLONG_MIN+1))+1)) /* 溢出检查 */ return 0; if (value != NULL) *value = -v; } else { if (v > LLONG_MAX) /* 溢出检查. */ return 0; if (value != NULL) *value = v; } return 1;}代码逻辑剖析小结string2ll整体思路是:解决符号,而后一一字符进行转换,从第一个字符开始转换,每一次转换都判断本次转换后的后果是否溢出,如果溢出就返回转换失败,否则就转换胜利,持续遍历下一个字符。 ...

April 15, 2022 · 2 min · jiezi

关于c:C语言程序设计谭浩强第五版-第4章-选择结构程序设计-习题解析与答案

你也能够上程序咖(https://meta.chengxuka.com),关上大学幕题板块,岂但有答案,解说,还能够在线答题。 题目1:什么是算术运算?什么是关系运算?什么是逻辑运算? 算术运算: 算术运算即“四则运算”,是加法、减法、乘法、除法、乘方、开方等几种运算的统称。 其中加减为一级运算,乘除为二级运算,乘方、开方为三级运算。在一道算式中,如果有多级运算存在,则应先进行高级运算,再进行低一级的运算。 C语言中的算熟运算符包含:+、-、*、/、++、--、% 等品种。 如果只存在同级运算;则从左至右的程序进行;如果算式中有括号,则应先算括号里边,再按上述规定进行计算。 示例:$ (1 + 1)^{2} * 4+5 * 3$ 解析: 先进行括号内运算1+1,而后进行乘方运算失去后果4.接下来与4相乘,失去后果16因为乘法优先级大于加法,因而先进行5*3,失去后果15最终相加失去后果31后果:31 关系运算: 关系的根本运算有两类:一类是传统的汇合运算(并、差、交等),另一类是专门的关系运算(抉择、投影、连贯、除法、外连贯等),而在C语言中,关系运算通常被认为是比拟运算,将两个数值进行比拟,判断比拟后果是否合乎给定的条件。 常见的关系运算符包含:<、<=、>、>=、==、!= 等品种。 其中,前4种关系运算符(<、<=、>、>= )的优先级别雷同,后2种(==、!=)也雷同。而前4种高于后2种。 例如, > 优先于 == 。而 > 与 < 优先级雷同。并且,关系运算符的优先级低于算术运算符,关系运算符的优先级高于赋值运算符(=)。 逻辑运算: 在逻辑代数中,有与、或、非三种根本逻辑运算。示意逻辑运算的办法有多种,如语句形容、逻辑代数式、真值表、卡诺图等。而在C语言中,逻辑运算通常用于应用逻辑运算符将关系表达式或其它逻辑量连接起来组成逻辑表达式用来测试虚实值。 常见的逻辑运算符包含:&&、||、! 等品种 &&: 与是双目运算符,要求有两个运算对象,示意两个运算对象都成立,则后果为真,否则后果为假。 例如:(a<b) && (x>y),示意(a<b)和(x>y)同时成立则为真。 ||:是双目运算符,要求有两个运算对象,示意两个运算对象只有任意一个成立,则后果为真,否则后果为假。 例如:(a<b) && (x>y),示意(a<b)和(x>y)两个对象中任意一个成立则后果为真。 !是单目运算符,只要求有一个运算对象,示意取运算对象反义,运算对象为真则后果为假,运算对象后果为假则后果为真。 例如:!(a>b),示意(a>b)成立时后果为假,不成立时后果为真。 若在一个逻辑表达式中蕴含多个逻辑运算符,则优先秩序为: ! > && > ||。当然若一个逻辑表达式中蕴含括号括起来的子逻辑,则优先括号内的子逻辑判断。 示例: (1>2)||(2>3)&&(4>3) 后果为0!(1>2)||(2>3)&&(4>3)后果为1 注:&&优先级大于||,((2>3)&&(4>3))无奈同时成立,则后果为假,而后与(1>2)后果进行逻辑或运算,两者都为假因而第一次后果为假。 而第二次!优先级最高,先对(1>2)的后果取逻辑非,失去后果为真,因而后果为真。 题目2:C语言中如何示意“真”和“假”?零碎如何判断一个量的“真”和“假”? 答案: 对于逻辑表达式,若其值为“真",则以1示意,若其值为“假”,则以0示意。然而在判断一个逻辑量的值时,零碎会以0作为“假”,以非0作为“真”。例如3 && 5的值为“真”,零碎给出3 && 5的值为1。 题目3:写出上面各逻辑表达式的值。设a=3,b=4,c=5。 (1) a+b>c && b==c (2) al|b十c && b-c (3) !(a>b) && !c || 1 (4) !(x=a) && (y=b) && 0 (5) !(a+b)+c-1 && b十c/2 ...

April 15, 2022 · 7 min · jiezi

关于c:C语言指针保存输入的9个数中所有的奇数并输出

1、题目编写一个函数,利用指针实现保留输出的9个数中所有的奇数并输入,若没有奇数则输入NO。 要求: 1、不在子函数中输入。2、不能批改指定的子函数void GetOdd(int a[], int b, int m)示例: 输出:1 4 7 2 5 8 3 6 9输入:1 7 5 3 9 输出:2 2 2 2 2 2 2 2 2输入:NO 2、残缺代码#include<stdio.h>#define N 10int a[N];int res[N];void GetOdd(int a[], int* b, int* m){ *b = 0; for (int i = i = 0; i < 9; ++i) { if (a[i] % 2 == 1) { m[*b] = a[i]; *b = *b + 1; } }}int main(){ int cnt; for (int i = 0; i < 9; ++i) scanf_s("%d", &a[i]); GetOdd(a, &cnt, res); if (cnt == 0) printf("NO"); else for (int i = 0; i < cnt; ++i) printf("%d ", res[i]); return 0;}3、截图 ...

April 14, 2022 · 1 min · jiezi

关于c:C语言生成10个随机种子为824的学生成绩用指针法统计低于均分的情况

1、题目在[0,100]范畴生成10个随机种子为824的学生问题。请你设计子函数实现指针法统计低于均分的状况。 要求: 1、应用子函数:void GetScore(int p, float avg, int* num) //p是指向原问题数组的指针,avg存储均分,num指针存储低于均分人数。2、应用指针法解决数据在子函数中实现统计,不容许在子函数中输入3、主函数中输入,输入分三行: 第一行输入原始问题第二行输入均分及低于均分总个数第三行输入低于均分的问题,保留一位小数示例: 输入:2 78 1 8 43 57 52 54 9 69           avg=37.3 num=4           2 1 8 92、残缺代码#include<stdio.h>#include<stdlib.h>void GetScore(int* b, float* avg, int* num){ int i; *num = 0; *avg = b[0]; for (i = 0; i < 10; i++) { *avg += b[i]; } *avg = *avg / 10; for (i = 0; i < 10; i++) { if (*avg >= b[i]) *num += 1; }}void main(){ int a[10], num; float avg; //种子824 srand(824); for (int i = 0; i < 10; i++) { // 0-100随机数 a[i] = rand() % 101; printf("%d ", a[i]); } GetScore(a, &avg, &num); printf("\navg=%.1f num=%d\n", avg, num); for (int i = 0; i < 10; i++) { if (a[i] < avg) printf("%d ", a[i]); }}3、截图 ...

April 14, 2022 · 1 min · jiezi

关于c:C语言学习笔记分支结构程序之if语句

分支构造程序之if语句家喻户晓,C语言是一种结构化程序设计语言。程序并不会总是执行同样的解决,例如程序会通过条件判断的后果选择性执行某种解决。接下来咱们一起学习依据条件扭转程序运行流程。if 语句1#include<stdio.h>int main(){ int n; //输入一个整数 scanf("%d",&n); //条件判断 0为假 非0为真 if(n%5) printf("输出的数字不能被5整除\n"); return 0;}if(表达式)语句会判断表达式的值,如果表达式的值非0,则会执行相应的语句;()中的表达式称为管制表达式,满足此表达式,后续语句则会则行,否则不执行。if 语句2#include<stdio.h>int main(){ int n; //输出一个整数 scanf("%d",&n); //判断奇偶 if(n%2==0) printf("这个数是偶数\n"); else printf("这个数是奇数\n"); return 0;}if(表达式) 语句1,else(表达式)语句2 else是否则的意思,当表达式1的值不为0的时候执行语句1,否则执行语句2; '==' 为相等运算符,属于双目运算符,对左右两侧的操作数进行比拟;与之对应的运算符是不等运算符 ‘!=’ if 语句3#include<stdio.h>int main(){ int m,n; //输出两个整数 scanf("%d %d",&m,&n); //判断大小 if(a>b) printf("a>b\n"); else if(a<b) printf("a<b\n"); else printf("a=b\n"); return 0;}if(表达式1)语句1,else if(表达式2)语句2,else(表达式3) 语句3; 表达式1的值不为0时,执行语句1,否则判断表达式2的值,若不为0则执行语句2,若为0则执行语句3; ‘>、<’ 为关系运算符,为双目运算符,对两侧操作数进行比拟。其余的关系运算符还有 ‘<=、>=’ 条件运算符语句#include<stdio.h>int main(){ int m,n,max; //输出两个整数 scanf("%d %d",&m,&n); //判断大小 max = m>n?m:n; printf("%d",max); return 0;}条件运算符属于三目运算符,须要三个操作数;a?b:c 若表达式a的值不为0,则后果为b,否则后果为c复合语句#include<stdio.h>int main(){ int m,n,max,min; printf("%d %d",m,n); if(m>n) { max = m; min = n; } else { max = n; min = m; } printf("最大值是%d,最小值是%d",max,min); return 0;}下面程序中的if语句在大括号内的语句称为复合语句或程序块;用{}括起来的复合语句也会被看做繁多的语句。逻辑运算符语句#include<stdio.h>int main(){ int month; scanf("%d",&month); if(month >= 3 && month <= 5) printf("%d是秋季\n"); else if(month >= 6 && month <= 8) printf("%d是冬季\n"); else if(month >= 9 && month <= 11) printf("%d是秋季\n"); else if(month == 1 || month == 2 || month ==12) printf("%d是夏季\n"); else printf("%d月不存在\n"); return 0;}上述语句应用的“&&”和“||”称为逻辑运算符; ...

April 14, 2022 · 1 min · jiezi

关于c:C语言程序设计谭浩强第五版-第3章-最简单的的C程序设计顺序程序设计-习题解析与答案

你也能够上程序咖(https://meta.chengxuka.com),关上大学幕题板块,岂但有答案,解说,还能够在线答题。 题目1:如果我国国民生产总值的年增长率为7%,计算10年后我国国民生产总值与当初相比增长多少百分比。计算公式为: $$p=(1+r)^n$$ r 为年增长率,n 为年数,p为与当初相比的倍数。 解:从主教材附录D(库函数)能够查到:能够用pow函数求$y^x$的值,调用pow函数的具体模式是pow(x,y)。在应用pow函数时须要在程序的结尾用# include指令将<math.h>头文件蕴含到本程序模块中。能够用上面的程序求出10年后国民生产总值是当初的多少倍。 答案代码: #include <stdio.h>#include <math.h>int main(){ float p, r, n; r = 0.07; n = 10; p = pow(1 + r, n); printf("p= %f\n", p); return 0;}运行后果: 即10年后国民生产总值是当初的1.967151倍。 题目2:贷款利息的计算。有1000元,想存5年,可按以下5种方法存: (1) 一次存5年期。 (2) 先存2年期,到期后将本息再存3年期。 (3) 先存3年期,到期后将本息再存2年期。 (4) 存1年期,到期后将本息再存1年期,间断存5次。 (5) 存活期存款。定期利息每-季度结算一次。 2017年的银行存款利息如下: 1年期定期存款利息为1.5%; 2年期定期存款利息为2.1%; 3年期定期存款利息为2.75%; 5年期定期存款利息为3%; 活期存款利息为0.35%(活期存款每一季度结算一次利息)。 如果 r 为年利率,n 为贷款年数,则计算本息和的公式如下: 1年期本息和: $P=1000* (1+r)$ ...

April 14, 2022 · 4 min · jiezi

关于c:C语言学习笔记数据类型与运算

C语言学习笔记_数据类型与运算我认为C语言是所有编程语言的根底,C生万物。我本科是软件工程,大一时早早就接触过C语言,但那时学习不够深刻,学习办法也有很大问题,导致编程根底很差。现如今考研失败,决定开始从新零碎学习编程,从C语言根底开始,笔记也只波及C语言根底局部,不会波及太深,因为我的学习方向是Java,接下来就是我的C语言学习笔记,绝不写半句废话,欢送各位一起学习交换以及批评指正~运算#include<stdio.h>int main(){ int x,y; scanf("%d %d",&x,&y); //加减运算符 printf("%d",x+y); printf("%d",x-y); //乘除运算符 //整数的除法运算只取商的整数局部,主动舍弃小数点局部 printf("%d",x*y); printf("%d",x/y); //取余运算符 //取余运算的操作数只能是整数(负整数取余没有意义) printf("%d",x%y); return 0;}像+、-、*、/、%这样能够进行运算的符号称为运算符,参加运算的变量或常量称为操作数用printf函数输入"%"这个符号的化,格式化字符串中要写%%;因为%有转换阐明的性能,当不须要进行转换阐明,只想输入%的时候,就要写成%%取余运算符的利用:#include<stdio.h>int main(){ //利用取余运算符求整数最初一位 int x; scanf("%d",&x); printf("x最初一位是:%d\n",x%10); return 0;}除法和取余运算的各种后果:除法运算和取余运算的后果都是依赖于编译器的两个操作数都是负数时:任何编译器商和余数都是负数两个操作数至多有一个为正数时:后果取决于编译器运算练习: #include<stdio.h>int main(){ //读取两个整数,输入前者是后者的百分之几 int x,y; scanf("%d %d",&x,&y); //%.0f这种用法前面会讲到 //(double)是类型转换 前面也会讲到 printf("x是y的%.0f%%",((double)x/y)*100); return 0;}单目运算符和三目运算符: 以上介绍的都是双目运算符,须要两个操作数,而单目运算符只须要一个操作数,三目操作数须要三个操作数。 常见的单目运算符有+、-、!、~ 三目运算符会在前面的条件运算中介绍 #include<stdio.h>int main(){ int x = 10; //+运算符其实没有什么理论运算 只是为了对应-运算符而设置的 printf("%d",+x); //对符号进行取反操作 printf("%d",-x); //非运算符 前面会介绍 printf("%d",!x); //位取反运算符 前面会介绍 printf("%d",~x); return 0;}C语言中“=”为赋值运算符,而“==”才为相等运算符程序中的一个语句都能够看做一个表达式,表达式必须要以;结尾,称为表达式语数据类型#include<stdio.h>int main(){ //int为整型变量,将9.99赋给x时,小数局部将会被抛弃,此时x=9 int x = 9.99; //double 为浮点型变量 double y = 9.99; //后果为4 printf("%d\n",x/2); //后果为4.995000 printf("%lf\n",y/2); return 0;}printf函数输入int型值的时候,转换阐明应用%dprintf函数输入double型值的时候,转换阐明应用%lf,%lf默认显示小数点后六位数字int 类型只能用来存储整数,即便把实数赋值给它,也只能保留整数局部double类型能够用来存储蕴含小数的实数数据类型之间的运算:进行整数/整数运算时,商的小数局部被舍弃,浮点数之间的运算则不会舍弃小数局部“int/int”与“double/double”这样两个雷同类型的操作数之间的运算,所得后果数据类型放弃不变“double/int”或“int/double”两个不同类型操作数之间的运算,int类型的操作数会进行隐式类型转换,主动向上转换为double型,运算演变成double类型之间的运算,所得后果也为double类型。这样的规定对于+、*等其余运算也实用强制类型转换:#include<stdio.h>int main(){ int a,b; scanf("%d %d",&a,&b); //强制类型转换,格局为:(类型名)a,把a的值转换为指定数据类型对应的值 printf("%lf",(double)(a+b)/2); return 0;}转换阐明书写格局:#include<stdio.h>int main(){ int a,b; int sum; double ave; scanf("%d %d",&a,&b); sum = a+b; ave = sum/2; printf("他们的总和为%05d\n",sum); printf("他们的平均值为%05.4f\n",ave); return 0;}%05d示意显示至多5位的十进制整数,0标记代表如果数值后面有空位用0补齐,若没有0标记则用空格补齐%05.4f示意显示至多5位的浮点数,然而小数点后只显示4位

April 13, 2022 · 1 min · jiezi

关于c:C语言用指针保存小于或等于lim的所有素数

1、题目编写一个函数,用指针保留小于或等于 lim 的所有素数 要求: 1、不要在子函数中输入2、不要批改子函数。应用子函数void GetPrime(int lim,intnum,intx)示例: 输出:20输入:num=82,3,5,7,11,13,17,192、残缺代码2.1 C语言版本#include <stdio.h>//宏定义布尔类型#define BOOL int#define TRUE 1#define FALSE 0#define N 100010BOOL st[N];void GetPrime(int lim, int* num, int* x){ for (int i = 2; i <= lim; ++i) { if (!st[i]) { x[*num] = i; (*num)++; } for (int j = 0; j < *num && i * x[j] <= lim; ++j) { st[i * x[j]] = TRUE; if (i % x[j] == 0) break; } }}void main(){ int x; int cnt = 0; int result[N]; BOOL flag = FALSE; scanf_s("%d", &x); GetPrime(x, &cnt, result); printf("num=%d\n", cnt); for (int i = 0; i < cnt; ++i) { if (flag) printf(","); else flag = TRUE; printf("%d", result[i]); } return 0;}2.2 C++版本#include <iostream>using namespace std;const int N = 1e5 + 10;bool st[N];void GetPrime(int lim, int *num, int *x){ for(int i = 2; i <= lim; ++i) { if(!st[i]) { x[*num] = i; (*num) ++; } for(int j = 0; j < *num && i * x[j] <= lim; ++j) { st[i * x[j]] = true; if(i % x[j] == 0) break; } }}int main(){ int x; int cnt = 0; int result[N]; bool flag = false; cin >> x; GetPrime(x, &cnt, result); printf("num=%d\n", cnt); for(int i = 0; i < cnt; ++i) { if(flag) printf(","); else flag = true; printf("%d", result[i]); } return 0;}3、截图 ...

April 13, 2022 · 2 min · jiezi

关于c#:AgileConfig-160-发布-支持服务注册与发现

大家好,良久没有输入博文了,一是因为比较忙,另外一个起因是最近次要的精力是在给 AgileConfig 增加一个新的性能:服务注册与发现。 先说说为什么会增加这个性能。我本人的我的项目是用 Consul 来做为服务注册发现组件的。自从我上线了 AgileConfig 做为配置核心后,我就很少去 Consul 察看服务的在线状态了,因为 AgileConfig 客户端列表曾经在肯定水平上能代表服务的状态了。服务注册发现与配置核心其实实质上都是解决了一类问题,那就是配置的动态化,所以大家会看到业界驰名的组件很多都是同时实现这2个性能的,如 Consul,Nacos 等。所以我想罗唆把这个性能给加上吧,这样能够省去部署一个组件。 当然也有同学说我不务正业,不去好好搞配置核心去搞什么服务注册发现。然而我还是做了。。。不过大家释怀 AgileConfig 的主业还是在配置核心上,服务注册发现只是附赠的小菜,能够用也能够不必,决定权齐全在你。在实现上我也是对两个性能是齐全解耦的。也就是说这2个性能都是互不影响独立运行的。惟一有交加的一个中央是,如果配置核心的客户端的 websocket 通道建设胜利的时候,服务的心跳会借用这个通道。 ✨✨✨Github地址:https://github.com/dotnetcore/AgileConfig 开源不易,欢送star✨✨✨ ✨✨✨Gitee地址:https://gitee.com/kklldog/AgileConfig ✨✨✨ 什么是服务注册与发现首先先让咱们回顾下服务注册发现的概念。 在施行微服务之后,咱们的调用都变成了服务间的调用。服务间调用须要晓得IP、端口等信息。再没有微服务之前,咱们的调用信息个别都是写死在调用方的配置文件里(当然这话不相对,有些公司会把这些信息写到数据库等公共的中央,以不便保护)。又因为业务的简单,每个服务可能依赖N个其余服务,如果某个服务的IP,端口等信息产生变更,那么所有依赖该服务的服务的配置文件都要去批改,这样显然太麻烦了。有些服务为了负载是有个多个实例的,而且可能是随时会调整实例的数量。如果每次调整实例数量都要去批改其余服务的配置并重启那太麻烦了。为了解决这个问题,业界就有了服务注册发现组件。假如咱们有服务A须要调用服务B,并且有服务注册发现组件R。整个大抵流程将变成大略3部: 服务B启动向服务R注册本人的信息服务A从服务R拉取服务B的信息服务A调用服务B有了服务注册发现组件之后,当批改A服务信息的时候再也不必去批改其余相干服务了。 参考我的另外一篇:.Net Core with 微服务 - Consul 注册核心 应用服务注册与发现应用服务注册与发现性能须要更新服务端与客户端至 1.6.0 及以上版本。 启动服务端服务端更新至 latest 镜像或 v-1.6.0 以上的镜像。 应用 docker 运行服务端实例: sudo docker run \--name agile_config \-e TZ=Asia/Shanghai \-e adminConsole=true \-e db:provider=sqlite \-e db:conn="Data Source=agile_config.db" \-p 5000:5000 \#-v /your_host_dir:/app/db \-d kklldog/agile_config:latest根本的应用没有太大的变动,只是在界面上增加了服务的相干治理界面,这里不在赘述。 相干教程: .Net Core & Agile Config配置核心 ...

April 13, 2022 · 2 min · jiezi

关于c:C语言程序设计谭浩强第五版-第2章-算法程序的灵魂-习题解析与答案

你也能够上程序咖(https://meta.chengxuka.com),关上大学幕题板块,岂但有答案,解说,还能够在线答题。 题目1:什么是算法?试从日常生活中找3个例子,形容它们的算法。 答: 算法:算法是计算机解决信息的实质,因为计算机程序实质上是一个算法来通知计算机确切的步骤来执行一个指定的工作。个别地,当算法在解决信息时,会从输出设施或数据的存储地址读取数据,把后果写入输出设备或某个存储地址供当前再调用。 算法是独立存在的一种解决问题的办法和思维。 对于算法而言,实现的语言并不重要,重要的是思维。 例如: 1、自驾去新疆游览 筹备好车,而后筹备游览路线等,开车登程,一路游山玩水。 2、网上买一部手机 首先选好网购平台(某宝,某东,某猫等),而后抉择想要的品牌和型号,下单,期待到货。 3、相亲 首先有七大姑八大姨等(如果没有能够抉择一些交友网站或其余媒婆),而后获取对方的联系方式和根本信息,登程达到目的地,相见,称心或不称心,决定了是否能够再约。 4、把大象放进冰箱 先关上冰箱门,而后将大象放进冰箱,关冰箱。 题目2:什么叫结构化的算法?为什么要提倡结构化的算法? 答: 结构化算法:由一些程序、抉择、循环等根本构造依照程序组成,流程的转移只存在于一个根本的范畴之内。 结构化算法便于编写,可读性高,批改和保护起来简略,能够缩小程序出错的机会,进步了程序的可靠性,保障了程序的品质,因而提倡结构化的算法。 题目3:试述3种根本构造的特点,请另外设计两种根本构造(要合乎根本构造的特点)。 解: 结构化程序设计办法次要由以下三种根本构造组成: 程序构造:程序构造是一种线性、有序的构造,它顺次执行各语句模块抉择构造:抉择构造是依据条件成立与否抉择程序执行的通路。循环构造:循环构造是反复执行一个或几个模块,直到满足某一条件地位 从新设计根本构造要满足以下几点: 只有一个入口只有一个进口构造内的每一部分都有机会执行到构造内不存在死循环 见图2.1和图2.2。 题目4:用传统流程图示意求解以下问题的算法。 (1)有两个瓶子A 和 B,别离盛放醋和酱油,要求将它们调换(即 A 瓶原来盛醋,现改盛酱油,B 瓶则相同)。 解:显然,如果只有两个瓶子,必定不能实现此工作,必须有一个空瓶C作为过渡,其步骤见图 2.3。 (2)顺次将10个数输人,要求输入其中最大的数。 解:流程图见图 2.4。 (3)有3个数a,b,c,要求按大小程序把它们输入。 解:流程图见图2.5。 (4)求1+2+3+……+ 100。 解:流程图见图 2.6。 (5)判断一个数n是否同时被3和5整除。 解:流程图见图 2.7(a)或图 2.7(b)。 (6)将100~200之间的素数输入。 解:流程图见图 2.8。 (7)求两个数m和n的最大公约数。 解:流程图见图 2.9。 (8)求方程式ax2+ bx+c=0的根。别离思考: ①有两个不等的实根; ②有两个相等的实根。 ...

April 13, 2022 · 2 min · jiezi

关于c++:C11包含守卫ifndef预处理指令pragma-once操作符Pragma

蕴含守卫#ifndef通常用于放在头文件中,避免文件内容被屡次蕴含在同一个文件中: //---------------------------test.h begin-----------------------------#ifndef TEST_H#define TEST_H void test(); #endif//---------------------------test.h end-------------------------------//---------------------------main.cpp begin------------------------------- #include "test.h" //第一次被#include时,因为没有定义TEST_H,test.h的内容会被蕴含进来#include "test.h" //第二次被#include时,因为在第一次#include时曾经通过#define定义了TEST_H,所以test.h的内容不会被反复蕴含 //---------------------------main.cpp end---------------------------------这种形式的长处是:1.能够对文件内容进行部分管制。2.如果多个文件具备雷同文件内容,但文件名不同,那么蕴含守卫也能够胜利的防止屡次蕴含的问题。 这种形式的毛病是:1.蕴含守卫的名字要保障唯一性,否则如果不同文件用了雷同的蕴含守卫,会导致只有一个文件被真正的蕴含进来。2.因为是方生在预编译期间,须要关上文件能力对蕴含守卫进行判断,所以编译的工夫会稍长。 预处理指令#pragma once定义在文件中,可批示编译器,这个文件只能被编译一次: #pragma once void test();这种形式的长处是:1.因为只被编译一次,所以编译速度较快。 这种形式的毛病是:1.不能对文件的部分内容进行管制,只能对文件整体管制。2..如果多个文件具备雷同文件内容,但文件名不同,那么尽管每个文件都只会被编译一次,但雷同的文件内容,会呈现反复定义的编译谬误: //---------------------------human1.h begin-----------------------------#pragma once struct Human{ std::string name; int age;}; struct Human xiaoming = {"xiaoming", 10}; //---------------------------human1.h end-------------------------------//---------------------------human2.h begin-----------------------------#pragma once struct Human{ std::string name; int age;}; struct Human xiaoming = {"xiaoming", 10}; //---------------------------human2.h end-------------------------------//---------------------------main.cpp-----------------------------#include <string>#include "human1.h"#include "human2.h" using namespace std; int main(){ return 0;} //---------------------------main.cpp end------------------------------- 因为human1.h和human2.h都定义了struct Human,所以编译时会报错:redefinition of 'struct Human'因为human1.h和human2.h都定义了xiaoming,所以编译时会报错:redefinition of 'Human xiaoming'操作符_PragmaC++11反对了操作符_Pragma,_Pragma("once")的成果与#pragma once雷同,不过因为_Pragma是操作符,所以能够利用于宏定义中: ...

April 11, 2022 · 1 min · jiezi

关于c:自学51单片机-矩阵按键实验

1、开发板原理图 2、程序2.1 行列式扫描法/**************************************************************************************试验名称:矩阵按键试验接线阐明: 试验景象:下载程序后,按下“矩阵按键”模块中S1-S16键,对应数码管最右边显示0-F注意事项: ***************************************************************************************/#include "reg52.h"typedef unsigned int u16; //对系统默认数据类型进行重定义typedef unsigned char u8;#define KEY_MATRIX_PORT P1 //应用宏定义矩阵按键管制口 #define SMG_A_DP_PORT P0 //应用宏定义数码管段码口u8 gsmg_code[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //共阴极数码管显示0~F的段码数据/******************************************************************************** 函 数 名 : delay_10us* 函数性能 : 延时函数,ten_us=1时,大概延时10us* 输 入 : ten_us* 输 出 : 无*******************************************************************************/void delay_10us(u16 ten_us){ while(ten_us--); }/******************************************************************************** 函 数 名 : key_matrix_ranks_scan* 函数性能 : 应用行列式扫描办法,检测矩阵按键是否按下,按下则返回对应键值* 输 入 : 无* 输 出 : key_value:1-16,对应S1-S16键, 0:按键未按下*******************************************************************************/u8 key_matrix_ranks_scan(void){ u8 key_value=0; KEY_MATRIX_PORT=0xf7;//给第一列赋值0,其余全为1 if(KEY_MATRIX_PORT!=0xf7)//判断第一列按键是否按下 { delay_10us(1000);//消抖 switch(KEY_MATRIX_PORT)//保留第一列按键按下后的键值 { case 0x77: key_value=1;break; case 0xb7: key_value=5;break; case 0xd7: key_value=9;break; case 0xe7: key_value=13;break; } } while(KEY_MATRIX_PORT!=0xf7);//期待按键松开 KEY_MATRIX_PORT=0xfb;//给第二列赋值0,其余全为1 if(KEY_MATRIX_PORT!=0xfb)//判断第二列按键是否按下 { delay_10us(1000);//消抖 switch(KEY_MATRIX_PORT)//保留第二列按键按下后的键值 { case 0x7b: key_value=2;break; case 0xbb: key_value=6;break; case 0xdb: key_value=10;break; case 0xeb: key_value=14;break; } } while(KEY_MATRIX_PORT!=0xfb);//期待按键松开 KEY_MATRIX_PORT=0xfd;//给第三列赋值0,其余全为1 if(KEY_MATRIX_PORT!=0xfd)//判断第三列按键是否按下 { delay_10us(1000);//消抖 switch(KEY_MATRIX_PORT)//保留第三列按键按下后的键值 { case 0x7d: key_value=3;break; case 0xbd: key_value=7;break; case 0xdd: key_value=11;break; case 0xed: key_value=15;break; } } while(KEY_MATRIX_PORT!=0xfd);//期待按键松开 KEY_MATRIX_PORT=0xfe;//给第四列赋值0,其余全为1 if(KEY_MATRIX_PORT!=0xfe)//判断第四列按键是否按下 { delay_10us(1000);//消抖 switch(KEY_MATRIX_PORT)//保留第四列按键按下后的键值 { case 0x7e: key_value=4;break; case 0xbe: key_value=8;break; case 0xde: key_value=12;break; case 0xee: key_value=16;break; } } while(KEY_MATRIX_PORT!=0xfe);//期待按键松开 return key_value; }/******************************************************************************** 函 数 名 : main* 函数性能 : 主函数* 输 入 : 无* 输 出 : 无*******************************************************************************/void main(){ u8 key=0; while(1) { key=key_matrix_ranks_scan(); if(key!=0) SMG_A_DP_PORT=gsmg_code[key-1];//失去的按键值减1换算成数组下标对应0-F段码 } }2.2 线翻转扫描法/**************************************************************************************试验名称:矩阵按键试验接线阐明: 试验景象:下载程序后,按下“矩阵按键”模块中S1-S16键,对应数码管最右边显示0-F注意事项: ***************************************************************************************/#include "reg52.h"typedef unsigned int u16; //对系统默认数据类型进行重定义typedef unsigned char u8;#define KEY_MATRIX_PORT P1 //应用宏定义矩阵按键管制口 #define SMG_A_DP_PORT P0 //应用宏定义数码管段码口u8 gsmg_code[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; //共阴极数码管显示0~F的段码数据/******************************************************************************** 函 数 名 : delay_10us* 函数性能 : 延时函数,ten_us=1时,大概延时10us* 输 入 : ten_us* 输 出 : 无*******************************************************************************/void delay_10us(u16 ten_us){ while(ten_us--); }/******************************************************************************** 函 数 名 : key_matrix_flip_scan* 函数性能 : 应用线翻转扫描办法,检测矩阵按键是否按下,按下则返回对应键值* 输 入 : 无* 输 出 : key_value:1-16,对应S1-S16键, 0:按键未按下*******************************************************************************/u8 key_matrix_flip_scan(void){ static u8 key_value=0; KEY_MATRIX_PORT=0x0f;//给所有行赋值0,列全为1 if(KEY_MATRIX_PORT!=0x0f)//判断按键是否按下 { delay_10us(1000);//消抖 if(KEY_MATRIX_PORT!=0x0f) { //测试列 KEY_MATRIX_PORT=0x0f; switch(KEY_MATRIX_PORT)//保留行为0,按键按下后的列值 { case 0x07: key_value=1;break; case 0x0b: key_value=2;break; case 0x0d: key_value=3;break; case 0x0e: key_value=4;break; } //测试行 KEY_MATRIX_PORT=0xf0; switch(KEY_MATRIX_PORT)//保留列为0,按键按下后的键值 { case 0x70: key_value=key_value;break; case 0xb0: key_value=key_value+4;break; case 0xd0: key_value=key_value+8;break; case 0xe0: key_value=key_value+12;break; } while(KEY_MATRIX_PORT!=0xf0);//期待按键松开 } } else key_value=0; return key_value; }/******************************************************************************** 函 数 名 : main* 函数性能 : 主函数* 输 入 : 无* 输 出 : 无*******************************************************************************/void main(){ u8 key=0; while(1) { key=key_matrix_flip_scan(); if(key!=0) SMG_A_DP_PORT=gsmg_code[key-1];//失去的按键值减1换算成数组下标对应0-F段码 } }3、后果 ...

April 11, 2022 · 2 min · jiezi

关于c:自学51单片机-独立按键实验

1、程序// 试验景象:下载程序后,按下“独立按键”模块中K1键,管制D1指示灯亮灭 // ,按下“独立按键”模块中K2键,管制D2指示灯亮灭// ,按下“独立按键”模块中K3键,管制D3指示灯亮灭 // ![请增加图片形容](https://img-blog.csdnimg.cn/1b8c0ea933df48e8b275340aaa7e8804.png),按下“独立按键”模块中K4键,管制D4指示灯亮灭 #include "reg52.h"typedef unsigned int uint16; //对系统默认数据类型进行重定义typedef unsigned char uint8;//定义独立按键管制脚sbit KEY1=P3^1; // K1sbit KEY2=P3^0; // K2sbit KEY3=P3^2; // K3sbit KEY4=P3^3; // K4//定义LED管制脚sbit LED1=P2^0; // D1sbit LED2=P2^1; // D2sbit LED3=P2^2; // D3sbit LED4=P2^3; // D4//应用宏定义独立按键按下的键值#define KEY1_PRESS 1#define KEY2_PRESS 2#define KEY3_PRESS 3#define KEY4_PRESS 4#define KEY_UNPRESS 0 /******************************************************************************** 函 数 名 : delay_10us* 函数性能 : 延时函数,ten_us=1时,大概延时10us* 输 入 : ten_us* 输 出 : 无*******************************************************************************/void delay_10us(uint16 ten_us) //消抖{ while(ten_us--); }/******************************************************************************** 函 数 名 : key_scan* 函数性能 : 检测独立按键是否按下,按下则返回对应键值* 输 入 : mode=0:单次扫描按键 mode=1:间断扫描按键* 输 出 : KEY1_PRESS:K1按下 KEY2_PRESS:K2按下 KEY3_PRESS:K3按下 KEY4_PRESS:K4按下 KEY_UNPRESS:未有按键按下*******************************************************************************/uint8 key_scan(uint8 mode){ static uint8 key=1; if(mode)key=1;//间断扫描按键 if(key==1&&(KEY1==0||KEY2==0||KEY3==0||KEY4==0))//任意按键按下 { delay_10us(1000);//消抖10ms key=0; if(KEY1==0) return KEY1_PRESS; else if(KEY2==0) return KEY2_PRESS; else if(KEY3==0) return KEY3_PRESS; else if(KEY4==0) return KEY4_PRESS; } else if(KEY1==1&&KEY2==1&&KEY3==1&&KEY4==1) //无按键按下 { key=1; } return KEY_UNPRESS; }/******************************************************************************** 函 数 名 : main* 函数性能 : 主函数* 输 入 : 无* 输 出 : 无*******************************************************************************/void main(){ uint8 key=0; while(1) { key=key_scan(0); if(key==KEY1_PRESS)//检测按键K1是否按下 LED1=!LED1;//LED1状态翻转 else if(key==KEY2_PRESS)//检测按键K2是否按下 LED2=!LED2;//LED1状态翻转 else if(key==KEY3_PRESS)//检测按键K3是否按下 LED3=!LED3;//LED1状态翻转 else if(key==KEY4_PRESS)//检测按键K4是否按下 LED4=!LED4;//LED1状态翻转 } }2、后果 ...

April 9, 2022 · 1 min · jiezi

关于c:我的编程之路

我的编程之路_第一天我认为C语言是所有编程语言的根底,C生万物。我本科是软件工程,大一时早早就接触过C语言,但那时学习不够深刻,学习办法也有很大问题,导致编程根底很差。现如今考研失败,决定开始从新零碎学习编程,从C语言根底开始,笔记也只波及C语言根底局部,不会波及太深,因为我的学习方向是Java,接下来就是我的C语言学习笔记,绝不写半句废话,欢送各位一起学习交换以及批评指正~ 笔记目录: [✔] 初识C语言[ ] 数据类型与运算[ ] 分支构造程序[ ] 循环控制程序[ ] 数组[ ] 函数[ ] 根本数据类型[ ] 程序编写[ ] 字符串[ ] 指针[ ] 字符串和指针[ ] 构造体[ ] 文件解决[ ] 结束语初识C语言什么是C语言?C语言是一门通用计算机编程语言,广泛应用于底层开发。C语言的设计指标是提供一种能以繁难的形式编译、解决低级存储器、产生大量的机器码以及不须要任何运行环境反对便能运行的编程语言。只管C语言提供了许多低级解决的攻能,但依然放弃着良好跨平台的个性,以一个规范规格写出的C语言程序可在许多电脑平台上进行编译,甚至蕴含一些嵌入式处理器(单片机或称MCU)以及超级电脑等作业平台。具备国际标准语法(初始语法ANSI C),C语言是一门面向过程的计算机编程语言,与C++,Java等面向对象的编程语言有所不同。第一个C语言程序//我的第一个C语言程序//头文件 其中stdio是standard I/O (规范输入输出)的缩写#include<stdio.h>//一个工程中有且仅有一个main函数,是程序运行的入口int main(){ //输入函数,调用输入函数,通过括号中的实参来传递想要的内容,printf函数的第一个实参%d(十进制)指定输入格局,第二个实参显示10的值 //函数调用是申请进行解决的申请,而调用函数的一些辅助批示则通过实参收回 printf("%d",10); return 0;}//前面的内容为正文内容,编译器不会进行辨认,对程序的运行并没有任何影响。编程者用简洁的的语言标注在程序旁,进步程序可读性。 原则上语句必须以分号结尾,{ }中的语句会被程序执行。 如以上代码所示,通过字符序列创立的程序称为源程序,用来保留源程序的文件为源文件,字符序列创立的程序须要转换为计算机可能了解的位序列,也就是0和1序列,一个源程序的执行要通过编辑、编译、链接、运行。 #include<stdio.h>int main(){ printf("1+1等于%d\n",1+1); return 0;}printf 函数中逗号之前局部称为格式化字符串,也是该函数的第一个参数 格式化字符串中的%d指定实参要以十进制数的模式显示,这就是转换阐明,若没有转换阐明则原样输入 \n 代表换行的符号,输入时看不到\和n,而是输入一个看不到的换行符 变量和申明 如果应用变量,必须通过申明明确其类型和名称 #include<stdio.h>int main(){ //申明一个整形变量x,并进行初始化 //变量在生成的时候会被放入不确定的值,因而在申明变量最好进行初始化 //int是变量的类型 x是变量名 int x = 10 ; printf("x的值为:%d",x); return 0;}初始化和赋值其实有一点点不同,初始化时在生成变量的时候放入数值,而赋值则是在已生成的变量中放入数值输出和显示 #include<stdio.h>int main(){ int x; //格式化输出函数scanf,从键盘读取输出信息 //与printf函数不同,应用scanf函数变量名必须加& scanf("%d",&x); printf("%d",x); return 0;}输入函数puts ...

April 9, 2022 · 1 min · jiezi

关于c++:Leetcode刷题股票问题系列总结

1. 交易股票的最佳时机给定一个数组 prices ,它的第 i 个元素 prices[i] 示意一支给定股票第 i 天的价格。你只能抉择 某一天 买入这只股票,并抉择在 将来的某一个不同的日子 卖出该股票。设计一个算法来计算你所能获取的最大利润。返回你能够从这笔交易中获取的最大利润。如果你不能获取任何利润,返回 0 。 int maxProfit(vector<int>& prices) { int min_price = INT_MAX, max_profit = 0; for(auto price : prices) { max_profit = max(max_profit, price - min_price); min_price = min(min_price, price); } return max_profit;}工夫复杂度:O(n),只须要遍历一次。空间复杂度:O(1),只应用了常数个变量。 2. 交易股票的最佳时机 II给定一个数组 prices ,其中 prices[i] 示意股票第 i 天的价格。在每一天,你可能会决定购买和/或发售股票。你在任何时候 最多 只能持有 一股 股票。你也能够购买它,而后在同一天发售。返回你能取得的最大利润 。 解法一:动静布局思考到「不能同时参加多笔交易」,因而每天交易完结后只可能存在手里有一支股票或者没有股票的状态。 定义状态dp[i][0]示意第 i 天交易完后手里没有股票的最大利润,dp[i][1]示意第i天交易完后手里持有一支股票的最大利润(i从0开始)。 思考dp[i][0]的转移方程,如果这一天交易完后手里没有股票,那么可能的转移状态为前一天曾经没有股票,即dp[i-1][0],或者前一天完结的时候手里持有一支股票,即dp[i-1][1],这时候咱们要将其卖出,并取得price[i]的收益。因而为了收益最大化,咱们列出如下的转移方程: dp[i][0] = max{dp[i-1][0], dp[i-1][1]+prices[i]} 再来思考dp[i][1],依照同样的形式思考转移状态,那么可能的转移状态为前一天曾经持有一支股票,即dp[i−1][1],或者前一天完结时还没有股票,即dp[i−1][0],这时候咱们要将其买入,并缩小prices[i]的收益。能够列出如下的转移方程: dp[i][1] = max{dp[i-1][1], dp[i-1][0]-prices[i]} 对于初始状态,依据状态定义咱们能够晓得第 00 天交易完结的时候 dp[0][0]=0,dp[0][1]=−prices[0]。 ...

April 8, 2022 · 4 min · jiezi

关于c#:47c-新建线程Thread线程内与操作窗体控件

Thread t3 = new Thread(() => { Console.WriteLine("a2...."); WriteLog("ComListForm.t3.begin.."); RefreshListFormDb(); }); t3.IsBackground = true; t3.Start();RefreshListFormDb()须要更新datagridView: List<ComPhoneBean> list = rv_list.Value; MethodInvoker mi = new MethodInvoker(() => { WriteLog("ComListForm.RefreshListFormDb....5."); UpdateDataGrid(list); }); this.BeginInvoke(mi);UpdateDataGrid这个办法更新Datagridview的内容: private void UpdateDataGrid(List<ComPhoneBean> list) { WriteLog("ComListForm.UpdateDataGrid....1."); if (list==null || list.Count == 0) { WriteLog("ComListForm.UpdateDataGrid....2."); return; } WriteLog("ComListForm.UpdateDataGrid....3."); this.dataGridView1.Rows.Clear(); WriteLog("ComListForm.UpdateDataGrid....4."); int index = 0; foreach(ComPhoneBean bean in list) { index++; this.dataGridView1.Rows.Add(new string[] { "" + index, bean.ComPort, bean.Phone, "" + bean.SignalIntensity }); } WriteLog("ComListForm.UpdateDataGrid....5."); }

April 7, 2022 · 1 min · jiezi

关于c#:Masa-Blazor-in-Blazor-Day

2022年第一场Blazor中文社区的开发者分享流动,咱们的团队也全程参加其中,在议程中,也分享了咱们团队的Blazor 治理后盾模板,针对于Blazor,先科普一波,防止有些敌人不理解,Blazor是微软推出的基于.NET的前端技术。利用现有的.NET生态,受于.NET的性能,可靠性和安全性,不仅能过够在服务器和客户端之间共享利用程序逻辑,还可能在不同的操作系统上高效、稳固的运行。本次Masa Blazor 也是分享最新的Blazor技术停顿和开发实际。 Masa技术团队全程参加咱们分享的议题是“开源的Blazor治理后盾模板”。通过咱们开源的我的项目MASA Framework Admin开展介绍,顺次介绍了具体的性能、技术栈、分享了咱们的Masa Blazor的组件和Masa Blazor Pro,同时也具体的阐明了MASA Framework的环境怎么装置、怎么运行等... 具体的具体内容,咱们精简成文字版给到大家,当天没有参加直播的敌人们,看这篇就够啦~仅限咱们的分享局部哦! 背景咱们做这个事件,其实是很忽然的,之前咱们公司的外部搞了一个小型的黑客松,大家花了3天工夫,基于咱们的组件库和框架,就把这样的一个我的项目给大家做进去了,因为是刚做进去的,用时也较短,其实能够说,还是个“宝宝”。基本上的性能演示是曾经做进去了,没有那么欠缺,如果期待值很高,那还是须要给一些工夫的。 MASA Framework Admin 的性能 多点登录互斥,同一个账号,只能在一台电脑上登录如果开了隐衷模式的浏览器,或者是在另外一个电脑下面,登录同一个账号,那么之前登录的账号就会被踢掉,是一个很实用的性能,咱们也用Blazor去给大家演示,在Blazor下面是怎么做到这点)引入Dapr,提供Pubsub、Secret等示例Pubsub就是事件,咱们把MQ用起来了 Secret就是密钥这些,大家会习惯于放在.NET配置文件里,通过Secret就能够放到Dapr的配置文件外面 定时工作,提供根底的定时计算报表数据的示例只是简略的给大家提供了一个定时计算报表的示例RBAC0,引入Role的概念,并将权限与角色进行关联。用户通过表演某种角色,具备该角色的权限引入角色的概念,把权限和角色关联起来,让用户去表演某种角色,而后具备该角色的权限。如果用RBAC,依据业务的复杂性,大家更偏向于用RBAC3,但MASA Framework Admin是一个比较简单的货色,临时不会实现RBAC3这么简单的性能。如果你须要RBAC3,而后又须要单点登录,而后不同我的项目之间的关系治理等等...如果须要这样的货色,能够略微等一下。咱们预计在往年7月前后,会开源另一个我的项目,叫MASA Auth。MASA Auth是咱们MASA Stack外面的第一个正式开源的我的项目,外面会给大家提供十分残缺的权限性能,你拿过来用,能够满足绝大多数的要求,基本上是不须要二开的集成可观测性这个性能其实也是dapr提供的技术栈.Net 6DaprMASA BlazorMASA FrameworkDocker ComposeMASA Blazor组件库演示Masa Blazor组件库格调 Material Design 咱们做这个组件库的时候,是照着vuetify做的,基本上是1:1还原的 咱们做了本人的首页,也能够在首页,理解更多Masa Blazor的详情 通过首页点击“开始应用”,在装置局部,咱们提供了演示视频,大家能够依据视频去操作,如果不喜爱看视频,上面的命令行就比拟适宜你啦!间接疾速看命令行就能够了,都是比较简单的。 组件也是做了蛮多的,感兴趣的能够间接到官网,点击理解更多。 https://blazor.masastack.com/... 用过咱们组件库的小伙伴,反映说”示例少“,这里和大家讲一下起因,因为一个组件的性能很多,咱们不太可能,全副都做成示例,如果你想看下,支不反对更多的性能,能够如下图所示,点击API进入之后,就能够看到咱们的组件,提供了多少属性、插槽、事件等,用过vue的小伙伴,对插槽这些,应该很相熟。 ”MASA Blazor Pro“,MASA Blazor的实际Masa Blazor Pro其实是一个纯前端的我的项目,是没有任何业务端的,群里的小伙伴,始终都在说,咱们的Pro蛮难看的,然而没有后端的演示代码,心愿咱们补充一下,咱们做Admin也是有这样的一个契机。大家要的布局,而后多页签、面包屑...这些咱们都是有做的,还包含多语言i18n,性能还原度上,都是做了的。打的版本号上,咱们是激进了一点,当初为止,咱们还没有打1.0的版本。咱们心愿1.0版本是能够给到大家长期反对的,所以咱们对1.0的要求比拟高,但实际上0.3.0也是足够大家用的, 组件展现 MASA Blazor Pro效果图 MASA Framework介绍底层框架、后端代码的局部咱们用的是MASA Framework,当初看到的是咱们第一个版本的性能清单。我的项目的模板、Dapr Starter...如果你用Dapr,应该就有理解。Dapr D的边车,每次启动的时候,会比拟麻烦。所以咱们做了一个Dapr Starter,只须要一行代码,它会主动去帮你治理Dapr D的整个生命周期,包含配置、包含端口映射等等一系列的操作,全副都会帮你做好。 Building Blocks 是咱们提供的整个框架的接口标准,就是咱们提供了哪些性能,这些性能都是通过接口标准提供的。Contribe就是实现了Building Blocks这些接口的,而后咱们提供了一些,咱们认为,你在用这些性能的时候,可能默认要用的一些选项。在咱们Building Blocks 外面,除了一些数据类相干的、服务类相干的,还有比如说Event Bus,包含隔离性、可观测性等这些都是有的。 ...

April 6, 2022 · 1 min · jiezi

关于c++:CS111-EIE111

Homework 1 : Knowledge items of C++ (part 1)C++ : CS111 EIE111 LP104MUST 2021 SpringInstructor: Zhiyao LiangMarch 22 2021I. Purpose of the homeworkIn order to write a good program, you need to know the following(a) The target tasks:The problems to be solved, the requirements and constraints.(b) The proper computation process for the taskThe algorithms.The data structure.(c) Enough knowledge of the programming language.So that the computation process can be implement as a program.There other homeworks that will emphasize the part (a) and (b). This homework emphasizes on part (c), and it will test different knowledge items(KI). The approach is based on the following observation:A knowledge item (KI) can be described or tested by at least two ways:Asking and answering some questions.Doing some tasks that are related to the KI.II. Requirements of the homeworkWrite a C++ program that satisfy two aspects of requirements:A: Use the C++ style as much as possibleIf there are different ways to write the code, choose the C++ way, not the C way. For example:For input and output, use cout and cin , instead of printf() and scanf() .Include the head file cstring in stead of string.h .B: Implement each task descried in Section IVSection IV describes a sequence of numbered tasks. Each task requires writing some simple code to reflect your understanding of someknowledge items of C++.For each task, say the nthtask, in your program you should the write some comment of the form / <n> / besides the statements thatimplement the KP.If a task can be implemented by several different pieces of code in the program, the comment mentioning a task number only needs to appearonce in the program. .For example, for the 5threquirement :5: Declare a variable of type int .The corresponding code that cover this knowledge point in the program could be like the following:int x; / <5> /If there are 3 statements declaring integer variables in the, the comment / <5> / only needs to appear once in your program.If a piece of code can cover several tasks, then the task numbers can be mentioned together. For example, if a statement that can cover the tasks4 and 6, the its comment can look like:/ <4> <6> /// some statementIII The knowledge neededThe tasks will cover the knowledge aspects covered from chapter 1 to chapter 9 in the textbookThese tasks cover the knowledge points of C++ in the following aspects:Compile programs of C++, C++ 2011 at command line.Structure of a program. Relationships between .cpp and .h files.The proper content of head files and the .cpp files.How to use the names defined in other files.Data types, constants, variables, arrays.composite data types:struct, union, enumVariable and array initializationHow to create data storage on different memory sectionsstatic areastackheap (allocation and release)pointers and referencesFunction definition, call, parameters, argumentsAn array name as an argument of function callsRecursive functionThree loop statementsnew style of for statements in C++if, if-else statementsswitch statementsinput and outputcin and coutknow the status of previous inputclear input queuereading and writing files.name spaces.template functionsDefine functions to solve simple computation problemsIV TasksThis section describe a list of tasks that need to be fulfilled in the program. For some tasks, their related knowledge items (marked by [k]), hints todo it ( [hint] ), and the design ideas ( [design] ) are mentioned. ...

April 4, 2022 · 14 min · jiezi

关于c++:网格拟合

这里的网格拟合,当然是三维网格拟合。 三维网格拟合有什么用?呃.....当前再说吧...... 什么是网格拟合嗯,常常常常听到[拟合]这个名词,它示意一个动作。最常听到的是最小二乘拟合---把一系列点拟合出一条线---把三维空间散乱点拟合出一个立体、球面、柱面... 拟合,总须要一个拟合源,总要有一个指标。下面场景中,拟合源个别是二维或者三维的点数据,指标个别是线、立体、球面或者柱面等等的数学参数示意。 OK,大略曾经晓得拟合是做什么的了。那咱们的三维网格拟合,又是怎么回事呢? 其实,三维网格的拟合和上述所谓拟合并没有本质区别,只是数据源和拟合指标都是可任意的三维网格数据而已,将两个三维网格拟合,其后果依然是一个三维网格,只不过拟合后的后果网格可能带有源数据和指标数据的局部显著特色。用公式示意就是: Mesh A + Mesh B = Mesh C,其中 “+”示意拟合计算留神:上述所谓三维网格的拟合,并不蕴含网格带纹理的状况。即纹理不参加拟合运算。 说白了,所谓三维网格的拟合,其实就是多个三维网格通过肯定的 ‘’ 修修剪剪 ‘’ 产生一个新网格的过程,新网格就是拟合的后果。 怎么进行网格拟合哦,我曾经晓得了什么是网格拟合,但怎么进行网格拟合计算呢。 如果,我有A和B两个三维网格数据,网格A有10w点,30w三角面片,网格B有7w点,20w三角面片,额(⊙﹏⊙)....它俩应该怎么进行拟合计算呢?---我应别离取A或B的哪一部分加入计算呢?A和B不在同一个坐标系下怎么办呢?我的拟合运算会不会扭转A或者B的三角网格顶点之间的连贯关系呢?A和B体积相差太大(比方一只狗和一只猫)怎么办呢?须要缩放吗?缩放系数怎么解决呢?拟合品质如何评估呢?......呃呃...头好大.... 既然头好大,那就规定非凡场景吧。 场景还是来拿手头的人头网格说事。首先,人头点云,隐含了点云的体积头差不多(小孩子除外);其次,同一个扫描设施获取的三维人头网格数据量不会差异太大(其实这个条件没啥影响);最初,就是...我手头只有三维人头数据能够测试(么有去找更多的)。 有上面两组数据,其中上边的图像记为Mesh A,下边的记为Mesh B, Mesh A:只有实在人脸局部,网格和顶点数量较多,三角网格之间并不是很“顺滑”;Mesh B:虚构全人头网格,网格数目和顶点数绝对A来说较少,且mesh表面光顺性较好。 指标,将A和B拟合,结构带有实在人脸网格模型的三维人头(理论利用中是有重要意义的)。 简略拟合至此,可能很多很多敌人,曾经想到了一种非常简单的网格拟合办法。怎么做呢? 首先,将Mesh A和Mesh B初步对齐,行将两个网格人脸局部对齐,放在同一个坐标系下。如何对齐呢?很简略,因为Mesh A和Mesh B都示意人脸网格,则其面部必有独特特色---眼睛、鼻子、嘴巴、鼻梁、眉毛.....通过选两组Mesh中对应的特色点,基于指定的准确的对应点对,通过ICP计算,即可取得某Mesh的变换矩阵,从而使得两个Mesh对立到对立坐标系下。示意图如下: 其次,在实现上述初步对齐--即两个模型的眼睛对眼睛、鼻尖对鼻尖...后,咱们只有扭转Mesh B的面部网格构造形态即可。通过设定脸部间隔阈值,在保障Mesh B各个顶点链接关系不变的条件下(即不扭转拓扑关系),扭转Mesh B的脸部特色点的网格顶点坐标,使得Mesh B脸部出现Mesh A的外观特色,即实现了两个网格的拟合。 如何实现上述计算呢?最简略的---置换或者说替换。通过设定的间隔阈值,找到Mesh B和Mesh A的脸部对应点对,将两个Mesh的对应点对的坐标间接进行替换,同时保障Mesh B中点的链接关系不变(若该边,可能 “ 脸就不是脸了 ”)。如下图: 能够看到,基于【简略拟合】实践,根本能够两个网格的拟合,并能根本失去本人想要的后果---含有实在人脸形态的全人头网格模型。 这就够了吗? 危险显然不够!其实,上边的【简略拟合】存在较大的危险,其后果根本无奈利用在理论生产我的项目中。 危险点1:品质较差。以上述形式拟合网格模型,如上图边界局部所示,拟合后果存在较大的突起,有十分突兀的形态变动。 危险点2:精度无奈保障。其实上述形式中,只是简略的对应点的顶点替换,这就导致了在替换时,各个参加计算的点没有思考其邻域点的散布状况。计算过程中,极大概率导致某个特色点的坐标屡次变换,而且该特色点的坐标只与最初一次变动(最初一个对应点)无关---因为,Mesh B和 Mesh A的点数、网格数目及点密度都不一样,当将两个网格拟合计算时,必然存在一对多或者多对一的状况。 危险点3:尺寸差异较大。这个问题应该怎么看待呢?!理论中,相对没有两个一摸一样的人,那么尺寸必然存在肯定误差。那咱们只能尽可能的缩小这种网格尺寸上的误差,可见,在下面计算中,没有思考这一点。 ...... 当然,还有其余很多的危险点,本人也无奈一一穷举。总之,上述形容计划兴许会是一种网格拟合的解决方案,然而对网格的后处理工作减少了许多的难度,须要更进一步的钻研与改良。 ...... 有没有其余方法呢? 实现有!先上一篇论文 《Review of Statistical Shape Spaces for 3D Data with Comparative Analysis for Human Faces》. ...

April 2, 2022 · 1 min · jiezi

关于c++:CC气象数据中心实战手把手教你做工业级项目附带源码

download:C/C++气象数据中心实战,手把手教你做工业级我的项目附带源码复制下崽ZY:https://www.zxit666.com/2347/大家在应用IDEA开发的时候有没有留神到过一个提醒,在字段上应用Spring的依赖注入注解@Autowired后会呈现如下正告 Field injection is not recommended (字段注入是不被举荐的) 然而应用@Resource却不会呈现此提醒网上文章大部分都是介绍两者的区别,没有提到为什么,过后想了良久想出了可能的起因,明天来总结一下Spring常见的DI形式 结构器注入:利用构造方法的参数注入依赖Setter注入:调用Setter的办法注入依赖字段注入:在字段上应用@Autowired/Resource注解 @Autowired VS @Resource事实上,他们的基本功能都是通过注解实现依赖注入,只不过@Autowired是Spring定义的,而@Resource是JSR-250定义的。大抵性能基本相同,然而还有一些细节不同: 依赖辨认形式:@Autowired默认是byType能够应用@Qualifier指定Name,@Resource默认ByName如果找不到则ByType实用对象:@Autowired能够对结构器、办法、参数、字段应用,@Resource只能对办法、字段应用提供方:@Autowired是Spring提供的,@Resource是JSR-250提供的 各种DI形式的优缺点参考Spring官网文档,倡议了如下的应用场景: 结构器注入:强依赖性(即必须应用此依赖),不变性(各依赖不会常常变动)Setter注入:可选(没有此依赖也能够工作),可变(依赖会常常变动)Field注入:大多数状况下尽量少应用字段注入,肯定要应用的话, @Resource绝对@Autowired对IoC容器的耦合更低 Field注入的毛病 不能像结构器那样注入不可变的对象依赖对外部不可见,外界能够看到结构器和setter,但无奈看到公有字段,天然无奈理解所需依赖会导致组件与IoC容器紧耦合(这是最重要的起因,来到了IoC容器去应用组件,在注入依赖时就会十分困难)导致单元测试也必须应用IoC容器,起因同上依赖过多时不够显著,比方我须要10个依赖,用结构器注入就会显得宏大,这时候应该考虑一下此组件是不是违反了繁多职责准则 为什么IDEA只对@Autowired正告Field注入尽管有很多毛病,但它的益处也不可疏忽:那就是太不便了。应用结构器或者setter注入须要写更多业务无关的代码,非常麻烦,而字段注入大幅简化了它们。并且绝大多数状况下业务代码和框架就是强绑定的,齐全松耦合只是一件现实上的事,就义了麻利度去适度谋求松耦合反而得失相当。那么问题来了,为什么IDEA只对@Autowired正告,却对@Resource熟视无睹呢?集体认为,就像咱们后面提到过的: @Autowired是Spring提供的,它是特定IoC提供的特定注解,这就导致了利用与框架的强绑定,一旦换用了其余的IoC框架,是不可能反对注入的。而 @Resource是JSR-250提供的,它是Java规范,咱们应用的IoC容器该当去兼容它,这样即便更换容器,也能够失常工作。

April 2, 2022 · 1 min · jiezi

关于c++:C语言利用指向数组的指针变量或指针数组求输入的数组的各行和

1、例如输出:2 3 4          5 6 7 输入:9          182、残缺代码如下2.1 C++版本#include <iostream>#include <cstring>using namespace std;int a[2][3];int res[2];void Sum(int (*p)[3], int total[], int n){ for(int i = 0; i < n; i++) { for(int j = 0; j < 3; ++j) total[i] += p[i][j]; }}int main(){ for(int i = 0; i < 2; ++i) for(int j = 0; j < 3; ++j) cin >> a[i][j]; Sum(a, res, 2); for(int i = 0; i < 2; ++i) cout << res[i] << endl; return 0; }2.2 C语言版本#include <stdio.h>int a[2][3];int res[2];void Sum(int(*p)[3], int total[], int n){ for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) total[i] += p[i][j]; }}int main(){ for (int i = 0; i < 2; i++) for (int j = 0; j < 3; j++) scanf_s("%d", &a[i][j]); Sum(a, res, 2); for (int i = 0; i < 2; i++) printf("%d\n", res[i]); return 0;}3、截图 ...

April 2, 2022 · 1 min · jiezi

关于c#:2022首场MASA技术团队黑客松赛事大赛完美落幕精彩集锦

Masa技术团队在2021年创建,这一年咱们团队公布了咱们第一个产品,Masa Blazor。登上了.NET Conf China,咱们承诺,开源咱们的产品,为开源社区增砖加瓦,一路上播种技术社区文章类的各种奖项... 2022年,咱们在路上... 开年之初,为了激励更多的开发同学参加到我的项目落地的实际中,团队外部举办了第一季的黑客松大赛,目前,第一季的获奖名次曾经颁布,这个过程中,有哪些项目和亮点,是值得关注的呢? 赛事详情后果很重要,过程更重要!背景在团队成立之初,就抱着做产品,要“高标准、严要求”的态度,去落地咱们的产品。愿景是心愿咱们的产品,最终能够做到咱们slogan说的那样!“让变动更简略”,但产品落地过程中,团队的严密合作,也至关重要。独特向着同一个指标,做喜爱的事件。借助团队的力量,做好每一个产品,最初就是拿后果。而黑客松的模式,能够让大家在日常的工作中,跳脱进去,集中在一段时间,去更有创造力的实现一个新的我的项目,过程中的成长,可能比理论播种的处分,更感动人心。 赛事处分任何赛事的举办,肯定要有好的彩头去激励参赛者。本次赛事,团队创始人们给到参赛者的激励是,“第一名能够播种5000元现金处分”,以及对应的职级降职布局,还有代表荣誉的名次奖杯。经营悄悄地采访了一下冲动的参赛者们!大家都在悄咪咪的讲,“万一第一名是本人呢~对吧”! 赛事期间,能量加油站间接拉满~ 赛程实录较量工夫:2022/02/10-2022/02/12 为期三天 参赛团队、选题: 组选题团队第一组主控面板,对立登录(升高为jwt登录),后盾页面布局,在线用户数,拜访日志筷子队(2人)第二组用户治理,组织治理,项目管理,菜单治理,角色治理,rbac0RBAC(3人)第三组字典,定时工作(dll和http,包含例子,控制面板,异样告诉等),发送邮件,文件服务(minio)拍脑袋(3人)第四组博客后盾治理静止卫裤队(3人)第五组博客前台Blog(2人过程中,会有界面设计师与产品经理全程合作,助力每个团队。 业余评审团队谨严把关在赛事发布会时,对于评审团队的评审规范,以及评审的谨严、公平性做出公示。会通过围绕技术、产品、创新力等多个方面对参赛我的项目进行评比,最终筛选出了各赛道最具后劲的优质我的项目。但因为参赛人员,是公司外部开发同学,针对每个开发的实力,评审团队是十分分明的,所以对于每个开发的规范,肯定是有差异化期待,保障每个参赛团队都在偏心的赛道上发力。 赛事过后,评审工夫为期一周,这一周内,每个团队都会在规定的工夫内,针对本人做的我的项目,进行演示和问难。评审的过程中,每个团队都全力以赴,力求能够在无限工夫内,能够很好的演示,以及说出全副我的项目亮点,评审团队的问答也是非常的精彩。 各团队我的项目亮点为了给每个团队,一个独立施展的空间,赛事场地长期征用了公司的各个角落,仓库都安顿上啦 ! 但并不影响大家的施展呢~筷子队:操之过急的同时不乏亮点,像多点登录互斥、在线人数统计、定时工作、异步生产等。 RBAC:性能布局丰盛,界面简洁且有一些业务翻新。 拍脑袋:引入minio作为文件存储,往云原生的路线上后退。 静止卫裤队:竟然反对广告设置,满足了“资本大佬”的欲望。 Blog:反对敏感词检测,对政策竟然钻研的如此透彻。最终第一名团队是:筷子队获奖起因:较量正式开始之前,筷子队就曾经把根本的框架拉进去了,整个过程中很踊跃,同时也在我的项目里加了一些比拟好的性能,比方:同一个账号同时登录,会把原登录的账号挤掉这些,对理论的业务场景做了反对,包含咱们公司将来的产品也会用到这些,演示的过程中,是没有bug的,所以最终决定这个奖给到了筷子团队!这个是评审团最终做出的总结! 赛后我的项目落地的转化本次优胜团队的我的项目,收录到了咱们的Masa.Admin中, Masa.Admin实现了RBAC(权限治理)、多点登录互斥、拜访日志性能。技术栈用到了咱们的 Masa.Framework、Masa.Blazor。代码继续更新中,感兴趣的小伙伴们,能够间接去看代码 https://github.com/masalabs/M... Masa.Admin我的项目演示截图 面包屑 多页签 菜单 部门 角色 用户 用户组 本次赛事,圆满闭幕。赛事过后,团队针对赛事做了整体的复盘,好的局部,咱们持续保留,做的没那么好的局部,下次赛事,咱们持续欠缺,本次赛事采取了非公开模式。之前通过咱们的Masa Blazor等产品,积攒了很多的用户,非常感谢大家的关注,咱们也心愿,下次赛事,能够和更多的用户,有更好的互动,可能会采取线上直播的形式等,如果对咱们的团队感兴趣,也欢送大家退出咱们!凋谢的团队气氛,肯定能够感化每一个你。 咱们正在口头,新的框架、新的生态咱们的指标是自在的、易用的、可塑性强的、功能丰富的、强壮的。 所以咱们借鉴Building blocks的设计理念,正在做一个新的框架MASA Framework,它有哪些特点呢? 原生反对Dapr,且容许将Dapr替换成传统通信形式架构不限,单体利用、SOA、微服务都反对反对.Net原生框架,升高学习累赘,除特定畛域必须引入的概念,保持不造新轮子丰盛的生态反对,除了框架以外还有组件库、权限核心、配置核心、故障排查核心、报警核心等一系列产品外围代码库的单元测试覆盖率90%+开源、收费、社区驱动还有什么?咱们在等你,一起来探讨通过几个月的生产我的项目实际,已实现POC,目前正在把之前的积攒重构到新的开源我的项目中MASA.BuildingBlocks:https://github.com/masastack/MASA.BuildingBlocks MASA.Contrib:https://github.com/masastack/MASA.Contrib MASA.Utils:https://github.com/masastack/MASA.Utils MASA.EShop:https://github.com/masalabs/MASA.EShop MASA.Blazor:https://github.com/BlazorComponent/MASA.Blazor 如果你对咱们的 MASA Framework 感兴趣,无论是star、代码奉献、应用、提 Issue,欢送分割咱们 ------ END ------

April 1, 2022 · 1 min · jiezi

关于c++:CS111问题求解

Homework 1 : Knowledge items of C++ (part 1)C++ : CS111 EIE111 LP104MUST 2021 SpringMarch 22 2021I. Purpose of the homeworkIn order to write a good program, you need to know the following(a) The target tasks:The problems to be solved, the requirements and constraints.(b) The proper computation process for the taskThe algorithms.The data structure.(c) Enough knowledge of the programming language.So that the computation process can be implement as a program.There other homeworks that will emphasize the part (a) and (b). This homework emphasizes on part (c), and it will test different knowledge items(KI). The approach is based on the following observation:A knowledge item (KI) can be described or tested by at least two ways:Asking and answering some questions.Doing some tasks that are related to the KI.II. Requirements of the homeworkWrite a C++ program that satisfy two aspects of requirements:A: Use the C++ style as much as possibleIf there are different ways to write the code, choose the C++ way, not the C way. For example:For input and output, use cout and cin , instead of printf() and scanf() .Include the head file cstring in stead of string.h .B: Implement each task descried in Section IVSection IV describes a sequence of numbered tasks. Each task requires writing some simple code to reflect your understanding of someknowledge items of C++.For each task, say the nthtask, in your program you should the write some comment of the form / <n> / besides the statements thatimplement the KP.If a task can be implemented by several different pieces of code in the program, the comment mentioning a task number only needs to appearonce in the program. .For example, for the 5threquirement :5: Declare a variable of type int .The corresponding code that cover this knowledge point in the program could be like the following:int x; / <5> /If there are 3 statements declaring integer variables in the, the comment / <5> / only needs to appear once in your program.If a piece of code can cover several tasks, then the task numbers can be mentioned together. For example, if a statement that can cover the tasks4 and 6, the its comment can look like:/ <4> <6> /// some statementIII The knowledge neededThe tasks will cover the knowledge aspects covered from chapter 1 to chapter 9 in the textbookThese tasks cover the knowledge points of C++ in the following aspects:Compile programs of C++, C++ 2011 at command line.Structure of a program. Relationships between .cpp and .h files.The proper content of head files and the .cpp files.How to use the names defined in other files.Data types, constants, variables, arrays.composite data types:struct, union, enumVariable and array initializationHow to create data storage on different memory sectionsstatic areastackheap (allocation and release)pointers and referencesFunction definition, call, parameters, argumentsAn array name as an argument of function callsRecursive functionThree loop statementsnew style of for statements in C++if, if-else statementsswitch statementsinput and outputcin and coutknow the status of previous inputclear input queuereading and writing files.name spaces.template functionsDefine functions to solve simple computation problemsIV TasksThis section describe a list of tasks that need to be fulfilled in the program. For some tasks, their related knowledge items (marked by [k]), hints todo it ( [hint] ), and the design ideas ( [design] ) are mentioned. ...

March 31, 2022 · 14 min · jiezi

关于c#:体验了一把最近很火的开源项目MASA-Blazor

前言        很羞愧直到去年底才接触到Blazor。那什么是Blazor呢?置信大家都看过官网文档的具体阐明,另外MASA团队也有不错的阐明介绍 。用官网的话说Blazor是一个交互式客户端Web UI的框架,并且应用C#开发而不是JavaScript。好了言归正传,事件的起因是这样的,公司组织外部比赛须要用Blazor做一个简略的网页。为了能够更好的做出成果就简略的尝试了几个开源组件。 开源组件抉择         遇事不决先找官网Blazor 教程,跟着微软的教程会失去上面这个样子的页面。 嗯,还是挺清爽的...预计会被领导喷死吧。既然官网提供的款式太清爽。那就要想一下怎么弯道超车了。         于是乎开始网上冲浪,首先想到的是Bootstrap Blazor组件库,也没有什么特地的起因可能只是因为以前常常用它写后盾页面吧。关上它的文档站点是上面这样的 无惊无喜吧,组件库看起来还是蛮丰盛的。接着在比拟下Ant Design Blazor。 颜值党感觉拉不开差距,接着就看到了前几天公布的MASA Blazor。跟下面两个赫赫有名相比这个名气绝对小了一些。不过人不可貌相海水不可瓢崴,这个官网首页高大上了不少啊。心愿组件库别翻车。 尽管说组件库是列表展现没有平铺那么直观吧,然而这几个示例做的也难看太多了。 既然难看就连忙趁热再多理解一下,关上源码他们也是有疾速创立我的项目模板的。这里我就间接把官网的应用介绍拿来用了。 依照模板生成进去的是这个样子的,我集体是十分喜爱这种设计格调的,感觉能够省不少事。 应用MASA Blazor做个后盾治理页面1.输入框<MTextField @bind-Value="_options.Title" Label="题目"></MTextField> 这样就实现了一个输入框并且绑定了_options.Title这个对象。查看了官网文档并且进入了官网的交换区,发现了还有更实用的技巧。应用onEnter及onSearch就能够实现回车触发检索条件了,相当于JS的onkeydown事件。 <PPageHeader Title="搜寻" ShowFiltersByDefault OnSearch="() => FetchList()">    <Filters Context="filter">        <MRow Dense>            <MCol Cols="12" Sm="6" Md="4">     <MTextFieldLabel="题目"                    @bind-Value="_options.Title"                    Dense                     HideDetails="auto"                     Outlined                     Clearable     OnKeyDown="filter.onEnter"     OnClearClick="filter.onSearch">      </MTextField>     </MCol>     </MRow>    </Filters></PPageHeader>2.下拉框<MSelect Label="状态"          Dense         HideDetails="auto"         Outlined         Clearable     MenuProps="(props) => props.OffsetY = true"         Items="Enum<StateTypes>.GetEnumObjectList<StateTypes>()" ItemText="item => item.Name" ItemValue="item => item.Value" @bind-Value="_options.State" TItem="EnumObject<StateTypes>" TValue="StateTypes?" TItemValue="StateTypes" OnSelectedItemUpdate="filter.onSearch" OnClearClick="filter.onSearch"></MSelect>这样就能够实现把枚举StateTypes间接转成下拉菜单展现了。 3.日期选择器<PDateTimePicker Label="公布开始工夫"                 Clearable                 Dense                 DefaultSelectedValue="DateTime.UtcNow"                 HideDetails="auto"                 Outlined                 Format="yyyy-MM-dd HH:mm:ss"                 @bind-Value="_options.ReleaseStartTime" OnOk="filter.onSearch" OnClearClick="filter.onSearch"></PDateTimePicker> 4.数据表格        数据表格这里应用的时候遇到了一个小问题。就是分页的数量。从官网的示例中能够看到这里是反对全副获取的,但实在的场景这种状况必定是要躲避的。看了官网博客应用MASA.Blazor写一个规范的查问表格页 - MASA Blogs也没有找到好的答案。 ...

March 31, 2022 · 2 min · jiezi

关于c++:多视角三维模型纹理映射-03

首先,严格意义来说,本文题目并非合乎无关多视角纹理映射的相干内容,而是基于上一篇文章《多视角三维模型纹理映射 02》的留坑持续... 其实,应该叫做 -- 3D扫描仪转台标定 吧。 在开启这部分的工作前,查阅了很多论文、材料等,其中比拟有借鉴意义的是《旋转平台点云数据的配准办法》,【作者周朗明,郑顺义,黄荣永,武汉大学】,这篇文章给了本人极大的启发。 设施与筹备先来看一些本人所用到设施及其大体组合构造示意图: 本人所应用的根本设施如上图所示:相机支架,深度相机(间接产生点云,内参已知)、旋转平台,待测物体(标定块)。嗯嗯,只有也仅有上述几个设施而已。其中旋转平台和相机的间隔应在正当范畴内。 在固定好上述设施的地位关系后,接下来就是设计标定算法并验证了。 3D扫描仪转台标定算法设计首先要明确,标定的目标是什么,料想的标定后果是什么。 标定目标第一个问题:标定的目标??目标难道不是确定转台和相机的绝对地位关系嘛?!是,当然是。更进一步的,因为相机无奈间接拍摄转台外表获取相应数据(此处转台为纯彩色,且转台外表没有标记点),因而须要借助标定块来实现相应目标。此时,上图中 [实物 ]能够临时了解为 [标定块 ]。 此时,又引来另一个问题,抉择什么样的标定块。留神,这里的标定块,是【块】,不是标定板,是一个三维的实体规范块。在抉择标定块时候,最好该标定块有严格且已知的规范尺寸,形态最好比较简单,且数学意义上比拟好形容,如球、圆柱等等。 算了,间接上我选的标定块吧,如图: 对,没有错。我抉择了台球,台球简直合乎上述所有要求(规范直径,规范数学形容公式、易拟合),而且还比拟便宜。此时标定块或者称为标定球更为适合。在理论施行中,我抉择了那个纯白色的球球...eee...因为其外表色调比拟繁多.... 留神:因为相机内参曾经晓得了,不须要对深度相机进行反复标定,所以也不须要标定板。 至此,根本解决了所有内部依赖条件。 标定的后果在筹备得当所有的内部硬件条件后,进一步便须要寻求标定后果。 设想一下扫描过程:转台在地位1,相机拍摄该地位下的标定块点云1-1;转台在地位2,相机拍摄该地位下的标定块点云2-2;...如此循环直到实现标定块的360度扫描。 转台旋转一周,拍摄的台球点云如下图: 不言而喻,“貌似”规范球在围绕一个货色旋转了一周。想想也是如此,不就是转台带着规范球转了一圈嘛。 的确,这里的一个货色就是咱们3D转台标定要求解的货色。从论文和上图数据,不难猜测:扫描失去的点云,是在绕某个固定轴--这个货色旋转。至此,根本晓得,我要求解的后果应该是个固定轴。 是什么样的固定轴呢?--旋转平台的核心轴---旋转平台的核心轴在相机坐标系下的示意---旋转平台的中心点和旋转平台的立体法向量 在相机坐标系下的示意==>标定后果。 至此,彻底明确了,所谓的标定后果,应该蕴含两个数据:点坐标和向量。 在上述场景下,如何求解这两个货色?!根本求解过程如下: 将台球固定在转台表明,管制旋转平台绕固定角度旋转;相机拍摄每个固定角度下的台球点云数据;为缩小误差,步骤1和步骤2数据量个数越多越好;拟合每个角度下的台球点云---球数据,并提取球心(提取球半径,与标准台球半径比拟,侧面测验规范球拟合算法精度);反复步骤4,直至计算出所有拍摄角度下的球心坐标;基于步骤5,在三维空间中拟合圆;提取三维圆形的圆心和法向量==>标定后果。为了进一步提高精度,能够反复步骤1--7,取屡次测量后果的均值作为最终的标定后果。 测试将规范球的标定后果利用于规范球,试验后果如下: 由上图可见,标定过程根本正确,后果根本可承受。 测试人头数据: 本篇文章的记录根本都可能基于PCL实现,所以不再贴源码。 大节本篇文章联合后面几篇,实践上根本能够搭建一个转台式三维扫描仪,当然,还有很多很多中央须要改良。 最近一系列文章涵盖了3D标定(本文)、点云非线性全局优化、全局点云交融、三维网格模型纹理映射等几个方面的根本要点及基础理论。尽管目前都已实现,但还有待更进一步的深刻开掘。

March 31, 2022 · 1 min · jiezi

关于c:COMP2401-simulator

COMP2401 - Assignment #5(Due: Wednesday, March 31st, 2021 @ 6pm)In this assignment, you will make a simulator for a singe 4-way traffic-monitor at an intersection thatuses multiple threads and allows multiple vehicles to connect to it … with each vehicle and traffic lightrunning as its own process.To begin this assignment, you should download ALL of the following files:• makefile – use this to compile everything.• simulator.c – this is the simulator program• simulator.h – contains definitions and structs that will be used throughout your code• trafficServer.c – this is the code to run the traffic server that communicates with the vehicles• movementTimer.c – this code updates the positions of the vehicles• trafficLight.c – this code simulates a traffic light• trafficLight.h – contains definitions for the code pertaining to traffic lights• vehicle.c – this is the code that runs a single vehicle• vehicle.h – contains definitions for the vehicle-related information• display.c – contains the window/drawing code that you will use to display everything• generator.c – this is the code that repeatedly generates vehicles• stop.c – this is the code that stops the server cleanly.There are 4 programs that you will be running:• simulator – runs the server that vehicles communicate with• stop – stops the server when run• vehicle – simulates a single vehicle• generator – generates a bunch of vehicles repeatedlyFollow the steps below (in order) to complete the assignment:(1) Use the makefile to compile everything. Run the simulator program. You should see theintersection showing with 4 red lights and nothing moving. A getchar() has been placed at thebottom of the main() in simulator.c so that you can stop the program either by pressingENTER in the terminal window or pressing the X on the simulator window.(2) Four traffic lights have been created in the main() function of simulator.c. Do not alter thiscode. However, you must add code to the main() function so that it creates 4 threads … onefor each traffic light. The thread should start by calling the runTrafficLight() function in thetrafficLight.c file. You will want to pass in a traffic light to that function. The code currentlyruns in an infinite loop doing nothing but pausing for half a second. The TrafficLight structhas been defined in trafficLight.h. Do not alter it. Add code to the function so that it makesthe traffic lights work properly by setting the currentState and countDownTimer values. Ifyou look at the trafficLight.h header, it also defines the following constants: ...

March 31, 2022 · 17 min · jiezi

关于c#:体验了一把最近很火的开源项目MASA-Blazor

前言很羞愧直到去年底才接触到Blazor。那什么是Blazor呢?置信大家都看过官网文档的具体阐明,另外MASA团队也有不错的阐明介绍 。用官网的话说Blazor是一个交互式客户端Web UI的框架,并且应用C#开发而不是JavaScript。好了言归正传,事件的起因是这样的,公司组织外部比赛须要用Blazor做一个简略的网页。为了能够更好的做出成果就简略的尝试了几个开源组件。 开源组件抉择遇事不决先找官网Blazor 教程,跟着微软的教程会失去上面这个样子的页面。 嗯,还是挺清爽的...预计会被领导喷死吧。既然官网提供的款式太清爽。那就要想一下怎么弯道超车了。 于是乎开始网上冲浪,首先想到的是Bootstrap Blazor组件库,也没有什么特地的起因可能只是因为以前常常用它写后盾页面吧。关上它的文档站点是上面这样的 无惊无喜吧,组件库看起来还是蛮丰盛的。接着在比拟下Ant Design Blazor。 颜值党感觉拉不开差距,接着就看到了前几天公布的MASA Blazor。跟下面两个赫赫有名相比这个名气绝对小了一些。不过人不可貌相海水不可瓢崴,这个官网首页高大上了不少啊。心愿组件库别翻车。 尽管说组件库是列表展现没有平铺那么直观吧,然而这几个示例做的也难看太多了。 既然难看就连忙趁热再多理解一下,关上源码他们也是有疾速创立我的项目模板的。这里我就间接把官网的应用介绍拿来用了。 依照模板生成进去的是这个样子的,我集体是十分喜爱这种设计格调的,感觉能够省不少事。 应用MASA Blazor做个后盾治理页面1.输入框<MTextField @bind-Value="_options.Title" Label="题目"></MTextField> 这样就实现了一个输入框并且绑定了_options.Title这个对象。查看了官网文档并且进入了官网的交换区,发现了还有更实用的技巧。应用onEnter及onSearch就能够实现回车触发检索条件了,相当于JS的onkeydown事件。 <PPageHeader Title="搜寻" ShowFiltersByDefault OnSearch="() => FetchList()">    <Filters Context="filter">        <MRow Dense>            <MCol Cols="12" Sm="6" Md="4">     <MTextFieldLabel="题目"                    @bind-Value="_options.Title"                    Dense                     HideDetails="auto"                     Outlined                     Clearable     OnKeyDown="filter.onEnter"     OnClearClick="filter.onSearch">      </MTextField>     </MCol>     </MRow>    </Filters></PPageHeader>2.下拉框<MSelect Label="状态"          Dense         HideDetails="auto"         Outlined         Clearable     MenuProps="(props) => props.OffsetY = true"         Items="Enum<StateTypes>.GetEnumObjectList<StateTypes>()" ItemText="item => item.Name" ItemValue="item => item.Value" @bind-Value="_options.State" TItem="EnumObject<StateTypes>" TValue="StateTypes?" TItemValue="StateTypes" OnSelectedItemUpdate="filter.onSearch" OnClearClick="filter.onSearch"></MSelect>这样就能够实现把枚举StateTypes间接转成下拉菜单展现了。 3.日期选择器<PDateTimePicker Label="公布开始工夫"                 Clearable                 Dense                 DefaultSelectedValue="DateTime.UtcNow"                 HideDetails="auto"                 Outlined                 Format="yyyy-MM-dd HH:mm:ss"                 @bind-Value="_options.ReleaseStartTime" OnOk="filter.onSearch" OnClearClick="filter.onSearch"></PDateTimePicker> 4.数据表格数据表格这里应用的时候遇到了一个小问题。就是分页的数量。从官网的示例中能够看到这里是反对全副获取的,但实在的场景这种状况必定是要躲避的。看了官网博客应用MASA.Blazor写一个规范的查问表格页 - MASA Blogs也没有找到好的答案。 ...

March 30, 2022 · 2 min · jiezi

关于c:理解C语言中的aa和aa

C语言中 a++ a-- 和 ++a --a 的区别a++ 示意先赋值再进行加运算a-- 示意先赋值再进行减运算++a 示意先进行加运算再赋值--a 示意先进行减运算再赋值注:从下面的概念了解很形象实例1. 了解 a++ 代码# include <stdio.h>int main(){ int a = 10; int c ; // 第一次间接给 c 赋值 c = a = 10,第二次再计算赋值给 a ,即 a = a + 1 = 10 + 1 = 11 c = a++; printf("先赋值再运算 \n"); printf("此时 c 的值为:%d", c); printf("此时 a 的值为:%d", a); return 0;}计算结果如下: 先赋值再运算此时 c 的值为:10此时 a 的值为:112. 了解 a-- 代码# include <stdio.h>int main(){ int a = 10; int c ; // 第一次间接给 c 赋值 c = a = 10,第二次再计算赋值给 a ,即 a = a - 1 = 10 - 1 = 9 c = a--; printf("先赋值再运算 \n"); printf("此时 c 的值为:%d", c); printf("此时 a 的值为:%d", a); return 0;}计算结果如下: ...

March 30, 2022 · 2 min · jiezi

关于c:CC-用什么软件编程

一款不便棘手的编程软件对于 C/C++ 开发者们来说,无疑会节俭十分多不必要的环境装置和学习应用教程的工夫。看到一些答复围绕不同操作系统,举荐了不同的IDE。我在这里给大家介绍一个全平台都通用、轻量且功能强大的在线编辑器 Lightly。它是首个依据中国开发者应用习惯量身打造的 IDE 编程软件,界面风格简洁明快。 在 Lighlty 上用户不须要配置任何编译运行环境,抉择开发语言后即可开始写代码。代码和我的项目文件能够实时保留在云端的,换台不同零碎的电脑或者是用平板,也能够关上我的项目,持续编码。 进入 Lightly 官网,能够抉择在线应用或者下载Mac和Windows本地版。 Lightly 不仅所有语言界面都有中文,而且反对手机或者QQ、微信扫码登录,十分中央便。(一键体验) 抉择我的项目语言后,零碎会主动生成对应的开发环境,你只须要在工作区域间接写代码就行。Lightly同样反对高亮显示、智能提醒、主动补全等性能。操作笨重灵便,应用便捷,开发效率高,是十分完满的 C/C++ 编程软件。 除此之外,他还具备我的项目一键分享性能:只需点击界面右上角头像旁边的“增加成员”按钮,生成并分享链接给小伙伴,他们就能够退出我的项目一起写代码啦!Lightly 对于有团队合作需要的开发者来说,也是最合适的抉择。

March 29, 2022 · 1 min · jiezi

关于c#:C-多线程

线程被定义为程序的执行门路。每个线程都定义了一个独特的控制流。如果您的应用程序波及到简单的和耗时的操作,那么设置不同的线程执行门路往往是无益的,每个线程执行特定的工作。 线程是轻量级过程。一个应用线程的常见实例是古代操作系统中并行编程的实现。应用线程节俭了 CPU 周期的节约,同时进步了应用程序的效率。 到目前为止咱们编写的程序是一个单线程作为应用程序的运行实例的繁多的过程运行的。然而,这样子应用程序同时只能执行一个工作。为了同时执行多个工作,它能够被划分为更小的线程。 线程生命周期线程生命周期开始于 System.Threading.Thread 类的对象被创立时,完结于线程被终止或实现执行时。 上面列出了线程生命周期中的各种状态: 未启动状态:当线程实例被创立但 Start 办法未被调用时的情况。就绪状态:当线程筹备好运行并期待 CPU 周期时的情况。不可运行状态:上面的几种状况下线程是不可运行的:曾经调用 Sleep 办法曾经调用 Wait 办法通过 I/O 操作阻塞死亡状态:当线程已实现执行或已停止时的情况。主线程在 C# 中,System.Threading.Thread 类用于线程的工作。它容许创立并拜访多线程应用程序中的单个线程。过程中第一个被执行的线程称为主线程。 当 C# 程序开始执行时,主线程主动创立。应用 Thread 类创立的线程被主线程的子线程调用。您能够应用 Thread 类的 CurrentThread 属性拜访线程。 上面的程序演示了主线程的执行: 实例using System;using System.Threading; namespace MultithreadingApplication{ class MainThreadProgram{ static void Main(string[] args) { Thread th = Thread.CurrentThread; th.Name = "MainThread"; Console.WriteLine("This is {0}", th.Name); Console.ReadKey(); }}}当下面的代码被编译和执行时,它会产生下列后果: This is MainThread

March 29, 2022 · 1 min · jiezi

关于c:MIPS-simulator-项目

Project 1 OverviewThe first project is going to be a MIPS simulator. In general, you will be building a program thatsimulates the execution of an assembly language file. The input of your program will be a MIPSfile that contains MIPS assembly language code. Examples will be given in the latter part of thisinstruction.1.1 Readings:Please read Appendix A from the text book before you start writing your first project. Make sureyou understand what each MIPS instruction is doing. All of the supplementary materials for thisproject can be found in Appendix A, such as the register numbers, instructions, and their machinecode format.MIPSMIPS is an assembly language, which is a low level programming language that each line ofcode corresponds to one machine instruction.2.1 InstructionMachines cannot understand high level programming languages directly, such as C/C++/JAVA.High level programming languages are "translated" to machine instructions that machine canunderstand. Assembly languages, including MIPS we deal with, are the readable (althoughdifficult) version of machine code. In assembly languages, one instruction tells the computer to doone thing exactly. For example, an instruction may look like this:This instruction tells the computer to add up the things stored in register $t1 and register $t2and store the result in $t3. Here, registers are small chunks of memory in CPU used for programexecution. The MIPS assembly language has three types of instruction in general: I-type, R-type,and J-type, each corresponds to a pattern of the 32 bits of machine code. Details can be found inAppendix A of the text book. The above instruction has the machine code:It does not make sense at a glance, however, it follows a certain pattern. The add instruction isa R-instruction, so it follows the pattern of:add $t0, $t1, $t200000001001010100100000000100000R-instruction:op rs rt rd shamt funct| 6bits | 5bits | 5bits | 5bits | 5bits | 6bits |op: operation code, all zeros for R-instructions.rs: the first register operandrt: the second register operandrd: the destination registershamt: shift amount. 0 when N/AHere, we go through how this instruction and its machine code corresponds to each other.The first 6 bits for R-instruction are for operation code, which are all zeros for R-type.The following three 5-bit slots are the register numbers specified in the instruction. "rs" and"rt" represents the first and second register operand in the instruction, and "rd" representsthe destination register. Here, the register number of $t0, $t1, and $t2 are 8, 9, 10,respectively. These translate to 01000, 01001, 01010 in binary, respectively. Putting them inthe right place, we have the middle 15-bits."shamt" represents the shift amount, which are only in certain instructions (such as sll, srl),and 0's are filled when N/A. In add instruction, these 5 bits are zeros.The last 6 bits are for function code. The function code for add is 32, which is 100000 inbinary.Machine codes of other R-instructions are constructed through the same process. As for Iinstructionsand J-instructions, I will not go through an example. The formats of these two types ofinstructions are:2.2 MIPS programsNow you know what do MIPS instructions look like, but what does a MIPS program look like?Here is a general format a MIPS program follows:funct: function code, which is used to identify which R-instruction this is.The add instruction has the format:add $rd, $rs, $rtTherefore, for add $t0, $t1, $t2, we have:01001 01010 01000 00000 100000I-instruction:op rs rt immediate| 6bits | 5bits | 5bits | 16bits |op: the operation code that specifies which I-instruction this is.rs: register that contains the base addressrt: the destination/source register (depends on the operation)immediate: a numerical value or offset (depends on the operation)J-instruction:op address| 6bits | 26bits |op: the operation code that specifies which J-instruction this is.address: the address to jump to, usually associate with a label. Since theaddress of an instruction in the memory is always divisible by 4 (think aboutwhy), the last two bits are always zero, so the last two bits are dropped.In general, a MIPS program looks like this. All of the MIPS code goes under the .text section, andall of the static data in the program are under .data section. As you can see, for each piece ofstatic data, we have a name to it, just like what we do in high level programming languages. "str1"is the name to that piece of data, .asciiz is the data type of it, and "hello world!\n" is the value.There are many other types of data, you can find them in Appendix A.For the code part, as you can see, we also have a "name" called "main". This is the labelrepresenting the line of code. Usually this is used for indicating the start of a loop, a function, or aprocedure. Recall that all of these codes are stored somewhere in the memory, which means thateach line of code has a specific address. To better understand this, see section 2.3.2.3 How computer runs the program?With the idea that all of the codes are stored in memory, and each has an address, we can nowtalk about how computers run these codes. Long story short, the computer runs the programsfollowing the machine cycle.2.3.1 Machine cycleA shorter version of a machine cycle looks like this:The computer loads the line of instruction PC is "pointing at".The computer increment PC by 4 (think about why).The computer runs the instruction loaded.This goes on until the program terminates. PC in this context represents the "program counter".In other words, PC is the "pointer" the computer maintains that stores the address of thenext instruction to be executed.Project 1 details3.1 RequirementsYour project 1 should be written in C/C++ only.You will need to write your own makefile/cmake.The testing environment is provided by Mr. Yifan Zhu and Mr. Guochao Xie. You need tomake sure your program can execute without a problem on the VM/Docker they provided.You can access the testing environment through VM instruction on BB.The detailed list of the MIPS instructions you need to support will be announced later.3.2 Assembler.data #static data go herestr1: .asciiz "hello world!\n".text #MIPS code goes heremain: add $t0, $t1, $t2...3.2.1 OverviewThe first task you are doing is assembling the given MIPS code to their corresponding machinecode. Here's a quick example of what you need to do:Remember that you are not assembling the .data section, nor the labels. The .data section willbe loaded to your memory in your simulation part. The labels in your .text section will betranslated to its corresponding address when needed. For example, when you see j R , you willput the address of the line of instruction label R is indicating.3.2.2 DetailsThis part of your program is easy but needs your patience. You need to be able to:Read file line by line.Find the segments of the MIPS file. (.data, .text)Tokenize the line read in.Discard useless information, such as comments.Here are some ideas of how to implement this part:You need to scan through the file for the first time. This time, discard all of the comments(following a "#"). Remember you only need to deal with .text segment for assembling. Find allof the labels in the code, and store them with their corresponding address for laterreference.You need to scan through the file for the second time, line by line. This time, you need toidentify which instruction the line is (R, I, J). According to the instruction type, you canassemble the line. For lines with the label, you can refer to the stored information for thelabel's address.3.3 Simulator3.3.1 OverviewThis is the major part of your project 1. You need to have a full understanding of how computerexecutes programs, and how are things stored in memory. Your code will need to be capable ofexecuting the MIPS code line by line.MIPS code:.textR: add $s0, $s1, $s2 #r instructionsaddu $s0, $s1, $s2sub $s0, $s1, $s2subu $s0, $s1, $s2Machine code:000000100011001010000000001000000000001000110010100000000010000100000010001100101000000000100010000000100011001010000000001000113.3.2 Memory & register simulationThe first thing you will need to do is memory simulation. Think about your simulator as a minicomputer,that has its own main memory, CPU, etc. To simulate main memory, you need todynamically allocate a block of memory with C/C++, with a size of 6MB. Here is a figure of whatdoes a real computer memory look like.Your simulated memory should also have these components. Also, since most of you are usinga 64-bit computer, you need to "translate" the real address of your allocated memory to a 32-bitsimulated address. Specifically:Let's say you have the pointer named "real_mem" storing the real address of the block ofmemory allocated. The first thing you need to do is to map the value of "real_mem" to400000_hex. Then the real address will have a 1-to-1 mapping relationship to the simulatedaddress. For instance, if the address mentioned in the MIPS testing file is 500000_hex (suchas lw, where we want to load the data storing on 500000_hex), then, you should access it atreal address of: (real_mem + 500000_hex - 400000_hex).The dynamically allocated 6MB memory block is pointing at the start of your text segment,and your text segment will be 1MB in size. The end of text segment will be at simulatedaddress 400000_hex+1MB, or at address real_mem+1MB.The static data segment will start at simulated address 500000_hex, or at real address(real_mem+1MB).The dynamic data segment will start at wherever your static data section ends.The stack segment will start at the highest address 1000000_hex (real_mem+6MB), and itgrows downwards (whenever you put things in there, the address decreases).You should also simulate the registers. The registers should not be a part of your simulatedmemory. Recall that registers are in CPU. In this project, you are not accessing the real registers,however, you will allocate memory for the 32 general purpose registers, which are:Your code should initiate the registers as described by its functionality. For example, the stackpointer register, $sp, should always store the current stack top. You should initialize it with a valueof 1000000_hex.3.3.3 Putting things in the right placeYour simulator should take a MIPS file as input, and you should put everything in the right placebefore your simulation. After the simulated memory is ready, you will read a MIPS file, and:Put the data in .data segment of MIPS file piece by piece in the static data segment. Thewhole block (4 bytes) is assigned to a piece of data even if it is not full. For example:Here, each character of .asciiz type occupies 1 byte, so "hell" occupies the first block. The firsttwo bytes of the second block is used by "o" and a terminating sign "\0", but the last twobytes of the second block is not used. However, when we put the next piece of data in thememory, we start a new block. The data type .word occupies 4 bytes, so the third block isassigned to this piece of data.Assemble the .text segment of the MIPS file (section 3.2), and put the assembled machinecode in the text segment of your simulated memory (the first line of code has the lowestaddress). The assembled machine code is 32 bits, which is 4 bytes. Thus, you can translate itto a decimal number and store it as an integer.3.3.4 Start simulatingYour code should maintain a PC, which points to the first line of code in the simulated memory.Your code should have a major loop, simulating the machine cycle. Following the machine cycle,your code should be able to:Go to your simulated memory to fetch a line of machine code stored at the address PCindicates.PC=PC+4From the machine code, be able to know what the instruction is and do the correspondingthings.The third step of the machine cycle requires you to write a C/C++ function for each instruction todo what it's supposed to. For example, for the add instruction, we can write in C:In the third step of the machine cycle, when we read a line of machine code and thecorresponding instruction is add , we can simply call the function.Miscellaneous.datastr1: .asciiz "hello"int1: .word 1in memory:| hell | o\0-- | 1 |void add (int rs, int rt, int* rd){rd = rs+ *rt;}4.1 DeadlineThe deadline of this project is 3/21/2021 midnight.4.2 SubmissionYou should put all of your source files in a folder and compress it in a zip. Name it with yourstudent ID. Submit it through BB.4.3 GradingThis project worth 30% of your total grade. The grading details of this project will be:Assembling - 20%Memory & register simulation - 30%Proper MIPS execution - 40%Each unsuccessful MIPS instruction will result in 3% deduction.Report - 10%NOTICE: If your code does not support makefile/cmake, you will lose 50% automatic.4.4 ReportThe report of this project should be no longer than 5 pages.In your report, you should write:Your big picture thoughts and ideas, showing us you really understand how are MIPSprograms executed in computers. (This part should be the major part of your report.)The high level implementation ideas. i.e. how you break down the problem into smallproblems, and the modules you implemented, etc.The implementation details. i.e. what structures did you define and how are they used.In your report, you should not:Include too many screenshots your code.Copy and paste others' report.4.5 HonestyWe take your honesty seriously. If you are caught copying others' code, you will get anautomatic 0 in this project. Please write your own code.WX:codehelp

March 29, 2022 · 11 min · jiezi

关于c++:CS-120-C项目

CS 120 Module 1 Open-Ended Project: Style and ErrorsDue on Gradescope by 11:59pm ET on Friday, February 19thFor this project, you will create two differently-styled versions of a creative C++ class on GitHub and will document the bugs you found in the code.Requirements ? All of your programming files should be in a private GitHub repository in the course organization. Your repository must be named with the convention: M1OEP-Style-Errors-netid, where netid is your UVM NetID username.The repository should have a .gitignore file and a README file (see the GitHub-with-CLion repo for directions).? Your C++ class must have at least two private fields and at least four methods. ? Your class should be nontrivial: at least one method must not be a constructor, getter, setter, or destructor. ? Your class declaration should be in a header file and the implementation in a corresponding .cpp file.? You must use objects of the class to create a fully functioning program in a main.cpp file. Describe your program in your README file.? Your two style versions should be stored in different branches of your repository.? Your README must describe which of the two styles you like better and why. ? The README file must also detail at least three errors that you experienced while developing this project.At least one must be a compiler error and at least one must not.For each bug, explain what you did to fix it.At least one of these explanations should include the use of the debugger.? All of the above must be pushed to your GitHub repository. ? On Gradescope, submit the URL of the repository. The last commit to each branch will be graded. If you have more than two branches, clarify which ones should be graded in the master branch README file.Design Your two style versions must include the following (you can choose how to split the options between the two versions, and each version should have consistent style within itself):Hanging and Egyptian-style bracesCamel case and snake caseTop-of-file comments and method commentsVariables with and without prefixesFor details on these, see the M1GP-Style-Me repository README file.Grading The project is out of 50 points. 5 pts Project compiles and runs. GitHub repository set up as described above. 5 pts Class satisfies requirements described above.pts Style 1 satisfies requirements and is consistent throughout the files.pts Style 2 satisfies requirements and is consistent throughout the files.pts The main program is fully functional.pts The README file contains all that is described above.如

March 29, 2022 · 2 min · jiezi

关于c#:LeetCode-C4寻找两个正序数组的中位数

开发工具与关键技术: C#作者:奶糖不甜撰写工夫:2022.2.27C#是微软公司公布的一种由C和C++衍生进去的面向对象的编程语言、运行于.NET Framework和.NET Core之上的高级程序设计语言.并定于在微软职业开发者论坛(PDC)上登台亮相。C#是微软公司研究员Anders Hejlsberg的最新成绩.C#看起来与Java有着惊人的类似;它包含了诸如繁多继承、接口、与Java简直同样的语法和编译成中间代码再运行的过程.然而C#与Java有着显著的不同,它借鉴了Delphi的一个特点,与COM是间接集成的,而且它是微软公司 .NET windows网络框架的配角.题目形容:给定两个大小别离为 m 和 n 的正序(从小到大)数组 nums1 和 nums2。请你找出并返回这两个正序数组的 中位数 。 算法的工夫复杂度应该为 O(log (m+n)) 。 示例:输出:nums1 = [1,2], nums2 = [3,4]输入:2.50000解释:合并数组 = [1,2,3,4] ,中位数 (2 + 3) / 2 = 2.5 合并排序解法:先将两个数组num1和num2合并为同一数组,如何将其进行排序。用除法返回中位数的下标地位,进行输入。 public class Solution { public double FindMedianSortedArrays(int[] nums1, int[] nums2) { List<int> list = new List<int>(nums1); list.AddRange(nums2); list.Sort(); int n = nums1.Length; int m = nums2.Length; int len = n + m; var r = len / 2; if(len % 2 == 0){ return (list[r - 1] + list[r]) / 2.0; } else if(len % 2 != 0){ return list[r]; } else{ return 0; } throw new System.Exception("Failure"); }}注:先将数组注入表List当中函数List.AddRange()为将注入合并另一表函数List.Sort()为将list表进行排序 ...

March 28, 2022 · 1 min · jiezi

关于c:从Minix中学到的C语言小技巧

在global.h中应用EXTERN申明全局变量,代码如下: #define EXTERN extern#ifdef TABLE #undef EXTERN #define EXTERN#endifEXTERN i32_t tty_pos;EXTERN u8_t gdt_info[6];EXTERN gdesc_t gdt[GDT_SIZE];在table.c中定义TABLE宏,并蕴含global.h,可使得所有的全局变量在table.c中定义,代码如下: #define TABLE/* 所有全局变量在此文件中定义 */#include "global.h"而所有其余蕴含global.h的C文件只蕴含全局变量的申明。

March 28, 2022 · 1 min · jiezi

关于c++:DeepRoute-Lab-C性能CPU-Cache-Serial-1

性能C++,作为最艰涩、最难把握的支流编程语言,一贯是容易上手,却很难写好。而这难写好的局部中,除了代码格调等稍微形象的局部,最难也最容易忽略的局部则是性能了。依据经典的二八准则,通常20%左右的代码耗费了80%左右的性能。然而,用户日常接触到的性能、或者在日常应用的场景下,性能是能够满足的,因而这往往造成程序员的漠视并埋下了隐患。 通常状况下,一旦遇到性能问题,那将是比性能问题更辣手、更难解决的。 C++,作为常常和硬件间接打交道的高级语言,性能问题堪称是重灾区。本系列文章,将联合实践和实际,深度分析典型的性能问题和陷阱。 在上一篇性能专题的文章(点击可跳转上期文章)中,咱们具体地介绍了C++代码中的性能杀手【拷贝】,并提供了几类具备针对性的应答措施。然而作为须要时刻思考硬件条件的编程语言,如果你认为防止了不必要的结构和拷贝,就能够领有极致的性能的话,那就大错特错了。 让咱们来看一个与拷贝无关,然而又存在显著性能问题的例子。 举例 CPU Cache首先咱们须要介绍一下什么是CPU Cache。 在咱们写代码的时候,有3个计算机硬件和咱们关系密切,别离是CPU、内存和硬盘。为什么这样说呢?因为咱们敲的代码和编译进去的执行文件是存储在硬盘上的,每次程序启动,对应的数据和代码被加载进内存,而后各种各样的指令会在CPU中运行。 看似内存中的数据会被间接加载进CPU进行解决,而后这两头实际上还存在着一个至关重要的组件:缓存(CPU Cache)。缓存通常会存储着最近拜访过的内存中的数据(这就是大家相熟的LRU、LFU等缓存替换算法作用的中央),它领有远快于内存(RAM)的访问速度,然而容量也显著地小于内存,它能够被视作CPU和内存数据的桥梁。 同时,CPU Cache也有不同的品种,次要有D-Cache,I-Cache和TLB。其实只有晓得全名,就很好了解了。D-Cache全名data cache,用来缓存数据。I-Cache全名instruction cache,用来缓存CPU指令。TLB全名translation lookaside buffer,用来缓存虚拟内存到物理内存的映射后果。 TLB看似让人摸不着头脑,然而有一个好消息是:如果D-Cache和I-Cache可能被很好地利用,那么TLB的性能通常也能从中受害。 I-Cache呢,在小片代码中区别不会太大,而且编译器会帮忙做肯定的优化,因而咱们最首要思考的就是D-Cache,它和咱们写代码的形式具备最严密的分割。 以一个6核12线程CPU为例, Cache的构造大抵如下: 能够看到,每个物理外围领有2个硬件线程,每个线程领有本人的L1 Cache,每个外围领有本人的L2 Cache,所有外围共享L3 Cache和内存。(请记住这个构造,前面的剖析都会基于此) 那么,这些CPU Cache具体是怎么影响咱们代码的性能的呢? 前文中咱们提到了,CPU Cache是CPU和内存之间的桥梁并且领有多个档次,可能此时咱们曾经发现,如果每一级缓存领有不同的访问速度,是不是就会导致拜访同样的数据(这些雷同的数据可能因为之前的拜访形式坐落于不同级的缓存和内存中)耗费不同的工夫?答案是必定的,下图中能够看到一个典型的古代CPU各个硬件的访问速度。能够看到,L1 Cache的访问速度根本是内存的100倍以上,L2 Cache则是10倍以上。 因而,整体上来看,越高的缓存命中率意味着程序具备越高的性能。所谓缓存命中率,直白地说,就是指原本要去内存中读取的数据,正好存在于缓存中的比例。 那么,是什么样的起因会导同样的数据在不同的拜访模式下会坐落于不同层级的缓存中呢?这就不得不提到缓存的存储形式和根本单元了。 CPU Cache的根本单元叫做cache line,这些cache line中存储的就是内存中的hottest data。内存和Cache替换数据都是通过它。对于典型的古代处理器,cache line的大小通常都是64 bytes,意味着,每一条cache line能够存储8个64位的整型。到目前为止,所有看上去都那么失常。 然而,cache line有一个十分非凡的性质,就是它的读写必须操作一整条!比方,你只想读前8个bytes,对不起,不行,整条cache line都会被读取;你只想写最初8个bytes,对不起,不行,整个cache line都须要更新。 缓存局部性(Cache locality)有了下面对于CPU Cache的介绍,咱们能够剖析为什么例1中拜访二维数组的形式会对性能有如此大的影响了。以下剖析咱们思考冷启动的模式,意即缓存最开始是空的,外面没有任何数据。 留神到,咱们的二维数组中存储的数据类型为整型,每个元素的大小为8 bytes,因而一条大小为64 bytes的cache line能够存储8个数据。 如果咱们一行一行地拜访二维数组数组,第一次读取缓存的某条cache line的时候,数据不在缓存上,须要从内存中读取,因而这次是一次cache miss,CPU读取这条数据的耗时是 t_memory + t_cache。然而请留神,因为cache line的个性,它的操作必须是整条的,因而在t_memory 的这次耗费中,在内存上相邻的另外7个int64型的数据也被加载到了这条cache line中。因为咱们是按行读取,前面拜访的7个数据正好就是被加载进了cache line的数据,他们的读取工夫都只须要t_cache,省去了7次t_memory 的高额开销。 在这种状况下,每读取8个元素的总工夫开销就是 t_memory + 8 t_cache。以上图中的硬件为例,仅思考L2 Cache,即100 + 8 7 = 156ns。 ...

March 28, 2022 · 1 min · jiezi

关于c:CMPSC473-Malloc-Lab

CMPSC473, Spring 2021Malloc Lab: Writing a Dynamic Storage AllocatorAssigned: Feb. 16Checkpoint 1 Due: Sun., Feb. 28,11:59:59 PMCheckpoint 2 Due: Sat., Mar. 06,11:59:59 PMDue: Fri., Mar. 12, 11:59:59PMPlease read this document carefully!1 IntroductionIn this lab, you will be writing a dynamic storage allocator for C programs, i.e., your own version of the malloc,free, and realloc functions. You are encouraged to explore the design space creatively and implement an allocatorthat is correct, space efficient, and fast.The only file you will be modifying is mm.c. Modifications in other files will not be used in the grading. You will beimplementing the following functions:• bool mm init(void)• void* malloc(size t size)• void free(void* ptr)• void realloc(void oldptr, size t size)• bool mm checkheap(int lineno)You are encouraged to define other (static) helper functions, structures, etc. to better structure your code.2 Programming Rules• IMPORTANT: You are required to implement a heap checker (see Section 5) that will be graded. Theheap checker will help you debug your code.• IMPORTANT:You are required to write commentsfor all of your code including the heap checker. Additionally,you need to write a file comment at the top of the file describing your overall malloc design. SeeSection 7 for grading details.• IMPORTANT: You must show your partial work on this assignment by periodically committing andsubmitting (i.e., pushing) your code to git. This will be used both for grading the checkpoints as well asensuring academic integrity.• You are not allowed to change any of the interfaces inmm.c.2• You are not allowed to invoke any memory-management related library calls or system calls. For example, youare not allowed to use sbrk, brk, or the standard library versions of malloc, calloc, free, or realloc.Instead of sbrk, you should use our provided mem sbrk.• Your code is expected to work in 64-bit environments, and you should assume that allocation sizes and offsetswill require 8 byte (64-bit) representations.• You are not allowed to use macros as they can be error-prone. The better style is to use static functions and letthe compiler inline the simple static functions foryou.• You are limited to 128 bytes of global space for arrays, structs, etc. If you need large amounts of space forstoring extra tracking data, you can put it in the heaparea.• IMPORTANT: Failure to abide by these requirements may result in a 0 for the assignment.3 Description of the dynamic memory allocator functions• mm init: Before calling malloc, realloc, calloc, or free, the application program (i.e., the tracedrivendriver program that will evaluate your code) calls your mm init function to perform any necessaryinitializations, such as allocating the initial heap area. The return value should be true on success and false ifthere were any problems in performing the initialization.• malloc: The malloc function returns a pointer to an allocated block payload of at least size bytes. Theentire allocated block should lie within the heap region and should not overlap with any other allocated chunk.If the requested size is 0 or if mem sbrk is unable to extend the heap, then you should return NULL. Similarto how the standard C library (libc) always returns payload pointers that are aligned to 16 bytes, your mallocimplementation should do likewise and always return 16-byte alignedpointers.• free: The free function frees the block pointed to by ptr. It returns nothing. This function is onlyguaranteed to work when the passed pointer (ptr) was returned by an earlier call to malloc, calloc, orrealloc and has not yet been freed. If ptr is NULL, then free should do nothing.• realloc: The realloc function returns a pointer to an allocated region of at least size bytes with thefollowing constraints.– if ptr is NULL, the call is equivalent to malloc(size);– if sizeis equal to zero, the call is equivalent to free(ptr);– if ptr is not NULL, it must have been returned by an earlier call to malloc, calloc, or realloc.The call to realloc changes the size of the memory block pointed to by ptr (the old block) to sizebytes and returns the address of the new block. Notice that the address of the new block might be the sameas the old block, or it might be different, depending on your implementation, the amount of internalfragmentation in the old block, and the size of the reallocrequest.The contents of the new block are the same as those of the old ptr block, up to the minimum of the oldand new sizes. Everything else is uninitialized. For example, if the old block is 8 bytes and the new blockis 12 bytes, then the first 8 bytes of the new block are identical to the first 8 bytes of the old block and thelast 4 bytes are uninitialized. Similarly, if the old block is 8 bytes and the new block is 4 bytes, then thecontents of the new block are identical to the first 4 bytes of the oldblock.These semantics match the the semantics of the corresponding libc malloc, realloc, and free functions. Runman malloc to view complete documentation.34 Support FunctionsThe memlib.c package simulates the memory system for your dynamic memory allocator. You can invoke thefollowing functions in memlib.c:• void* mem sbrk(int incr): Expands the heap by incr bytes, where incr is a positive non-zero integer.It returns a generic pointer to the first byte of the newly allocated heap area. The semantics are identicaltothe Unix sbrk function, except that mem sbrk accepts only a non-negative integer argument.You must use our version, mem sbrk, for the tests to work. Do not use sbrk.• void* mem heap lo(void): Returns a generic pointer to the first byte in the heap.• void* mem heap hi(void): Returns a generic pointer to the last byte in the heap.• size_t mem heapsize(void): Returns the current size of the heap in bytes.• size_t mem pagesize(void): Returns the system’s page size in bytes (4K on Linux systems).• void memset(void ptr, int value, size t n): Sets the first n bytes of memory pointed toby ptr to value.• void memcpy(void dst, const void* src, size t n): Copies n bytes from src to dst.5 Heap Consistency CheckerDynamic memory allocators are notoriously tricky beasts to program correctly and efficiently. They are difficult toprogram correctly because they involve a lot of untyped pointer manipulation and low-level manipulation of bits andbytes. You will find it very helpful to write a heap checker mm checkheap that scans the heap and checks it forconsistency. The heap checker will check for invariants which should always be true.Some examples of what a heap checker might check are:• Is every block in the free list marked asfree?• Are there any contiguous free blocks that somehow escapedcoalescing?• Is every free block actually in the free list?• Do the pointers in the free list point to valid free blocks?• Do any allocated blocks overlap?• Do the pointers in a heap block point to valid heapaddresses?You should implement checks for any invariants you consider prudent. It returns true if your heap is in a valid,consistent state and false otherwise. You are not limited to the listed suggestions nor are you required to check all ofthem. You are encouraged to print out error messages when the check fails. You can use dbg printf to printmessages in your code in debug mode. To enable debug mode, uncomment the line #define DEBUG.To call the heap checker, you can use mm checkheap( LINE ), which will pass in the line number of the caller.This can be used to identify which line detected a problem.You are required to implement a heap checker for your code, both for grading and debugging purposes. SeeSection 7 for details on grading.46 Testing your codeFirst, you need to compile/build your code by running: make. You need to do this every time you change your codefor the tests to utilize your latest changes.To run all the tests after building your code, run: make test.To test a single trace file after building your code, run: ./mdriver -f traces/tracefile.rep.Each trace file contains a sequence of allocate, reallocate, and free commands that instruct the driver to call yourmalloc, realloc, and freefunctions in some sequence.Other command line options can be found by running: ./mdriver -hTo debug your code with gdb, run: gdb mdriver.7 EvaluationYou will receive zero points if:• you break any of the programming rules in Section2• your code does not compile/build• your code is buggy and crashes the driverOtherwise, your grade will be calculated as follows:50 pts Checkpoint 1 (Due: Sun., Feb. 28, 11:59:59 PM): This part of the assignment simply tests the correctness of yourcode. Space utilization and throughput will not be tested in this checkpoint. Your grade will be based on thenumber of trace files that succeed.100 pts Checkpoint 2 (Due: Sat., Mar. 06, 11:59:59 PM): This part of the assignment requires that your code is entirelyfunctional and tests the space utilization (60 pts) and throughput (40 pts) of your code. Each metric will have amin and max target (i.e., goal) where if your utilization/throughputis above the max, you get full score and if itis below the min, you get no points. Partial points are assigned proportionally between the min and max.– Space utilization (60 pts): The space utilization is calculated based on the peak ratio between the aggregateamount of memory used by the driver (i.e., allocated via malloc or realloc but not yet freed via free)and the size of the heap used by your allocator. You should design good policiesto minimize fragmentationin order to increase this ratio.– Throughput (40 pts): The throughput is a performance metric that measures the average number ofoperations completed per second. As the performance of your code can vary between executions andbetween machines, your score as you’re testing your code is not guaranteed. The performance testingwill be performed on the W204 cluster machines to ensure more consistent results.100 pts Final submission (Due: Fri., Mar.12, 11:59:59 PM): This part of the assignment is graded identically as Checkpoint2, except that the grading curve has not been significantly reduced as is the case with Checkpoint 2.50 pts Code demo and comments (Due: Fri., Mar. 12, 11:59:59 PM): As part of the final submission, we will bereviewing your heap checker code and commentsthrough your code. You will need to upload a 4-5 minutedemo video describing your design choice, data structures and heap checker code and upload it on canvas(one demo video per team). The TAs can ask you to schedule an appointment to meet them via zoom toanswer additional questions about your project after the deadline, if necessary. Your heap checker will begraded based on correctness, completeness, and comments. The comments should be understandable to aTA. The demo will show correctness. Your explanation of the heap checker and your malloc design willdetermine the degree to which your checker is checking invariants.5There will be a balance between space efficiency and speed (throughput),so you should not go to extremes to optimizeeither the space utilization or the throughput only. To receive a good score, you must achieve a balance betweenutilization and throughput.Grades will be assigned by running your code on W204 machines. So, please check that your code runs on thosemachines.8 Handin InstructionsYou must show your partial work on this assignment by periodically committing and submitting (i.e., pushing) yourcode to git. To do this, run:git add mm.cgit commit -m "Write a comment here about your code changes"git pushWe will use the latest submission before each deadline as well as the latest submission before each late deadline forgrading purposes. Each checkpoint and final submission can use the late policy, and we will calculate and use thebetter of the normal score and the late score with the late penalty. Thus, make sure you are committing and submittingto git often. If you want to specify a commit for a specific checkpoint, write it in your readme file.You have to submit your demo video as an assignment (Project 2) on Canvas.Additionally, you must submit your github username that you used for the assignment in Canvas (Youshould have done this for project 1. No need to re-submit.).9 Hints• Use the mdriver -f option. During initial development, using tiny trace files will simplify debugging andtesting. We have included some trace files ending in -short.rep that you can use for initial debugging.• Write a good heap checker. This will help detect errors much closer to when they occur. This is one of the mostuseful techniques for debugging data structures like the malloc memory structure.• Use gdb; watchpoints can help with finding corruption. gdb will help you isolate and identify out of boundsmemory references as well as where in the code the SEGFAULT occurs. To assist the debugger, you may wantto compile with make debug to produce unoptimized code that is easier to debug. To revert to optimizedcode, run make release for improved performance. Additionally, using watchpoints in gdb can help detectwhere corruption is occurring if you know the address that is being corrupted.• The textbooks have detailed malloc examples that can help your understanding. You are allowed to referenceany code within the textbooks as long as you cite the source (as comment in your code). However, directlycopying code from online source is strictly forbidden.• Encapsulate your pointer arithmetic and bit manipulation in static functions. Pointer arithmetic in yourimplementation can be confusing and error-prone because of all the casting that is necessary. You can reducethe complexity significantly by writing static functions for your pointer operations and bit manipulation. Thecompiler should inline these simple functions for you.• Use git to track your different versions. git will allow you to track your code changes to help you rememberwhat you’ve done in the past. It can also provide an easy way to revert to prior versions if you made a mistake.• Use the mdriver -v and -V options. These options allow extra debug information to be printed.• Start early! Unless you’ve been writing low-level systems code since you were 5, this will probably be some ofthe most difficult and sophisticated code you have written so far in your career. So start early, and good luck! ...

March 28, 2022 · 11 min · jiezi

关于c++:CC气象数据中心实战手把手教你做工业级项目吾爱fen享

前言:download:C/C++气象数据中心实战,手把手教你做工业级我的项目吾爱 复制下载资源课程:https://www.97yrbl.com/t-991.htmlc语言入门C语言一经呈现就以其功能丰富、表达能力强、灵便不便、利用面广等特点迅速在全世界遍及和推广。C语言岂但执行效率高而且可移植性好,能够用来开发应用软件、驱动、操作系统等。C语言也是其它泛滥高级语言的鼻祖语言,所以说学习C语言是进入编程世界的必修课。 hello,world#include<stdio.h> int main(){ /*在双引号两头输出Hello World*/ printf("Hello World"); return 0; }注:在最新的C规范中,main函数前的类型为int而不是void c语言的具体构造简略来说,一个C程序就是由若干头文件和函数组成。 mark #include <stdio.h>就是一条预处理命令, 它的作用是告诉C语言编译系统在对C程序进行正式编译之前需做一些预处理工作。函数就是实现代码逻辑的一个小的单元。必不可少之主函数一个C程序有且只有一个主函数,即main函数。 markC程序就是执行主函数里的代码,也能够说这个主函数就是C语言中的惟一入口。而main后面的int就是主函数的类型.printf()是格局输入函数,这里就记住它的性能就是在屏幕上输入指定的信息return是函数的返回值,依据函数类型的不同,返回的值也是不同的。\n是转义字符中的换行符。(留神:C程序肯定是从主函数开始执行的)良好习惯之标准一个阐明或一个语句占一行,例如:蕴含头文件、一个可执行语句完结都须要换行。函数体内的语句要有显著缩进,通常以按一下Tab键为一个缩进。括号要成对写,如果须要删除的话也要成对删除。当一句可执行语句完结的时候开端须要有分号。代码中所有符号均为英文半角符号。mark程序解释——正文正文是写给程序员看的,不是写给电脑看的。 C语言正文办法有两种: `多行正文: / 正文内容 /单行正文: //正文一行` 有名有姓的C(标识符)C语言规定,标识符能够是字母(A~Z,a~z)、数字(0~9)、下划线_组成的字符串,并且第一个字符必须是字母或下划线。在应用标识符时还有留神以下几点: 标识符的长度最好不要超过8位,因为在某些版本的C中规定标识符前8位无效,当两个标识符前8位雷同时,则被认为是同一个标识符。标识符是严格辨别大小写的。例如Imooc和imooc 是两个不同的标识符。标识符最好抉择有意义的英文单词组成做到"见名知意",不要应用中文。标识符不能是C语言的关键字。想理解更多C语言关键字的常识。变量及赋值变量就是能够变动的量,而每个变量都会有一个名字(标识符)。变量占据内存中肯定的存储单元。应用变量之前必须先定义变量,要辨别变量名和变量值是两个不同的概念。 mark变量定义的个别模式为:数据类型 变量名;多个类型雷同的变量:数据类型 变量名, 变量名, 变量名...;mark留神:在定义中不容许间断赋值,如int a=b=c=5;是不非法的。 变量的赋值分为两种形式: 先申明再赋值申明的同时赋值根本数据类型C语言中,数据类型可分为:根本数据类型结构数据类型指针类型空类型四大类

March 27, 2022 · 1 min · jiezi

关于c#:C速成指南从入门到进阶实战WPF与Unity3D开发吾爱

下栽地止:https://lexuecode.com/4375.htmlC#基础知识根底语法你如果后期学习过C语言的话,那么学习C#基础知识就会感觉很容易,特地好了解。在这个环节你须要认真学习基础知识,你得学会在保障语法不报错的状况下,利用基础知识写一些简略的算法;得纯熟理解语法,应用切当并能够实现一些逻辑代码。 (根底语法、数据类型、变量、循环、办法、数组、汇合、判断、类等) 面向对象开发C语言是面向过程的开发语言,而C#是面对对象的开发语言,在应用C语言写逻辑代码时都是能够依照肯定的顺利逻辑将其实现就OK,而C#就不一样,你在学习语法,实现业务逻辑时得思考程序的可扩展性,鲁棒性等。 你得领有抽象思维,能够将事实中无生命体征的物品进行拟物解决,将它们进行更为形象的提炼,汇总为某个非凡类,让其这个类代表这类物品,并让其领有这个物品的所有属性和行为,这就是面向对象开发。 (继承、封装、多态、接口、抽象类等) 这一部分的学习比拟形象,学会领有抽象思维,让本人能够更好的了解这些知识点。 基础知识进阶这里你将会学习一些高端的编程玩法,可能短期内,你无奈应用到,然而它们更多体现在你的职业前期,当你理论应用框架或者浏览源码的过程中,都会遇到这些知识点,并有可能被它困住。 C#速成指南:从入门到进阶,实战WPF与Unity3D开发集成开发环境Visual Studio 构造using System;蕴含 System 命名空间 class hello{ /正文/ static void Main(string\[\] args){ //一个文件一个main函数}}构造体struct Books{变量...}构造不反对继承。构造不能申明默认的构造函数 枚举enum Day { Sun, Mon, tue, Wed, thu, Fri, Sat };Day.Sun==0 Day.Mon==1 接口public interface PaintCost {int getCost(int area);}派生类class Rectangle : hello, PaintCost{}全析namespace first{命名空间申明 public class Test{能够多个class构造函数、析构函数、动态成员... 变量... decimal a=10;128 位准确的十进制值,28-29 有效位数 sbyte b=2;8 位有符号整数类型 uint c;32 位无符号整数类型 ulong d;64 位无符号整数类型 ushort e;16 位无符号整数类型 ...

March 27, 2022 · 3 min · jiezi

关于c++:EE2028A-重点分析

EE2028A C ProgrammingLab Exercise 4Submission instructions: Test your code on your computer first before submitting.You must use the code skeleton provided fro Question 1.Feel free to write as many functions as needed for Question 2.Deadline: Wednesday, February 24th / Friday, February 26thConcepts used: Structures, Pointers, Decision-making statements, loops and C Functions.Question 1: [30 Marks]Let us work on the menu of a library. Create a structure containing book information likeaccession number, name of author, book title and flag to know whether a book is issued or not.Create an interactive menu in which the following can be done.Display book informationAdd a new bookDisplay all the books in the library of a particular authorDisplay the number of books of a particular titleDisplay the total number of books in the libraryIssue a book(If we issue a book, then its number gets decreased by 1 and if we add a book, its number getsincreased by 1)To guide your answer, you can follow the code skeleton provided bellow:12Sample Output:Further Instructions:• As shown in the screen-shot above, the initial number of books in the library is 0• Displaying a book’s information should include its four attributes (shown in skeleton code).Use proper printf messages (no standard format is enforced).• Similarly, for adding a book, prompt the user for all four attributes with proper I/O.• For displaying all books of a given author, first prompt the user for the author’s name, thenuse the same display format in question 1 for all books of that author.• Displaying the total number of books in the library should exclude all books for which theissued flag was set to 1• For your report, add at least 5 books to your library and take screenshots demonstratingeach of the Menu’s options.3Question 2: [20 Marks]Consider a five-element integer array, answer the following questions in order. You can eithertake a user input of the array in the range [-9 ; 9] OR hard-code a five-element array in therange [-9 ; 9].1) Write the appropriate code to generate all sub-arrays with at least 2 elements of agiven input array. A subarray is defined as an array that is generated from a given array.Thus, a subarray comprises elements from the given array, and is of smaller length.For example, for a given array [7, 2, -1, 2], bellow is the expected I/O:Note that the sample I/O above is for format illustration purposes only. Your actualanswer needs to handle five-element integer arrays.2) In the example above, if you consider two-element sub-arrays, possible pairs include thefollowing shown in the table below. Observe that (7,2) is listed twice, one for eachoccurrence of 2. Consider each subarray from your list of all generated subarrays with at4least 2 elements, and perform the sum of products for each subarray as shown in theexample above in the table. The sum of products is calculated by considering only theproducts of the pairs (i.e. for sub-array [7, 2, -1], the sum of products is [7x2] + [7x(-1)] +[2x(-1)] = 5. Modify your code from question 1 to match the sample output bellow:3) Complete the function “largestValue” which takes an array and returns an integerdenoting the largest value of the “sum of products” of any of the sub-arrays generatedfollowing guidelines from questions 1&2. Continuing on the same example, your outputshould look like this:5For your report, take screenshots of your final answer to Q3 only as illustrated above. You arerequired to report on three runs of your program with the following inputs:• 8 4 -2 6 -5• -9 4 3 -1 2• 5 -5 0 3 -9

March 26, 2022 · 3 min · jiezi

关于c#:C速成指南从入门到进阶实战WPF与Unity3D开发吾爱fen享

C#学习路线指南下哉课程ZY: https://www.97yrbl.com/t-1374...题记最近本人始终在想,一个初学者刚开始应该学些什么,该学习到哪种水平找工作才不成问题,能力在做我的项目时熟能生巧不被Bug所困住。 破费了几天工夫整顿了C#学习路线图,能够说是纯家养C#程序员成长路线布局,在这里分享下,心愿能够帮忙到想从事C#开发的同学们。自己经历尚浅,有些知识点可能分享不正确,心愿宽广网友评论区补充,我会同步修改更新。是不是每一个初学者在刚开始学习任何一门编程语言的时候,都会有这样的疑难,都感觉无从下手,没有脉络。反正我过后的确有这样的困惑,在刚开始接触编程的时候,过后幸好有实验室学长和老师的倡议,才缩小了试错老本,能够把更多工夫都破费在正确的事件上,学习效率才会高。 依据我过后的学习状况和当初目前市场上的行情来剖析,列举出新手学习C#编程语言路线指南,心愿对你有帮忙。计算机根底 如果你是本科生的话,在校期间,应该会学习计算机根底,C语言,计算机组成原理,操作系统等对于计算机的课程,我心愿你好好学习,尤其是C语言,它是一种特地容易入门上手和理解编程思维的语言,是面向过程式的开发,首先你得学会应用它的语法做一些简略的逻辑运算,其次能够依据肯定的需要,实现局部非凡算法的演练(这些对你前期学习面向对象开发语言有很大的帮忙)。如果没有开设这些课程,那么就须要你花工夫去互联网上找相干视频去学习。 C#基础知识根底语法你如果后期学习过C语言的话,那么学习C#基础知识就会感觉很容易,特地好了解。在这个环节你须要认真学习基础知识,你得学会在保障语法不报错的状况下,利用基础知识写一些简略的算法;得纯熟理解语法,应用切当并能够实现一些逻辑代码。 (根底语法、数据类型、变量、循环、办法、数组、汇合、判断、类等) 面向对象开发C语言是面向过程的开发语言,而C#是面对对象的开发语言,在应用C语言写逻辑代码时都是能够依照肯定的顺利逻辑将其实现就OK,而C#就不一样,你在学习语法,实现业务逻辑时得思考程序的可扩展性,鲁棒性等。 你得领有抽象思维,能够将事实中无生命体征的物品进行拟物解决,将它们进行更为形象的提炼,汇总为某个非凡类,让其这个类代表这类物品,并让其领有这个物品的所有属性和行为,这就是面向对象开发。 (继承、封装、多态、接口、抽象类等) 这一部分的学习比拟形象,学会领有抽象思维,让本人能够更好的了解这些知识点。 基础知识进阶这里你将会学习一些高端的编程玩法,可能短期内,你无奈应用到,然而它们更多体现在你的职业前期,当你理论应用框架或者浏览源码的过程中,都会遇到这些知识点,并有可能被它困住。 (Linq、泛型、委托、事件、多线程、Socket开发)

March 26, 2022 · 1 min · jiezi

关于c++:C的移动构造函数和移动赋值运算符

什么是挪动结构在 C++ 11 规范之前(C++ 98/03 规范中),如果想用其它对象初始化一个同类的新对象,只能借助类中的复制(拷贝)构造函数。在C++11中,引入了右值援用,提供了左值转右值的办法,防止了对象潜在的拷贝。而挪动构造函数和挪动赋值运算符也是通过右值的属性来实现的。直观的来讲,挪动结构就是将对象的状态或者所有权从一个对象转移到另一个对象。只是转移,没有内存的搬迁或者内存拷贝所以能够进步利用效率,改善性能。 右值和左值CPU视角的右值和左值通过一个最简答的程序来看一下CPU是如何对待左值和右值的。 void push(int && x){ int y = x;}void push(int & x){ int y = x;}下面程序对应的汇编代码为: push(int&&): push rbp mov rbp, rsp mov QWORD PTR [rbp-24], rdi mov rax, QWORD PTR [rbp-24] mov eax, DWORD PTR [rax] mov DWORD PTR [rbp-4], eax nop pop rbp retpush(int&): push rbp mov rbp, rsp mov QWORD PTR [rbp-24], rdi mov rax, QWORD PTR [rbp-24] mov eax, DWORD PTR [rax] mov DWORD PTR [rbp-4], eax nop pop rbp ret能够看到汇编指令对于右值和左值的解决是完全相同的,因而无论是左值和右值在CPU看来都是完全相同的。 ...

March 25, 2022 · 1 min · jiezi

关于c:C速成指南从入门到进阶实战WPF与Unity3D开发

download:C#速成指南:从入门到进阶,实战WPF与Unity3D开发备链:https://www.97yrbl.com/t-1374.html 新的计划咱们奇妙地将 FFi 计划与外接纹理计划组合,解决了一系列业务痛点。 FFI正如结尾说的那些问题,Texture 计划有些做不到的事件,这须要其余计划来互补,这其中外围须要的就是 ui.Image。咱们把 native 内存地址、长度等信息传递给 flutter 侧,用于生成 ui.Image。 首先 native 侧先获取必要的参数(以 iOS 为例): _rowBytes = CGImageGetBytesPerRow(cgImage);CGDataProviderRef dataProvider = CGImageGetDataProvider(cgImage);CFDataRef rawDataRef = CGDataProviderCopyData(dataProvider);_handle = (long)CFDataGetBytePtr(rawDataRef);NSData *data = CFBridgingRelease(rawDataRef);self.data = data;_length = data.length;dart 侧拿到后,@override FutureOr<ImageInfo> createImageInfo(Map map) {Completer<ImageInfo> completer = Completer<ImageInfo>();int handle = map['handle'];int length = map['length'];int width = map['width'];int height = map['height'];int rowBytes = map['rowBytes'];ui.PixelFormat pixelFormat = ui.PixelFormat.values[map['flutterPixelFormat'] ?? 0];Pointer<Uint8> pointer = Pointer<Uint8>.fromAddress(handle);Uint8List pixels = pointer.asTypedList(length);ui.decodeImageFromPixels(pixels, width, height, pixelFormat, (ui.Image image) { ImageInfo imageInfo = ImageInfo(image: image); completer.complete(imageInfo); //开释 native 内存 PowerImageLoader.instance.releaseImageRequest(options);}, rowBytes: rowBytes);return completer.future; }咱们能够通过 ffi 拿到 native 内存,从而生成 ui.Image。这里有个问题,尽管通过 ffi 能间接获取 native 内存,然而因为 decodeImageFromPixels 会有内存拷贝,在拷贝解码后的图片数据时,内存峰值会更加重大。 ...

March 22, 2022 · 1 min · jiezi

关于c#:MASA-Blazor入门这一篇就够了

1.什么是Blazor? 有什么劣势?ASP.NET Core Blazor 简介 Blazor 是一个应用 Blazor 生成交互式客户端 Web UI 的框架: 应用 C# 代替 JavaScript 来创立信息丰盛的交互式 UI。共享应用 .NET 编写的服务器端和客户端应用逻辑。将 UI 出现为 HTML 和 CSS,以反对泛滥浏览器,其中包含挪动浏览器。与旧式托管平台(如 Docker)集成。Blazor 劣势: 1. 应用 C# 代替 JavaScript 来编写代码。 2. 利用现有的 .NET 库生态系统。 3. 在服务器和客户端之间共享应用逻辑。 4. 受害于 .NET 的性能、可靠性和安全性。 5. 在 Windows、Linux 和 macOS 上应用 Visual Studio 放弃高效工作。 6. 以一组稳固、功能丰富且易用的通用语言、框架和工具为根底来进行生成。2.为什么抉择MASA Blazor?能用来干什么?MASA Blazor是一个基于 Blazor Component 和 Material Design 的 UI 组件库。 dotNET开发者不须要懂得javascript就能开发一个企业级中后盾零碎。 MASA Blazor劣势: 丰盛组件:蕴含Vuetify 1:1还原的根底组件,以及很多实用的预置组件和.Net深度集成性能,包含Url、面包 屑、导航三联动,高级搜寻,i18n等。UI设计语言:设计格调古代,UI 多端体验设计优良。繁难上手:丰盛具体的上手文档,收费的视频教程(制作中)。社区沉闷激励:用户参加实时互动,做出奉献退出咱们,构建最凋谢的开源社区。长期反对:全职团队保护,并提供企业级反对。业余示例:MASA Blazor Pro提供多种常见场景的预设布局。MASA Blazor Pro预设布局示例: ...

March 22, 2022 · 2 min · jiezi

关于c++:Linux知识读书笔记

Linux IO 子系统传统IO(读/写) CPU copy:用户buffer => 内核buffer ----------------------------------------> 拷贝* 1DMA copy:内核buffer => 硬件 ------------------------------------------------>拷贝 * 1上下文切换:用户态 => 内核态 => 用户态 ------------------------------------->上下文切换 * 2PageCache技术 Linux IO 栈 文件系统层:治理pagecache块层:治理块设施的IO队列,对IO申请进行合并、排序设施层:通过DMA和内存进行交互,负责数据传输IO形式: 传统 Buffer IO:磁盘 => pagecache => 用户空间 -------------------------------------------------------------------------> 拷贝 * 2mmaped- IO:磁盘 => pagecache =>映射到用户空间,把pagecache映射到用户的地址空间外面 -----------> 拷贝 * 1Direct IO:用户态和块IO层做对接,放弃了pagecache,从磁盘间接向用户态拷贝数据;益处:快,DMA拷贝,本人负责cache ----> 拷贝 * 1Buffer IO:偏移 + 长度mmaped IO:数据按页对齐Direct IO:读写是底层存储块设施大小的整数倍Linux内存地址空间 分段机制:逻辑地址 => 线性地址 GDT(段描述符)分页机制:线性地址 => 物理地址碎片 搭档零碎:将闲暇页分为11个链表,每个链表中页块中间断页的大小别离是1、2、4 .. 1024 申请:申请 4 ,看4 有:调配没有:看8,分成两个4,将另一半挂到块大小为4的链表下开释:看搭档是否闲暇,是则合并劣势:合并时地址只有一位不同,十分疾速定位slab零碎: slab 层有三个slab链表,slab-full、slab-partial、slab-empty每个链表有多个page,每个page都分为若干个object劣势: ...

March 21, 2022 · 1 min · jiezi

关于c#:3-堪比JMeter的Net压测工具-Crank-进阶篇-认识bombardier

1. 前言通过之前的学习,咱们曾经理解了各参数以及配置的意义,接下来的文章咱们别离从bombardier以及wrk动手,进一步理解彼此之间的分割 2. 意识 bombardierbombardier 是一个 HTTP(S) 基准测试工具。它是用 Go 编程语言编写的,并应用优良的fasthttp代替 Go 的默认 http 库,因为它具备闪电般的疾速性能,具体文档查看 其反对参数: -c, --connections=125 Maximum number of concurrent connections-t, --timeout=2s Socket/request timeout-l, --latencies Print latency statistics-m, --method=GET Request method-b, --body="" Request body-f, --body-file="" File to use as request body-s, --stream Specify whether to stream body using chunked transfer encoding or to serve it from memory --cert="" Path to the client's TLS Certificate --key="" Path to the client's TLS Certificate Private Key-k, --insecure Controls whether a client verifies the server's certificate chain and host name-H, --header="K: V" ... HTTP headers to use(can be repeated)-n, --requests=[pos. int.] Number of requests-d, --duration=10s Duration of test-r, --rate=[pos. int.] Rate limit in requests per second --fasthttp Use fasthttp client --http1 Use net/http client with forced HTTP/1.x --http2 Use net/http client with enabled HTTP/2.0-p, --print=<spec> Specifies what to output. Comma-separated list of values 'intro' (short: 'i'), 'progress' (short: 'p'), 'result' (short: 'r'). Examples: * i,p,r (prints everything) * intro,result (intro & result) * r (result only) * result (same as above)-q, --no-print Don't output anything-o, --format=<spec> Which format to use to output the result. <spec> is either a name (or its shorthand) of some format understood by bombardier or a path to the user-defined template, which uses Go's text/template syntax, prefixed with 'path:' string (without single quotes), i.e. "path:/some/path/to/your.template" or "path:C:\some\path\to\your.template" in case of Windows. Formats understood by bombardier are: * plain-text (short: pt) * json (short: j)并且bombardier反对多平台,能够在Windows、Linux、OSX零碎上运行,那接下来咱们应用bombardier测试一下百度的压测状况 ...

March 21, 2022 · 3 min · jiezi

关于c++:CMPUTC语言设计

CMPUT 379, Assignment 1, Winter 2021University of Alberta / Department of Computing ScienceObjectiveYou are asked to program a C function in a single source file with the following synopsis: struct memregion { void *from; void *to; unsigned char mode; / MEM_RW, or MEM_RO, or MEM_NO /};int get_mem_layout (struct memregion *regions, unsigned int size);When get_mem_layout() is called, it scans the entire memory area of the calling process and returns in regionsthe list of all the different regions comprising the process's address space. By region, we mean a contiguous areaof memory characterized by the same accessibility. Accessibility can have one of three possible values: MEM_RWmeaning read/write accessibility, MEM_RO meaning read-only accessibility, and MEM_NO meaning no accessibility atall (the process does not have memory assigned to it in the particular address range).In essence, your function should try to reference all locations in the address space of the process and find out 1)whether there is readable memory at the respective location or not, and 2) if there is readable memory, whether itis also writable. Note that there exists a unit of memory allocation called a page and for a given page size, itsuffices to determine the accessibility of a single location within each page. Thus, you don't actually have to scanall locations (for example, successive page base addresses will do).The function get_mem_layout() assumes that the output array regions exists and its size, i.e., the number ofentries, is equal to size. The function get_mem_layout() returns the actual number of memory regions locatedin the process's address space, even if it is larger than size. In the latter case, only the first size regions arereturned in the array. The regions must be stored in increasing order of their starting addresses. For eachmemregion, from represents the starting address of the region, and to represents the very last address of theregion. Note that get_mem_layout should NOT produce any output to stdout on its own.2 / 3Additionaly, you will write three driver programs (mem_1.c, mem_2.c, and mem_3.c). Each one of the driverprograms, first invokes the get_mem_layout() function, then prints the entries returned in memregion in ahumanly readable format, then performs a certain action (different for each action), then invokesget_mem_layout() again, and, finally prints the entries of memregion (now the result of the second invocation).You can choose the action of each driver from a set of options. Examples are: a) allocating a massive array withmalloc and initializing it, b) mmap()-ing a large file, c) invoking a recursive function with a considerable depth ofrecursion, d) performing a mathematical function using the standard math library, assuming always you compiledynamically loaded executables, etc.With humanly readable output we mean something mimicking the following format of hexadeciaml addressrange followed byRW, RO or NO (entries shown here are totally fictitious) :0x00000000-0x0742ffff NO0x07430000-0x07442fff RW0x07443000-0x082fffff RO0x08300000-0x0affffff RW0x0b000000-0x2fffffff NO0x30000000-0x3000ffff RO0x30010000-0xafffffff NO0xb0000000-0xffffffff RONotesThere are other ways to determine the memory layout of a process using a variety of tools available under Linux.However, you will have to do it the hard way, i.e., by scanning the memory directly. This is in fact the most reliableway to authoritatively find out what is really there.Note that you will have to intercept memory reference errors and respond to them in a manner meaningful to theobjectives of the exercise. For this, you have to familiarize yourself with UNIX signals and signal handling. Theywill be covered in the labs.Because, by default, the gcc compiler on the lab machines produces 64 bit executable (which corresponds to amassive address space) you are expected to, instead, produce and run 32 bit executables. This is accomplishedwith the –m32 flag.DeliverablesYou should submit your assignment as a single compressed archive file (zip or tar.gz) containing: ...

March 21, 2022 · 5 min · jiezi

关于c++:名字查找

名字查找C++ 有一个准则,就是标识符要先申明,再应用。每一个标识符在应用的时候,都要找到它对应的申明。这个过程,就是名字查找。 在程序的不同构造中,名字查找的规定也不尽相同。上面简述如下。 Unqualified name lookup简略地说,就是独自一个标识符的查找。 名字空间中对标识符的应用名字空间中的应用的标识符须要在应用前,在以后或蕴含它的名字空间中被申明。 名字空间中定义的函数中这包含函数名之后呈现的任何符号,包含参数表中呈现的类型、默认参数等。 其申明须要呈现在应用之前,顺次查找以后块(block),蕴含以后块的块,函数属于的 namespace,该 namespace 的父 namespace。 namespace A { namespace N { void f(); }}void A::N::f() { i = 5; // i 的申明会在以下中央被查找: // 1) A::N::f 中,i 的只用之前 // 2) namespace N // 3) namespace A // 4) 全局名字空间,A::N::f 的定义之前}类定义中的名字类定义中的名字按其是否在一个 complete-class context ,查找跪在不同。 Complete-class context 是指:函数体、函数的默认参数、noexcept-specifier,成员初始化 在 complete-class context 外,申明要在应用之前,查找范畴包含:以后类、基类的成员、蕴含以后类定义的类(如有)或其基类成员、蕴含以后类的函数(如有)、蕴含以后类的namespace。 namespace M { class B { };}namespace N { class Y : public M::B { class X { int a[i]; }; };}// 会在以下地位查找 i 的申明:// 1) class N::Y::X 中,i 应用之前// 2) class N::Y 中, N::Y::X 定义之前// 3) N::Y’s 的基类 M::B// 4) 名字空间 N, N::Y 定义之前// 5) 全局名字空间, N 定义之前在 complete-class context 中,当查找类成员时,并不要求成员申明在标识符应用之前,查找范畴包含:以后块或蕴含的块(如有)、以后类成员或基类的成员、蕴含以后类定义的类(如有)的成员或其基类成员、蕴含以后类的函数(如有)、蕴含以后类的namespace。 ...

March 20, 2022 · 3 min · jiezi

关于c++:COMP-SCI-7306-PageRank

Assignment 3: PageRank, Frequent Item-Setsand ClusteringFormative, Weight (15%), Learning objectives (1, 2, 3),Abstraction (4), Design (4), Communication (4), Data (5), Programming (5)Due date: 11 : 59 pm, 25 March, 20221 Overview (Attention, Different To PreviousAssignments)This assignment must be done individually. This means all the rules regardingindividual submission will apply and the submission must be solely your ownwork. Therefore, we will not use the groups on MyUni. You will need to submiton the assignment page as an individual.2 AssignmentExercise 1 Frequent Item-Sets (30 points)Suppose there are 100 items, numbered 1 to 100, and also 100 baskets, alsonumbered 1 to 100. Item i is in basket b if and only if i divides b with noremainder. Thus, item 1 is in all the baskets, item 2 is in all fifty of the evennumbered baskets, and so on. Basket 12 consists of items 1, 2, 3, 4, 6, 12, sincethese are all the integers that divide 12. Answer the following questions: ...

March 20, 2022 · 3 min · jiezi

关于c++:读书笔记2

负载指数调研负载四因素:CPU + 内存 + 磁盘 + 网络 四因素的欧几里得间隔作为负载指数 CPU资源: CPU利用率:反馈过程对CPU应用状况 Load Average:= Running + Waiting + Uninterruptable,反馈过程对CPU需要状况 二者并非线性关系,CPU利用率低 load average 可能高,此时过程处于期待IO状态 负载平衡伎俩DNS pros:兼容性好 cons:作用无限(没有权重、只有IP地址、因为缓存不实时、不反对服务可用度上报)网关:通过隧道技术可使server看到用户实在ip,并且能够维持会话信息,保障落到同一台server上反向代理:Nginx 正向代理次要是用来解决拜访限度问题。而反向代理则是提供负载平衡、平安防护等作用。哈希规定 轮询weight:依据权重ip hash:同一个用户落到同一个serverurl hashfair:依据响应工夫抉择C++排查内存问题经验谈mprotect 设置 guard page,呈现问题第一工夫core dump,尽可能靠近谬误现场malloc_trim 尽快让 glibc 偿还内存给操作系统(sbrk)what is non virtual thunk一致性哈希算法1. 经典一致性哈希将节点映射到 [0, 2^32 - 1]的环上,同时将数据映射到[0, 2^32 - 1]的环上,查找第一个哈希值大于等于数据哈希值的节点。 更好的做法(防止了一台机器退出导致负载全副落入下一台机器):为每个物理节点调配若干个虚构节点,应用虚构节点作为哈希映射。

March 19, 2022 · 1 min · jiezi

关于c++:Linux常见命令学习

Linux下过程状态详解 top 、uptime 等命令展现出的 load average,并非 CPU load average,而是零碎整体负载,包含了对磁盘资源的申请 然而通常状况下,load average / CPU core number > 1 暗示零碎可能是CPU BOUND 计算公式: load average = TASK_RUNNING + TASK_UNINTERRUPTABLE Linux下过程状态的划分: R:TASK_RUNNINGS:TASK_INTERRUPTABLED:TASK_UNINTERRUPTABLE:这个状态个别呈现在过程与外部设备替换,内核的一些解决流程是无奈被中断的,如果此时容许中断,原有流程被插入一段解决异步信号的流程,过程与外部设备交互过程被中断,那么外部设备可能陷入不可控的状态,因而,此时不响应异步信号(kill -9 无奈杀死)Z:TASK_ZOMBIELinux /proc子系统文档 常见目录项 cmdline:命令行参数cwdexefdmapscgrouptop命令详解 top命令常见参数 -c :输入残缺命令行-H:显示每个线程而非过程的汇总 (通过pthread_setname_np)更敌对-p pid:显示特定过程的信息交互命令: m:切换显示内存的形式t:切换显示CPU负载的形式c:切换显示残缺命令行与否M:按内存排序P:按CPU排序T:按运行工夫排序perf perf record 通过挂载到某个过程上生成 perf.data,perf report 读取perf.data 取得信息address-sanitizer:原理是 shadow poison,可能探测dangling pointer、buffer overflow、memory leak [Use after free] (dangling pointer dereference)[Heap buffer overflow][Stack buffer overflow][Global buffer overflow][Use after return][Use after scope][Initialization order bugs][Memory leaks]iostat命令详解 ...

March 19, 2022 · 1 min · jiezi

关于c++:22种设计模式的C实现

前言1. 代码仓库https://github.com/TOMO-CAT/C...2. 前置常识UML类图与面向对象编程软件设计准则与SOLID准则创立型模式工厂办法模式(Factory Method)形象工厂模式(Abstract Factory)生成器模式(Builder)原型模式(Prototype)单例模式(Singleton)结构型模式适配器模式(Adapter)桥接模式(Bridge)组合模式(Composite)装璜模式(Decorator)外观模式(Facade)享元模式(Flyweight)代理模式(Proxy)行为型模式责任链模式(Chain of Responsibility)命令模式(Command)迭代器模式(Iterator)中介者模式(Mediator)备忘录模式(Memento)观察者模式(Observer)状态模式(State)策略模式(Strategy)模板办法模式(Template Method)访问者模式(Vistor)

March 18, 2022 · 1 min · jiezi

关于c#:基于NET的在线刷题考试系统源代码

分享一个基于.NET的在线刷题考试零碎,有残缺的源代码和脚本文件,能够做二次开发,有管理员,老师和学生三种角色,老师后盾能够批量上传试题,公布试卷,批改试卷,统计导出问题等 性能很全面,除了在线刷题和考试,还有其余性能,我在这里简略说一下,具体的能够下载钻研哦 1、在线刷题:试题能够批量导入导出,学员能够随时随地刷题2、在线考试:多种考试模式,主观题主动阅卷,主观题人工阅卷3、视频点播:能够上传录播课程,增加课件等4、在线直播:对接七牛云直播接口,非常晦涩5、实时督学:批量治理学员,对学员的学习进度无效统计,后盾可查6、在线领取:支付宝,微信在线购买课程,主动开课 运行环境:服务器操作系统:windows server 2012 64位中文版数据库:Microsoft SQL Server 2008.NET版本:.NET4.6 开发文档https://pan.baidu.com/s/1koQyvnb0YEutlQomjAwIjg 提取码:xekq源码下载https://gitee.com/weishakeji/LearningSystem 装置问题技术支持483828432留神:零碎装置后用记事本关上db.config文件里配置以下主域用域名拜访:例如拜访域名是:www.weisha100.net,主域处填写:weisha100.net,示例如下:add name="weisha100.net" 内网以及应用ip拜访:间接填写ip地址,示例如下:add name="122.114.68.70"留神:不须要带端口号。

March 18, 2022 · 1 min · jiezi

关于c:ECE-650-Malloc

Assignment #1: Malloc Library Part 1ECE 650 – Spring 2021See course site for due dateGeneral Instructions You will work individually on this the project.The code for this assignment should be developed and tested in a UNIX-basedenvironment. You can use the VM that has been made available to you for ECE551.You must follow this assignment specs carefully, and turn in everything that is asked(and in the proper formats, as described).You should plan to start early on this project and make steady progress over time. It willtake time and careful though to work through the assignment.Implementation of malloc libraryFor this assignment, you will implement your own version of several memory allocationfunctions from the C standard library (actually you will have the chance to implement and studyseveral different versions as described below). Your implementation is to be done in C code.The C standard library includes 4 malloc-related library functions: malloc(), free(),calloc(), and realloc(). In this assignment, you only need to implement versions ofmalloc() and free(): void * malloc(size_t size); void free(void *ptr);Please refer to the man pages for full descriptions of the expected operation for thesefunctions. Essentially, malloc() takes in a size (number of bytes) for a memory allocation,locates an address in the program’s data region where there is enough space to fit the specifiednumber of bytes, and returns this address for use by the calling program. The free() functiontakes an address (that was returned by a previous malloc operation) and marks that dataregion as available again for use.The submission instructions at the end of this assignment description provide specific detailsabout what code files to create, what to name your new versions of the malloc functions, etc.As you work through implementing malloc() and free(), you will discover that as memoryallocations and deallocations happen, you will sometimes free a region of memory that isadjacent to other also free memory region(s). Your implementation is required to coalesce inthis situation by merging the adjacent free regions into a single free region of memory.Hint: For implementing malloc(), you should become familiar with the sbrk() system call.This system call is useful for: 1) returning the address that represents the current end of theprocesses data segment (called program break), and 2) growing the size of the processes datasegment by the amount specified by “increment”. void *sbrk(intptr_t increment);Hint: A common way to implement malloc() / free() and manage the memory space is tokeep an adequate data structure to represent a list of free memory regions. This collection offree memory ranges would change as malloc() and free() are called to allocate andrelease regions of memory in the process data segment. You may design and implement yourmalloc and free using structures and state tracking as you see best fit.In this assignment, you will develop a malloc implementation and study different allocationpolicies. Study of Memory Allocation PoliciesYour task is to implement 2 versions of malloc and free, each based on a different strategyfor determining the memory region to allocate. The two strategies are:First Fit: Examine the free space tracker (e.g. free list), and allocate an address fromthe first free region with enough space to fit the requested allocation size.Best Fit: Examine all of the free space information, and allocate an address from thefree region which has the smallest number of bytes greater than or equal to therequested allocation size.The following picture illustrates how each strategy would operate (assuming free regions aretraversed in a left to right order) for a malloc() request of 2 bytes:Requirements: Malloc implementationsTo implement your allocation strategies, you will create 4 functions://First Fit malloc/freevoid * ff_malloc(size_t size);void ff_free(void * ptr);//Best Fit malloc/freevoid * bf_malloc(size_t size);void bf_free(void * ptr);Note, that in all cases, a policy to minimize the size of the process’s data segment should beused. In other words, if there is no free space that fits an allocation request, then sbrk()should be used to create that space. However, you do not need to perform any type of garbagecollection (e.g. reducing the size of the process’s data segment, even if allocations at the top ofthe data segment have been freed).On free(), your implementation is required to merge the newly freed region with any currentlyfree adjacent regions. In other words, your bookkeeping data structure should not containmultiple adjacent free regions, as this would lead to poor region selection during malloc.Requirement: Performance study reportIn addition to implementing these malloc functions, you are tasked to conduct a performancestudy of the malloc()with different allocation policies. Several programs for experimentationwill be provided that perform malloc() and free() requests with different patterns (e.g.frequencies, sizes). The metrics of interest will be:1) the run-time of the programs, as the implementation of different allocation policies mayresult in different speeds of memory allocation;2) the memory fragmentation is a number in the interval [0,1] (interpreted as apercenbtage), which is measured as follows:−(size of largest allocatable memory block/total size of free memory)In order to capture #2, you should also implement two additional library functions:unsigned long get_largest_free_data_segment_size();//in bytesunsigned long get_total_free_size();//in bytesThen, using these functions, you can use the included test programs as well as test programs ofyour own creation to evaluate and compare the algorithms.The Starter KitA starter kit is included in a file on Sakai: homework1-kit.tgzThis archive can be extracted using “tar xvzf homework1-kit.tgz”.The kit includes: Makefile: A sample Makefile for libmymalloc.so. general_tests/: General correctness test, see README.txt for details. alloc_policy_tests/: Allocation policy test cases, see README.txt for details. alloc_policy_tests_osx/: Same thing adapted for MacOS.NOTE: Mac OS is not the grading platform; these files are provided as a convenience.Additionally, you may need to change #include "time.h" to #include "sys/time.h"Testing your systemCode is provided for minimal testing, but the provided materials will not exhaustively evaluatethe correctness of your implementation. It is recommended to create your own test software thatuses your library, both to aid during development and to ensure correctness in a variety ofsituations.Detailed Submission InstructionsPlease submit a written report called report.pdf to Sakai (a submission link will beposted soon). The report should include an overview of how you implemented theallocation policies, results from your performance experiments, and an analysis of theresults (e.g. why do you believe you observed the results that you did for differentpolicies with different malloc/free patterns, do you have recommendations for whichpolicy seems most effective, etc.).Please submit a zipped file hw1_netID.zip to Sakai (e.g., if the netID is abc123, thename of the file should be hw1_abc123.zip). All source code should be included in adirectory named “my_malloc”. There should be a header file name “my_malloc.h” with the function definitionsfor all _malloc() and _free() functions. You may implement these functions in “my_malloc.c”. If you would like to usedifferent C source files, please describe what those are in the report. There should be a “Makefile” which contains at least two targets: 1) “all” shouldbuild your code into a shared library named “libmymalloc.so”, and 2) “clean” should remove all files except for the source code files. The provided Makefilemay be used as-is, expanded upon, or replaced entirely. If you have notcompiled code into a shared library before, you should be able to find plenty ofinformation online. With this “Makefile” infrastructure, the test programs will beable to: 1) #include “my_malloc.h” and 2) link against libmymalloc.so (-lmymalloc), and then have access to the new malloc functions. Just like that, youwill have created your own version of the malloc routines in the C standardlibrary!

March 18, 2022 · 6 min · jiezi

关于c++:软件开发通识之一什么是计算机语言

https://www.toutiao.com/i7076...

March 17, 2022 · 1 min · jiezi

关于c++:CQt-和-WordExcelPDF-交互总结

浏览本文大略须要 6 分钟日常开发软件可能会遇到这类小众需要,导出数据到 Word、Excel 以及 PDF文件,如果你应用 C++ 编程语言,那么能够抉择的计划不是很多,恰好最近刚好有这部分需要,整顿下这段时间踩过的坑,不便前人 读写 Word日常开发的软件应用最多的应该是导出数据到 Word 文档中,目前能够用的计划有这几种 没有美中不足的计划,任何计划都存在长处和毛病,上面来具体看下这几种计划的优缺点以及实用场景 XML 模板替换原理:当时编辑好一份 Word 模板,须要替换内容的中央预留好地位,而后应用非凡字段进行标记,前面应用代码进行全量替换即可实现长处代码量绝对较少、导出速度快跨平台,反对多个零碎,零碎不装置 office 也能导出;反对图片以及固定格局导出;毛病导出格局固定,可扩展性不强,如果需要变动导出格局变了,那么模板也要跟着扭转;一种格局对应一份模板,如果导出格局较多,须要筹备的模板文件较多,这样比拟繁琐;须要 Word 2003 以上版本;举个栗子咱们先编辑一份 Word 模板文档,内容大略如下所示: 将该文档另存为 Word XML 文档 XML-Template.xml读取文档内容进行变量替换 QFile file("XML-Template.xml"); if (!file.open(QIODevice::ReadOnly)) { qDebug() << "open xxml file fail. " << file.errorString(); return 0; } QByteArray baContent = file.readAll(); file.close(); QString strAllContent = QString::fromLocal8Bit(baContent); strAllContent.replace("$VALUE0", "1"); strAllContent.replace("$VALUE1", QString::fromLocal8Bit("法外狂徒张三")); strAllContent.replace("$VALUE2", QString::fromLocal8Bit("考试不合格")); strAllContent.replace("$VALUE3", "2"); strAllContent.replace("$VALUE4", QString::fromLocal8Bit("李四")); strAllContent.replace("$VALUE5", QString::fromLocal8Bit("合格")); QFile newFile("export.doc"); if (!newFile.open(QIODevice::WriteOnly)) { qDebug() << "file open fail." << newFile.errorString();; return 0; } newFile.write(strAllContent.toLocal8Bit()); newFile.close();保留替换后的内容,写入文件 ...

March 17, 2022 · 2 min · jiezi

关于c#:LeetCode-C3无重复字符的最长子串

开发工具与关键技术: C#作者:奶糖不甜撰写工夫:2022.3.17C#是微软公司公布的一种由C和C++衍生进去的面向对象的编程语言、运行于.NET Framework和.NET Core之上的高级程序设计语言.并定于在微软职业开发者论坛(PDC)上登台亮相。C#是微软公司研究员Anders Hejlsberg的最新成绩.C#看起来与Java有着惊人的类似;它包含了诸如繁多继承、接口、与Java简直同样的语法和编译成中间代码再运行的过程.然而C#与Java有着显著的不同,它借鉴了Delphi的一个特点,与COM是间接集成的,而且它是微软公司 .NET windows网络框架的配角.题目形容:给定一个字符串 s ,请你找出其中不含有反复字符的最长子串的长度. 示例:输出: s = "abcabcbb"输入: 3 解释: 因为无反复字符的最长子串是 "abc",所以其长度为 3. 哈希表滑动窗口解法:利用滑动Hash联合窗口,设置left(左)指针和right(右)指针来进行窗口保护,通过right指针下标右移,遍历字符串中不含有反复字符的最长子串的长度.当发现反复字符时,将已知的最长不反复字符串存入Hash中,批改left指针下标,进行新一轮遍历.最初,将Hash中的所有后果进行比照判断出最长子串的长度,并返回. public class Solution { public int LengthOfLongestSubstring(string s) { if (s.Length < 2) return s.Length; //如果字符串长度小于2,也就是为1或null时,返回自身长度即可. var l = 0;//定义left指针 var r = 0;//定义right指针 var maxlen = 0;//定义后果maxlen var charSet = new HashSet<char>();//定义哈希表charSet while (r < s.Length) { //在right指针值大于长度条件未达成之前有限循环 if (charSet.Contains(s[r]) == false) { //当后果不等,right指针自增后重新加入charSet哈希表 charSet.Add(s[r++]); maxlen = Math.Max(maxlen, r - l);//计算结果 } else { charSet.Remove(s[l++]);//否则状况下,left指针自增 } }//后果maxlen匹配是跳出循环,return后果 return maxlen; }}注: 为何开始判断字符串长度的条件是s.Length < 2,而不是s.Length <= 2?因为如果字符串两个都雷同时,它须要返回的后果也仅为1,没必要额定削减运算. ...

March 17, 2022 · 1 min · jiezi

关于c#:LeetCode题库-C2两数相加

开发工具与关键技术: C#作者:奶糖不甜撰写工夫:2022.3.7 C#是微软公司公布的一种由C和C++衍生进去的面向对象的编程语言、运行于.NET Framework和.NET Core之上的高级程序设计语言.并定于在微软职业开发者论坛(PDC)上登台亮相。C#是微软公司研究员Anders Hejlsberg的最新成绩.C#看起来与Java有着惊人的类似;它包含了诸如繁多继承、接口、与Java简直同样的语法和编译成中间代码再运行的过程.然而C#与Java有着显著的不同,它借鉴了Delphi的一个特点,与COM是间接集成的,而且它是微软公司 .NET windows网络框架的配角.题目形容:给你两个非空的链表,示意两个非负的整数.它们每位数字都是依照逆序的形式存储的,并且每个节点只能存储 一位数字.请你将两个数相加,并以雷同模式返回一个示意和的链表.你能够假如除了数字 0 之外,这两个数都不会以 0 结尾,每个链表中的节点数都在范畴[1, 100]之内. 示例:输出l1 = [2, 4, 3], l2 = [5, 6, 4].后果输入为[7, 0, 8].解释:342 + 465 = 807. 最清晰解法:链表的计算方法,首先想到的就是进位,设置进位值.因为题目表明链表是逆序相加,所以第一位也就是个位数先进行计算,更加不便确定是否有进位值。 设置进位值num,将每次l1, l2, num三个值加起来为mid,位数为mid%10,大于10则进位为mid/10,实例如下: public class Solution { public ListNode AddTwoNumbers(ListNode l1, ListNode l2, int num = 0) { if(l1 == null && l2 == null) { if(num != 0) return new ListNode(num); else return null; } int mid = (l1?.val ?? 0) + (l2?.val ?? 0) + num; ListNode listnode = new ListNode(mid % 10); listnode.next = AddTwoNumbers(l1?.next, l2?.next, mid/10); return listnode; }}注:解说一下问号的用法. ...

March 16, 2022 · 1 min · jiezi

关于c++:CC气象数据中心实战手把手教你做工业级项目

download:C/C++气象数据中心实战,手把手教你做工业级我的项目2021 年 Node.js 的发展趋势世界各地的开发者对 2021 年 Node.js 的发展趋势做了很多预测。在下文中,咱们将解说往年预期的 Node.js 趋势。Node.js 为什么如此有名呢?近些年来,Node.js 凭借其高度灵活和极其轻量的个性,变得非常流行。Node.js 具备大量的 JavaScript 库用于简化开发流程。Node.js 的开源属性也使得它在 web 和移动利用开发方面变得非常出名。根据最近的统计,可能看出: 目前有超过 50% 的开发者在自己的我的项目中使用 Node.js。在美国,基于 Node.js 创建的网站超过 28000 个 。AliExpress、eBay 等出名公司很大程度上依赖于 Node.js。包含 PayPal、Netflix 和 Groupon 在内的大流量的网站都在使用 Node.js。 Node.js 自 2009 年在市场上推出就变得非常受欢迎。Node.js 在 Github 中具备 75.9k stars、3k watchers,还有 19k forks,在 Stack share 中具备 71.8k 的关注者以及 8.3k 的同意。这些数字足以描述 Node.js 流行程度。出名的科技巨头,比如 Netflix 和 Microsoft 都在使用 Node.js。Node.js 胜利在 StackOverflow 2021 年开发者考察中位居榜首,其中超过 50% 的考察参与者声称正在我的项目中使用 Node.js。

March 16, 2022 · 1 min · jiezi

关于c#:C速成指南从入门到进阶实战WPF与Unity3D开发

download:C#速成指南:从入门到进阶,实战WPF与Unity3D开发在 Web 應用程序開發方面,Vue.js 正快速成爲開發人員的最愛。這個現代、新穎的 JavaScript 庫它在 GitHub 上有超过 123,000 颗星,關於開發人員來說是一個引人瞩目的選择,由於它很容易集成到現有項目中。它的速度很快,它非常強大。妳能夠用它從頭開端樹立一個動態的、可擴展的、可維護的單頁面應用程序。 作爲一個 JavaScript 框架,Vue.js 允許您輕鬆地將動態數據渲染到 DOM,將數據绑定到 DOM 元素,以及治理/維護應用程序的狀態(本地存儲),而無需用戶从新加载阅讀器。它是首選,由於它是輕量級的,模塊化的,需要起码的配置。它的速度也非常快,文件大小也很低。開發人員能夠很容易地把它放入任何項目或現有的框架中。 隨著Vue.js逐渐成爲更多開發者的首選框架,這里有8個值得關注的UI組件,心愿能在2019年整合到妳的項目中。在每個組件的开端,我都增加了該組件GitHub倉庫账戶的链接,以讓妳能夠做出奉獻。

March 16, 2022 · 1 min · jiezi

关于c++:typetraits源码阅读笔记

// enable_iftemplate <bool, typename _Tp = void>struct enable_if {};template <typename _Tp>struct enable_if<true, _Tp>{ typedef _Tp type; }// integral_constanttemplate<typename _Tp, _Tp __v>struct integral_constant{ static constexpr _Tp value = __v; typedef _Tp value_type; typedef integral_constant<_Tp, __v> type; constexpr value_type operator()() const noexcept { return value; }};/// The type used as a compile-time boolean with true value.typedef integral_constant<bool, true> true_type;/// The type used as a compile-time boolean with false value.typedef integral_constant<bool, false> false_type;<type_traits> 值得好好读 ...

March 14, 2022 · 1 min · jiezi

关于c++:初始化-Initialization

初始化 (Initialization)初始化的模式 Direct-initializationCopy-initialization初始化的含意Value initializeDefault initializeZero initializeList initialize narrowing conversion字符数组初始化聚合(aggregate)初始化 Aggregate援用初始化基于c++20 draft n4868 初始化的模式通常讲到初始化,会想起变量的时候给的初始化值(initializer)。然而除此之后,还有一些中央会产生对象的初始化。所有的这些初始化操作听从同一套规定。 初始化依照其模式,能够分为两大类,direct-initialization与copy-initialization Direct-initialization变量定义中初始化值无= int i{1}; std::vector<std::string> vec(3);new-initializer int *p = new int(3);,应用3初始化一个新建的int对象static_cast static_cast 会应用其参数初始化一个后果类型的对象,如:static_cast<int>(2.0);,其中应用2.0初始化一个int对象。函数调用像是的类型转换 int(2.0),其中应用2.0初始化一个int类型的对象condition 中的 brace-init-list if (Derived *pDerived{dynamic_cast<Derived*>(pBase)}),应用 dyanmic_cast<Drived*>(pBase) 初始化 pDerivedCopy-initialization变量定义中应用 = 模式初始化 int i = 1; ,应用 1 初始化 icondition 中应用 = 模式初始化 if (Derived *pDerived = dynamic_cast<Derived*>(pBase)),应用 dyanmic_cast<Drived*>(pBase) 初始化 pDerived参数传递,函数返回值 示例: int foo(int i) { return i+1;}void bar() { foo(1);}应用 1 初始化 foo 的参数 i,应用 i+1 初始化函数的返回值(右值) ...

March 13, 2022 · 4 min · jiezi

关于c:CS139-C-项目

CS139 C Programming ProjectNovember 24, 2020The objective of this project is to practice the implementation of structures and functions in C.The submission of the project requires the source code and a readme.pdf describing it.Pokémon DatabasePart 1 - Structure (4 points)Implement a structure named pokemon, which contains the following elements id (int)name (char*)height (float)type (char*)It is suggested to use an array of the designed structure as the database, for example:struct pokemon pkdb[100]; orstruct pokemon *pkdb[100];However, other forms such as linked list are also acceptable.Part 2 - Basic Functions (4 points)The following functions should be realized.int insert(int id, char name, float height, char type);Add a new pokemon into the database. Return 0 if successful. Return 1 if the max size of thedatabase is exceeded.int delete_id(int id);Delete the pokemon of given id from the database. Return 0 if successful. Return 1 if thepokemon of given id doesn’t exist in the database.Then print a sentence to describe the situation according to the return value.Part 3 - Extended Functions (8 points)The following functions should be realized.void find_height(int param);param ∈ {1, 2}. Find the pokemons with maximum height (param=1) or minimum height1(param=2). Print the name of the found pokemons.Make sure to print all the pokemons if they have the same maximum or minimum height.void sort_id(); Sort the database with id-ascending order. Print all pokemon names in order.void sort_id_plus(int param);param ∈ {1, 2}. Sort the database with id-ascending order (param=1) or id-descending order(param=2). Print all pokemon names in order.Use pointer to function (such as the functions below) instead of duplicating the sort process.int ascending (int a, int b) { return b<a; }int descending (int a, int b) { return b>a; }void group(char* type);Print the name of all the pokemons belonging to the given type.Part 4 - Free Design (4 points)Design and implement a feature for the database. Feel free to add any element in the structure andadd any function. Explain this feature in detail in readme file.For example, it could be a great idea to implement the evolutionary chains of pokemons. For pokemonEevee, the function could find its evolution Vaporeon, etc.Input and OutputThe main function firstly reads the information of several pokemons, then reads a set of instructionsand prints corresponding output.The first line of input is an integer n ≤ 50, indicating the number of pokemons in the following lines.For each pokemon, there are 4 lines containing its id, name, height and type respectively. Remarkthat each pokemon may have at least 1 type and at most 2 types. Types are separated with a singlecomma.Then there’s an integer m ≤ 20, indicating the number of instructions. Each line contains 1 instruction,which is consisted of a number and a parameter, separated by a blank. The number is theenumeration of corresponding function: 2 delete_id, 3 find_height, 4 sort_id, 5 sort_id_plus, 6 group.The parameter is passed into the function as argument.There’s a sample of input and output in the appendix. Each instruction and its output is aligned. Itcould be used to validate the functions.Remark that the format of the output is not important. Do not bother with order of print (exceptfor sort_id or sort_id_plus), or number of blanks.Charmander Charizard Pikachu Nidoran LaprasLaprasPikachu NidoranDeleted successfully !Pokemon of id 29 doesn’t exist in the database.Charmander Charizard Pikachu LaprasLapras Pikachu Charizard CharmanderCharizard CharmanderLapras

March 13, 2022 · 3 min · jiezi

关于c++:sharedptr源码阅读

能够通过模板参数指定Lock_Policy class sp_counted_Base{} use_count => 当减为0析构资源 disposeweak_count => 当减为0 delete this; destroy开释管制区域 二者皆为原子变量,原子操作扭转值,同时应用内存屏障确保可见性 dispose肯定要能被调用destroy的线程察看到 class sp_counted_Ptr{} 继承了 sp_counted_Baseclass sp_counted_deleter{} 继承了sp_counted_Base,存储了Deleter_,应用std::addressof 1获取地址 十分乏味,当面对模板时,传入的类型的& operator可能被重载,并非取地址的含意,因而应用这个补救。 why use std::addressof versus &: https://stackoverflow.com/que... ↩

March 12, 2022 · 1 min · jiezi

关于c++:SOF103

DESCRIPTION OF COURSEWORKCourse Code SOF103Course Name C and C++ ProgrammingLecturer Dr. Kamran SiddiqueAcademic Session 202009Assessment Title Project (Replacement of Class Test)A. Introduction/ Situation/ Background InformationThe key characteristics of object oriented programming (OOP) are encapsulation, inheritance, andpolymorphism. In order to comprehend and utilize the advantages of the OOP, a project has beendesigned to simulate the working of a banking account system. The students are expected toimplement it with an effective utilization of the characteristics of OOP focusing constructors, datahiding and abstraction techniques, code reusability, virtual functions, input validations, and so on.This activity also highlights the significance or report writing and effective presentation.B. Course Learning Outcomes (CLO) coveredAt the end of this assessment, students are able to:CLO 1 Comprehend basic programming constructs of C and C++.CLO 2 Demonstrate an understanding of the concepts and principles of C and C++programming by solving real-world problems in particular.CLO 4 Evaluate the given C/C++ code segments using algorithm tracing technique.C. University Policy on Academic Misconduct ...

March 12, 2022 · 8 min · jiezi

关于c#:COMP1038银行系统

COMP1038 Coursework 02 – Digital MiniBanking SystemIntroductionThis is the COMP1038 Coursework 02. It is worth 40% of the module mark. Thedeadline for this exercise is 16:00 on Saturday 26th of December 2020.Read the entire document before beginning the exercise.If you have any questions about this exercise, please ask in the Q&A forum onMoodle, after a lecture, in a lab, or during the advertised office hours. Do not postyour program or parts of your program to Moodle as you are not allowed to share yourcoursework programs with other students. If any questions require this exercise to beclarified then this document will be updated and everyone will be notified via Moodle.Version History Version 2.0 - 2020-12-04 – version 2.SubmissionYou must submit a single C source code file containing all your code for this exerciseand a text file containing city names, branch names, and their codes. The files must becalled DigitalMiniBank_<Your_Name>_<Your Numeric Id>.c andCityBranchCodes_<Your_Name>_<Your Numeric Id>.txt. The program must notrequires any other files outside of the standard C headers which are always available.The first line of the C source code file should be a comment which contains yourstudent ID number, username, and full name, of the form:// 6512345 zy12345 Joe BlogsThe file must compile without warnings or errors when I use the commandgcc -std=c99 -lm -Wall DigitalMiniBank_<Your_Name>_<Your Numeric Id>.c -oMiniBankAccountThis command will be run on our Linux server cslinux. If it does not compile, for anyreason, then you will lose all the marks for testing (common reasons in the past havebeen submitting a file with the wrong filename, or developing your solution on yourpersonal computer without having tested it on our Linux server). If the file compilesbut has warnings then you will lose some marks for not correcting the warnings.The completed source code file should be uploaded to the Coursework Submissionlink on the COMP1038 Moodle page. You may submit as many times as you wishbefore the deadline (the last submission before the deadline will be used). After thedeadline has passed, if you have already submitted your exercise then you will not beable to submit again. If you have not already submitted then you will be allowed tosubmit once.Late submissions: Late submissions will lose 2 percentage points per hour, roundedup to the next whole hour. This is to better represent the large benefit a small amountof extra time can give at the end of a programming exercise. No late submissions willbe accepted more than 50 hours after the exercise deadline. If you have extenuatingcircumstances you should file them before the deadline.PlagiarismYou should complete this coursework on your own. Anyone suspected of plagiarismwill be investigated and punished in accordance with the university policy onplagiarism (see your student handbook and the University Quality Manual). This mayinclude a mark of zero for this coursework.You should write the source code required for this assignment yourself. If you usecode from other sources (books, web pages, etc), you should use comments toacknowledge this (and marks will be heavily adjusted down accordingly). The onlyexception to this is the dynamic data-structures (linked lists and others) developedduring the lectures and tutorials; you may use these, with or without modification,without penalty as long as you add a comment in your program saying you have takenthem from the lectures or tutorials and saying how you have modified it (or notmodified it). If you do not acknowledge their source in a comment then it will beregarded as potential plagiarism.You must not copy or share source code with other students. You must not worktogether on your solution. You can informally talk about higher-level ideas but not toa level of detail that would allow you all to create the same source code.Remember, it is quite easy for experienced lecturers to spot plagiarism in source code.We also have automated tools that can help us identify shared code, even withmodifications designed to hide copying. If you are having problems you should askquestions rather than plagiarize. If you are not able to complete the exercise then youshould still submit your incomplete program as that will still get you some of themarks for the parts you have done (but make sure your incomplete solution compilesand partially runs!).If I have concerns about a submission, I may ask you to come to my office andexplain your work in your own words.MarkingThe marking scheme will be as follows: Tests (60%): Your program should correctly implement the task requirements.A number of tests will be run against your program with different input datadesigned to test if this is the case for each individual requirement. The teststhemselves are secret but general examples of the tests might be:o Does the program work with the example I/O in the question?o Does the program work with typical valid input?o Does the program correctly deal with input around boundary values?o Does the program correctly deal with invalid input (both invalid files andvalues)?o Does the program handle errors with resources not being available (eg,malloc failing or a filename being wrong)?o Does the program output match the required format?o Does the program output an appropriate table when required?As noted in the submission section, if your program does not compile thenyou will lose all testing marks. Appropriate use of language features (30%): Your program should use theappropriate C language features in your solution. You can use any languagefeatures or techniques that you have seen in the course, or you have learned onyour own, as long as they are appropriate for your solution. Examples of thismight be:o If you have many similar values, are you using arrays (or equivalent)instead of many individual variables?o Have you broken your program down into separate functions?o Are all your function arguments being used?o If your functions return values, are they being used?o If you have complex data, are you using structures?o Are you using loops to avoid repeating many lines of code?o Are your if/switch statements making a difference, or are the conditionsalways true or false making the statement pointless?o Are you closing files when the file is no longer in use? Source code formatting (10%): Your program should be correctly formattedand easy to understand by a competent C programmer. This includes, but is not limited to, indentation, bracketing, variable/function naming, and use ofcomments.TaskNowadays, bank accounts have become an important part of human life for savingmoney easy and safe way. Due to the recent growth of digitization, most of the banksare maintaining the accounts of their customers on a computerized system. As abanking software developer, your task is to develop a computerized banking system.When the program runs, it should display the following main menu to the user andprompt them to enter a menu option:1) Show city code and branch code2) Open an account3) Show account details4) Show list of accounts5) Deposit in an account6) Withdraw from an account7) Transfer money8) Transaction details9) Close an account10)QuitOption:If the user enters the number of an option, the program should perform that optionthen return to the main menu to let the user select another option. If the user enterssomething which is not a valid option then the program should print "Unknownoption." then print "Option: " again for the user to select another option. The usermay enter any input at this, or any other prompt, in the program, terminated bypressing the return key (newline character). Your program must deal with thisappropriately, accepting valid input and rejecting invalid input according to theparticular prompt.If the user selects “Show city code and branch code”, then the program will show thelist of city and city codes, and a prompt “Enter the city code:”. When the userenters a city code from the list, it will display list of branches within that city and theircodes. For doing this, the students need to prepare a text file containing city namesand branch names and their codes. The file shoud contains at least 10 city names, 5branch name from each city, and their respective codes.If the user selects “Open an account”, then the program should ask the user to inputflowing data.Description Type Size RemarksName String 100 charactersId Number String 15 Characters Id can be alphanumericAddress String 200 CharactersDate of Birth String 10 Characters YYYY/MM/DDInitial deposit Integer not less than 1000 RMBAfter inputting these data of an account the account will be created and a numericaccount number will be assigned by the program in the format of xxxxxxxxxx. Thefirst xxx is the city code which is a number within 001-999 from the list of city codes,the second xx is the branch code which is a number within 01-99 from list of branchcodes, and the third xxxxx is the account number which is a number within 00001- ...

March 12, 2022 · 15 min · jiezi

关于c++:读书笔记之智能指针广度搜索

make_shared和shared_ptr<T>()的比拟make_shared只进行一次堆内存调配,shared_ptr<T>()进行两次堆内存调配 make_shared :将对象Object 和 管制块Control Block调配到一起shared_ptr<T>() :先new Object,再调配Contrl Block造成的结果: Exception safety:函数 f 接管两个 shared_ptr A、B作为参数,那么经验四个步骤 new Anew Bshared_ptr<T>(A)shared_ptr<T>(B)如果步骤2抛出异样(例如OOM),那么A对象没有被回收,因为此时A对象没有被智能指针治理起来,造成了资源泄露。 这个问题在C++17中失去了解决,C++17对函数参数求值程序做了规定,规定了函数参数求值须要 fully evaluate后 能力对下一个参数进行求值 Disadvantage of make_shared:weak_ptr的存在使得对象可能永远得不到开释。 因为weak_ptr的实现原理,是依据Control Block中的援用计数来判断对象是否被开释,因而Control Block的生命周期至多要和weak_ptr一样长。而make_shared在一次调配中调配了对象和Control Block的空间,因而只有对象和Control Block都不再应用的时候,能力进行开释。这就导致了即便援用计数为0,对象也没有被开释,直到最初一个weak_ptr析构,资源能力被一起开释。而shared_ptr因为是两次调配,能够别离开释。noexcept 和 stack unwind 和 FPOnoexcept 申明函数不抛出异样,不便编译器优化(应用move),对于big four(constructor 、 assignment 效果显著)。也能够在编译期对不同类型判断是否会抛出异样。 保障不抛出异样,编译器就不用进行Exception Handling FPO1: 问题起源:如何索引栈上变量? 计划一:通过esp进行偏移索引。毛病是esp会产生变动,要求编译器生成的代码更简单。 计划二:通过ebp进行偏移索引,ebp在一个栈帧中是固定的,更简略。 必须应用ebp的场景 SEH 当解决异样时,不能通过esp正确索引栈上变量,因为esp可能曾经产生变动具备destructor的对象必须应用SEH来取得unwind support应用alloca动态分配栈上数组,则必须 应用ebp,因为编译器无奈取得变量对esp的偏移=> 大部分场景 FPO disabled FPO disabled的益处:能够在缺失符号的状况下,依据ebp,将栈当作链表串起来 FPO的劣势: 1. x86寄存器太少,多一个寄存器能够少在栈上调配空间,访存更快 2. 没有保留、复原ebp的开销,代码提交更小custom deleter in smart_ptrstd::function => 32 bits on x64 payload of unnecessary flexibilityfunction ptr => 8 bits on x64stateless lambda => 0 EBOstateful lambda => sizeof (lambda)关注引起的 smart_ptr size 变动2 ...

March 11, 2022 · 1 min · jiezi

关于c:RBE104TC-开发

RBE104TC C/C++ Programming LanguageAssignment 1Assignment Overview:This assignment aims at testing some basic concepts of the C programming andinitiates the routine of code development using the software development process(SDP) presented in the relevant lectures. It focuses on the following five steps ofthe SDP. Problem statement: formulate the problem;Analysis: determine the inputs, outputs, variables, etc.;Design: define the list of steps (the algorithm) needed to solve theproblem;Implementation: the C code has to be submitted as a separate file, justindicate here the name of the file;Testing: explain how you have tested and verified your C program.You will need to apply this methodology to each one of the following simpleexercises.Things to note:Include clear comments in your code to make it easy to understand.Explain your testing procedure and what you have observed during thetesting. The testing should be demonstrated by screenshot pictures topresent the actual implementation output.How you solved any problems.Contribution to the Overall Marks 40%Issue DateSubmission Deadline Dec. 21st, 2020/ 5Exercise 1 (25%):Write a C program that can perform the following operations:• Read the following from the keyboard and store them in appropriate variables;• A full name (e.g. John Smith);• A telephone number (e.g. 12345678900) assume all phone numbers are withdigits;• A 2 digit decimal number (e.g. 22);• A temperature in degrees Celsius (e.g. 28.5°C).• Divide the first 6 figures of the telephone number by the last 5 and store theresult in a variable. Print the value on the screen (e.g. 123456/78900 = 1.56;• Print an integer on the screen with the decimal, the octal, and the hexadecimalformat (e.g. 45, 55,2D);• Convert the temperature from degrees Celsius to degrees Fahrenheit anddegrees Kelvin. Store the values in appropriate variables rounded to theclosest whole number and print them on the screen (e.g. 10°C 50°F 283°K);• Solve the real roots of the quadratic equation for any real input a,b,c (e.g.invalid(a = 0), two equal real roots, two unequal real roots, or no real roots).Exercise 2 (30%):• Write a functionbool same_vec (vector<int> a, vector<int> b)that checks whether two vectors are including the same elements, ignoringthe order and multiplicities.• For example, the two vectors {1, 4, 9, 16, 9, 7, 4, 9, 11} and {11, 11, 7, 9, 16, 4, 1}would be considered identical.Requirements:Get the numbers from keyboard input;The length of the vectors is unknown, it is only determined by the input./ 5Exercise 3 (45%):An entertainment company designs a game: both the player and the computergenerate a letter taking the value A, B, C, but the result is determined by thefollowing rules: A < B, B < C, and C < A. It would now invite you to develop thissoftware to provide players of the game with their own secured account in whichtheir game history including the win, lose, or draw numbers is recorded and storedin a file. There are several requirements as described in the following section.Program Requirements• Your program should provide users with the ability to create an account. Anaccount should be a structure type variable containing: a username, a password,and a record of the game history.• The game history should be stored in a two-dimensional array and contain thefollowing details as a minimum:i. Number of rounds in a gameii. Number of player winsiii. Number of computer winsiv. Number of drawsv. Whether or not the game was overall a winning, draw or loss.• All of the accounts should be stored in a data file and accessed by the program.• Once a user is logged on to the game they should be able to:i. Start a new gameii. Review their game historyiii. Clear their game historyiv. Logout• Normally, the use of global variables is not allowed. Any use of global variablesmust be fully justified in your report.Ideas:Note: the following are only to provide you with ideas of how to implement therequired functionality. They do not represent the “best” or only ways to implementthe functions.All of the player accounts are structure variables and will be stored in a file. Thelogin process can be achieved using a single structure variable, into which eachaccount can be read from the file one by one, each time checking the usernameuntil you find the correct players' account. The gaming operations can then beperformed using that single structure variable. When the player finishes only thisone structure needs to be written back to the file for saving.Alternatively, you can create an array of structures in the program and read thewhole file into the array, then search the array. The game can be played using the/ 5correct element of the array of structures. When the player finishes, the whole arraycan be written to the file.Try to create your own functions to simplify the programming task.Consider how your program should function when there is an invalid input.To make your program more interesting for the user thinks about what kind ofinformation they may like to access for example overall win percentages./ 5What should be submitted?You should submit the followings:1). A short report (up to a few pages of text plus C source codes) detailing for eachquestion:a). SDP steps 1 to 3 in the report (Report + Specification + Analysis +Algorithm Design) (40%);b). SDP step 4 (Implementation + Robustness): your C source code includingthe comments. (40%);c). SDP step 5 (testing): you will explain how you have tested the correctnessof your C program and will include some sample runs of your C Programs.(20%);Please refer to the file Marking Guidelines for RBE104TC.pdf on the Learning Mallsystem for a detailed marking scheme.2). The report in Microsoft Word or pdf format and C source code of yourimplementation zipped into a single file, i.e. the zip file will contain 2 files. (It is goodpractice to include comments in your code see the example provided.)The naming of Report ( .doc, .docx or .pdf only), Source Code (.c) and Compressedfile (.zip, or .rar only)StudentID_LastName_FirstName_AssignmentNumber.docStudentID_ AssignmentNumber.cStudentID_LastName_FirstName_AssignmentNumber.zipFor example:Report and c source file named:1234567_Albert_Einstein_1.doc1234567_1.cContained within the zip file:1234567_Albert_Einstein_1.zipHow the work should be submitted?Should be submitted electronically through the Learning Mall system so that themarker can run your programs during marking. Feedback and your grade will alsobe given through the Learning Mall system.

March 11, 2022 · 5 min · jiezi

关于c++:RBE104TC-分析

RBE104TC C/C++ Programming LanguageAssignment 2 Assignment Overview:This assignment aims at testing some basic concepts of the C++ programming andinitiates the routine of code development using the software development process(SDP) presented in the relevant lectures. It focuses on the following five steps ofthe SDP. Problem statement: formulate the problem;Analysis: determine the inputs, outputs, variables, etc.;Design: define the list of steps (the algorithm) needed to solve theproblem;Implementation: the C code has to be submitted as a separate file, justindicate here the name of the file;Testing: explain how you have tested and verified your C program.You will need to apply this methodology to each one of the following simpleexercises.Things to note:Include clear comments in your code to make it easy to understand.Explain your testing procedure and what you have observed during thetesting. The testing should be demonstrated by screenshot pictures topresent the actual implementation output.How you solved any problems.Contribution to the Overall Marks 60%Issue DateSubmission Deadline Dec. 23rd, 2020/ 5Exercise 1:Design a new class to represent a fraction (anation of two integer values).The data members of the class Fraction are twointegers, top and down, denoting the numeratorand denominator, respectively.class Fraction{private:int top; // Numeratorint bottom; // Denominatorpublic:. . . . . .};Part 1: Fundamental requirements for the class Fraction.Fractional numbers can be declared with both a numerator and denominator,or simple numerator:Fraction a; // represents 0/1Fraction b(3,4); // represents 3/4Fraction c(5); // represents 5/1Fractions should be able to act just like other numbers.Add, subtract, multiple and divide;Compare based on values;Input and output.Part 2: Advanced requirementsFractional number is normalized to ensure that only the numerator can benegative and the value is in the least common denominator form:• 2/-3 would be converted into -2/3 automatically;• 15/21 would be converted into 5/7 automatically.Write methods to convert between decimals and fractions.Exercise 2:Derive a sub-class iFraction from the base class Fraction, which was designed byyou in Exercise 2 of Assessment 2. The iFraction class represents the mixedfractions like ;Part 1: Design the sub-class iFraction:• It should have a constructor for initialisation;• It should contain a method to display the mixed fraction on screen;Part 2: Design an external function convertF (not function member of class Fractionand iFraction) to convert the improper fractions to mixed fractions.Hint: convertF can be the friend function of those two classes.Exercise 3:Design a composite class that represents complex numbers whose real andimaginary parts are Fractions.• Write appropriate constructors for this class;• Complex numbers should be able to add, subtract and multiple./ 5Exercise 4:This is a computer game with different types of players. Take the code provided forthe container class (container.h), player class (player.h), and the swordsman class(swordsman.h), and the main function (main.cpp).Part 1:Read the source codes, understand the meaning and fill the blank (shownas) to make it work;Generate the CRC cards of the classes: clarify the responsibilities of eachclass, illustrate the collaboration with others, and label all the members’ aspublic, protected, and private. Then draw the hierarchy chart of them;Part 2:Design another two classes, archer and mage. Generate their CRC cardand put them in the hierarchy chart drew above. Write the code for these twoclasses and make them work (cooperate with the main function);Modify the main function, to have enemies with all three professions (couldbe randomly chosen).Part 3 (Optional): Can you involve another attribute – luck, in this game?Notes: The factors are imperfect, make the fight too hard or too easy. Changewhatever you want, but leave hints for reviewers to know what you have done./ 5What should be submitted?You should submit the followings:1). A short report (up to a few pages of text plus C source codes) detailing for eachquestion:a). SDP steps 1 to 3 in the report (Report + Specification + Analysis +Algorithm Design) (40%);b). SDP step 4 (Implementation + Robustness): your C source code includingthe comments. (40%);c). SDP step 5 (testing): you will explain how you have tested the correctnessof your C program and will include some sample runs of your C Programs.(20%);Please refer to the file Marking Guidelines for RBE104TC.pdf on the Learning Mallsystem for a detailed marking scheme.2). The report in Microsoft Word or pdf format and C source code of yourimplementation zipped into a single file, i.e. the zip file will contain 2 files. (It is goodpractice to include comments in your code see the example provided.)The naming of Report (.doc, .docx or .pdf only), Source Code (.c) and Compressedfile (.zip, or .rar only)StudentID_LastName_FirstName_AssignmentNumber.docStudentID_ AssignmentNumber.cStudentID_LastName_FirstName_AssignmentNumber.zipFor example:Report and c source file named:1234567_Albert_Einstein_1.doc1234567_1.cContained within the zip file:1234567_Albert_Einstein_1.zipHow the work should be submitted?Should be submitted electronically through the Learning Mall system so that themarker can run your programs during marking. Feedback and your grade will alsobe given through the Learning Mall system.

March 11, 2022 · 4 min · jiezi

关于c++:读书笔记

调试Crash-g 保留了源码级别的调试信息(变量名称、函数名称、代码行的映射),能够通过strip或者objcopy删去调试信息。依据core dump产生时的调用栈和代码行号信息去看源代码。利用gdb调试core文件,查看堆栈以及变量。内存被毁坏,个别状况下core的时候曾经不是内存毁坏的第一现场了(早就被毁坏了)SEGV_MAPPER => 没有被映射(空指针、低地址指针)SEGV_ACCERR => 没有权限(试图批改只读区域)64位零碎中,0x0000000007fffffffffffff 以下为user,0xfffffffffffff8000000以上为kernel。 低地址、空指针问题虚函数调用问题:越界、溢出导致this被写坏,虚指针指向谬误,导致运行时谬误。野指针、空悬指针无栈协程无栈协程不会进行寄存器级别的上下文保留和复原,只是将函数执行到的地位记录在协程对象的成员变量中,协程函数通过switch case 和 跳转宏,在复原执行时跳转到指定地位执行。并非没有stack,而是在以后的stack下面创立协程栈帧,不会为协程指定独立的stack空间。 有栈协程能够在嵌套的栈帧中暂停(随时随地挂起),无栈协程只能在顶层栈帧暂停,在协程中调用的函数不能被暂停。 无栈协程应用宿主栈,没有独自协程栈。 对称协程 vs 非对称协程对称协程提供 pass control 语义(交出控制权),非对称协程提供 yield、resume语义,由管制协程进行调度。

March 10, 2022 · 1 min · jiezi

关于c++:zbh的协程学习总结

IO倒退历程1从同步IO谈起 长期以来,应用C/C++编写服务器程序的时候,应用的往往是多过程模式:一个父过程负责 accept 传入连贯,而后 fork 一个子过程解决;或者是一个父过程创立了一个 socket 之后,fork 出多个子过程同时执行 accept 和解决,(例如Apache Http Server 2.4版本前,采纳per request per thread模型2)。 这时候个别应用同步IO来解决,也就是应用阻塞的read、write,当过程被IO阻塞的时候挂起过程。益处是这种同步开发方式和人类思维相近,编写简略。害处之一是效率低:随着C10K问题3的提出,在高并发场景下,cpu忙于过程或线程的切换,大量cpu工夫被节约。 异步IO降临 所谓异步IO,就是发动IO申请的线程不等IO操作实现,就继续执行随后的代码,IO后果用其余形式告诉发动IO申请的程序。 最简略的情景就是通过设置O_NONBLOCK标记应用非阻塞的read、write,定时轮询资源是否可用。如果资源不可用,会返回相应的谬误如EAGAIN。 然而在并发量很大时,cpu同样失陷于轮询中,效率很低(次要是每次都要进行零碎调用,开销大)。有没有什么办法让咱们被动接管资源就绪的告诉,而不是一一被动轮询呢?在Linux下,咱们能够应用select/poll/epoll来同时监听多个文件描述符,看似将非阻塞IO阻塞在了select/poll/epoll中,然而这种形式监听了多个描述符,而且防止了大部分无用的零碎调用开销。 益处是高效:没有切换上下文的开销、没有过程间同步、通信问题,然而害处是开发不便。异步IO须要配合基于事件驱动的异步开发模式。在EventLoop中,什么事件到来,就调用相应的回调函数进行解决,和传统同步思维有很大不同。(std::function满天飞~,容易毁坏逻辑的连续性)。 协程退场 有种说法是协程是一种轻量级的线程,这是针对它不须要操作系统调度染指、开销小而言,然而我感觉不够精确。实质上,协程就是一个能够暂停的函数,遇到阻塞的时候,就让出cpu,当条件满足了就持续复原运行。 从另一个角度来说,协程和过程、线程的区别就是两点 – 是否隔离变量,是否主动切换运行上下文。满足这两点区别的,就是协程。 过程:变量隔离,主动切换运行上下文线程:不变量隔离,主动切换运行上下文切换协程:不变量隔离,不主动切换运行上下文切换在不隔离变量的状况下,主动切换运行上下文,几乎就是 bug 之源,这两件事基本就不该同时反对。当前线程这个货色,应该被扫进历史的垃圾堆,线程带来的便当,比起它挖出的坑相比,有余一提。4 之所以在协程的总结小文中上来就谈到这么多IO相干内容,是因为C++中的协程和IO有很大关系。协程实用于IO密集型利用,而非CPU密集型利用。协程的 暂停期待条件满足后复原执行 的特点人造适宜IO。当文件描述符不可读/不可写时,让出cpu;可读/可写后被复原执行,持续解决相应逻辑。让出cpu的动作与同步IO中过程/线程被阻塞而挂起相似,然而防止了过程/线程调度开销,而保留了同步IO的同步开发方式。这正是协程的弱小之处: 并发 + 同步5。 协程分类6协程能够依照以下 3 个角度进行分类 对称/不对称:前者提供让出执行权的原语,后者提供唤起协程和把执行权转交给调用者的原语第一类/受限:协程是不是第一类对象有栈/无栈:协程能在调用栈的任意处挂起,还是只能在协程的函数体内挂起这里看第三个分类的区别: 此处「有栈」和「无栈」的含意不是指协程在运行时是否须要栈,对于大多数语言来说,一个函数调用另一个函数,总是存在调用栈的; 而是指协程是否能够在其任意嵌套函数中被挂起,此处的嵌套函数能够了解为子函数、匿名函数等。显然有栈协程是能够的,而无栈协程则不能够。 它们的次要区别是:有栈协程能在调用栈的任意处挂起,无栈协程只能在协程的函数体内挂起。 有栈协程很多中央又把协程称为 subroutine,subroutine 是什么,就是函数。上古期间的计算机科学家们早就给出了概念,coroutine 就是能够中断并复原执行的 subroutine,从这个角度来看协程领有调用栈并不是一个奇怪的事件。 咱们再来思考 coroutine 与 subroutinue 相比有什么区别,你会发现区别仅有一个,就是 coroutinue 能够中断并复原,对应的操作就是 yield/resume,这样看来 subroutinue 不过是 coroutinue 的一个子集罢了。 也就是说把协程当做一个非凡的函数调用,有栈协程就是咱们现实中协程该有的模样。 既然把其当做一个非凡的函数调用,对咱们来说最严厉的挑战就是如何像切换函数一样去切换协程,难点在于除了像函数一样切换进来,还要在某种条件满足的时候切换回来,咱们的做法能够是 在协程外部存储本身的上下文,并在须要切换的时候把上下文切换就能够了。 ...

March 9, 2022 · 9 min · jiezi

关于c++:xmake-v264-发布大量包管理特性改进

Xmake 是一个基于 Lua 的轻量级跨平台构建工具。 它十分的轻量,没有任何依赖,因为它内置了 Lua 运行时。 它应用 xmake.lua 保护我的项目构建,相比 makefile/CMakeLists.txt,配置语法更加简洁直观,对老手十分敌对,短时间内就能疾速入门,可能让用户把更多的精力集中在理论的我的项目开发上。 咱们可能应用它像 Make/Ninja 那样能够间接编译我的项目,也能够像 CMake/Meson 那样生成工程文件,另外它还有内置的包管理系统来帮忙用户解决 C/C++ 依赖库的集成应用问题。 目前,Xmake 次要用于 C/C++ 我的项目的构建,然而同时也反对其余 native 语言的构建,能够实现跟 C/C++ 进行混合编译,同时编译速度也是十分的快,能够跟 Ninja 持平。 Xmake = Build backend + Project Generator + Package Manager我的项目源码官网文档入门课程新个性介绍更灵便的包扩大当初,咱们能够通过 set_base 接口去继承一个已有的包的全副配置,而后在此基础上重写局部配置。 这通常在用户本人的我的项目中,批改 xmake-repo 官网仓库的内置包比拟有用,比方:修复改 urls,批改版本列表,装置逻辑等等。 例如,批改内置 zlib 包的 url,切到本人的 zlib 源码地址。 package("myzlib") set_base("zlib") set_urls("https://github.com/madler/zlib.git")package_end()add_requires("myzlib", {system = false, alias = "zlib"})target("test") set_kind("binary") add_files("src/*.c") add_packages("zlib")咱们也能够用来单纯增加一个别名包。 package("onetbb") set_base("tbb")咱们能够通过 add_requires("onetbb") 集成装置 tbb 包,只是包名不同而已。 包治理反对工具链切换之前,咱们限度了只能在 cross 平台下切换包装置的工具链,新版本中,咱们能够反对更多平台下,对工具链的切换。 ...

March 8, 2022 · 2 min · jiezi

关于c++:C的引用类型的掌握

援用类型是C++新减少的一个类型,也是十分体现C++特点的一个类型,始终晓得其是别名,但具体含意必须精确把握,能力精确的利用,其留神点如下: 1、定义:援用是已定义的变量的别名(另一个名称) 2、用处:援用变量的主要用途是用作函数的形参 3、应用注意事项:必须在申明援用时进行初始化(援用更靠近const指针,必须在创立时进行初始化,一旦与某个变量关联起来,就将始终效忠于它) 这三点记住,就能够说把握了援用的用法,哪一点不了解到位,应用过程中都报错。 比方第一点,定义,援用是已定义的变量的别名,其含意就是首先存在一个变量,这是前提条件,否则的话,编译就会报错,用一个例子展现一下: 1 #include <iostream> 2 #include <stdio.h> 3 4 int getMax(int &a, int &b) 5 { 6 int max; 7 if(a > b) 8 max = a; 9 else 10 max = b; 11 return max; 12 } 13 14 int main() 15 { 16 using namespace std; 17 int a1 = 2; 18 int b1 = 3; 19 int max = getMax(2, 3); 20 printf("max = %d\r\n", max); 21 int max = getMax(a1, b1); 22 printf("max = %d\r\n", max); 23 return 0; 24 }是不是,看着下面的代码挺失常的,我一开始也是感觉这样的,间接隐形转化不就能够了,理论不是这样的,如果你这样想,编译就开始打你耳光了。 ...

March 7, 2022 · 2 min · jiezi

关于c++:C与QT的sprintf的用法

反正常常用sprintf这个函数,因为太好用了吧。 通过这个,能够拼字符串,包含各种类型的变量,都能够组装到外面,拼字符串是程序最常常的一个操作了,能够说,很多程序就是组装字符串的过程,记得一个同学以前说过:程序的实质不就是解决数据吗?是啊,就是这点事。 用法是统一的,如下: C 库函数 int sprintf(char str, const char format, ...) 发送格式化输入到 str 所指向的字符串这就是他们独特的中央,不同的就是QT通过面向对象封装了一下,如此而已。上面总结了在C++与QT当中这种函数的用法,很简略,两者比照着记,印象更深一些吧: void MainWindow::on_pushButton_3_clicked(){ //1、c++的字符串格式化 char a[12] = "this is c "; char b[64] = {0}; sprintf(b, "function %s ", a); qDebug()<<b; //2、QT的字符串格式化 QString info = "this is a test"; //1.1/QT的第一种用法,实例调用法: QString test; test.sprintf("function:%s", info.toStdString().c_str()); qDebug()<<info; qDebug()<<test; //1.2/QT的第二种用法,动态调用法: QString info2 = QString::asprintf("function:%s", info.toStdString().c_str()); qDebug()<< info2;}输入状况如下: function this is c "this is a test""function:this is a test""function:this is a test"

March 7, 2022 · 1 min · jiezi

关于c++:C-workflow异步调度框架-架构设计篇

最近在致力同步保护SegmentFault的文章积攒~不便后续继续更新~ 原文是2019年7月底开源后陆续po的,这里对近况进行了调整和补充。 心愿本人和我的项目都能够继续提高 (╹ヮ╹)ノ 欢送多多交换!!尽管我更新本博客比较慢,然而github上的workflow我的项目自身在继续更新中~这一年多以来改了好多好多。这里仅列出一些根本的特点: 包含通信、计算、文件IO、定时器、计数器等异步资源创新性引入的工作流概念,各种异步工作都能够被对等地组装起来实现简单的业务逻辑外部自带多种通用协定,包含http,redis,mysql和kafka等跨平台、反对多种操作系统自带命名服务,包含过程内服务治理与负载平衡,轻松构建微服务零碎实用于实现任何计算与通信关系非常复杂的高性能高并发的后端服务附上github地址: https://github.com/sogou/workflow 明天我还是要抱着跟大家学习的心态,急不可待要从整体的角度来写一下workflow的架构。并且郑重声明一下,本篇只是自己作为开发者之一、想尽快和大家学习交换而写的集体梳理,咱们并没有官网号或公司内其余技术号去发文章,所以这里就当做是其中一个开发者的一丢丢分享了~ 架构设计必然是从底向上开始,所以咱们间接从kernel目录的设计思路开始聊。 1. 封装调度器上次说到,咱们作为异步调度框架,目前反对的异步调度资源分为6种: 这里能够举大家平时接触最多的网络通信框架和计算调度框架作为重点解说一下。 咱们须要封装调度器去操作这些系统资源,简略来说就是操作一批网络连接或者说线程。留神这里说的“操作”,也就是说调度器远不止连接池和线程池那么简略,咱们要做的事件是: 蕴含与治理资源池实现如何对一批连贯尽可能高性能地响应其读写、如何尽可能快且尽可能通用地给出一个足够灵便的机制去让各线程执行各种计算提供申请接口给下层应用咱们以线程执行器Executor为例来看看具体怎么做。以上第二点尽可能快又足够灵便的机制,就是咱们设计的ExecQueue,在以下代码得以体现: class Executor{public: // 一次要执行的接口,对于线程执行器来说,就是把一个执行工作扔进某个队列中 int request(ExecSession *session, ExecQueue *queue);private: // 执行器和系统资源,是一个蕴含关系 thrdpool_t *thrdpool;};2. 封装调度的根本单位构思完了调度器,咱们须要构思一下被调度的根本单位。 对应每种能够调度对象的零碎接口,咱们必须封装本人的构造,作为每次与系统资源交互的根本单位,通过调度器提供的申请接口,扔到调度器里被调度。 具体来说,这显然是一次网络交互、或者一次线程须要执行的计算工作。而后每个根本单位上,能够有上下文、供子类做具体实现的接口/函数指针等等。 咱们以网络交互为例: class CommSession{ // 往连贯上要发的数据 virtual CommMessageOut *message_out() = 0; // 连贯上收到数据流,如何切下一个数据包 virtual CommMessageIn *message_in() = 0; // 本次网络事件被响应的机会 virtual void handle(int state, int error) = 0; … // 个别咱们的上下文是存在派生类上};阶段性总结一下,写到这里,咱们就能够欢快地做网络收发或者线程调度了~这些模块都曾经是能够独自拆出来用的。 作为框架,咱们基于上述的多种调度器和调度单位,能够给用户封装各种具体网络协议和计算算法。然而这还不是咱们的串并行任务零碎的外围价值。 3. 工作流咱们想要实现工作流(无论是DAG还是串并连),意味着咱们须要一套机制去按程序触发具体的子工作执行、并接管其执行完之后要做的事件。实现的形式有很多,咱们做了一套子工作零碎来满足形象的任务调度,而这个工作自身是网络通信还是计算,都不重要。 因为咱们的子工作是要给异步框架用的,所以每个工作你不能只有一个接口:execute()之类,咱们必须有开始执行的dispatch()和执行结束的done()两个须要实现,而工作流零碎自身只是做按程序调起你的开始和完结这两个接口的事件。 class SubTask{ // 子工作被调起的机会 virtual void dispatch() = 0; // 子工作执行实现的机会 virtual SubTask *done() = 0; // 外部实现,决定了工作流走向 void subtask_done(); … };对于工作流,之后会具体介绍其概念,有做相似事件的小伙伴欢送多多交换互相学习,我也会多翻阅一些材料再写,这是十分十分有意思的一个主题。 ...

March 7, 2022 · 2 min · jiezi

关于c++:2022武汉中科创达技术面试C开发工程师

自我介绍-英文Hello, interviewer, my name is **. I am from the School of Computer Science, Wuhan University of Technology, majoring in Internet of Things Engineering. My undergraduate gpa is 3.58, ranking in the top 5% of my major. Courses studied during the undergraduate course include object-oriented programming, algorithms and data structures. My hobbies are playing basketball and running. This concludes my self-introduction, thank you! 业余问题1.过程与线程问题2.static变量作用 总结这家很水,惟一惊喜之处在于英文的自我介绍。没有金山有程度,顺利通过计面。

March 6, 2022 · 1 min · jiezi

关于c:C语言编程程序的内存如何布局

 一:C语言程序的存储区域 由C语言代码(文本文件)造成可执行程序(二进制文件),须要通过编译-汇编-连贯三个阶段。编译过程把C语言文本文件生成汇编程序,汇编过程把汇编程序造成二进制机器代码,连贯过程则将各个源文件生成的二进制机器代码文件组合成一个文件。 C语言编写的程序通过编译-连贯后,将造成一个对立文件,它由几个局部组成。在程序运行时又会产生其余几个局部,各个局部代表了不同的存储区域: 1.代码段(Code或Text) 代码段由程序中执行的机器代码组成。在C语言中,程序语句进行编译后,造成机器代码。在执行程序的过程中,CPU的程序计数器指向代码段的每一条机器代码,并由处理器顺次运行。 2.只读数据段(RO data) 只读数据段是程序应用的一些不会被更改的数据,应用这些数据的形式相似查表式的操作,因为这些变量不须要更改,因而只须要搁置在只读存储器中即可。 3.已初始化读写数据段(RW data) 已初始化数据是在程序中申明,并且具备初值的变量,这些变量须要占用存储器的空间,在程序执行时它们须要位于可读写的内存区域内,并具备初值,以供程序运行时读写。 4.未初始化数据段(BSS) 未初始化数据是在程序中申明,然而没有初始化的变量,这些变量在程序运行之前不须要占用存储器的空间。 5.堆(heap) 堆内存只在程序运行时呈现,个别由程序员调配和开释。在具备操作系统的状况下,如果程序没有开释,操作系统可能在程序(例如一个过程)完结后回收内存。 6.栈(stack) 栈内存只在程序运行时呈现,在函数外部应用的变量、函数的参数以及返回值将应用栈空间,栈空间由编译器主动调配和开释。 C语言指标文件的内存布局 看一个例子: int a = 0; //全局初始化区,。data段 static int b=20; //全局初始化区,。data段 char *p1; //全局未初始化区 .bss段 const int A = 10; //.rodata段 void main(void) { int b; //栈 char s[] = "abc"; //栈 ...

March 6, 2022 · 2 min · jiezi

关于c++:聊聊第一个开源项目内网穿透-CProxy

文章首发:聊聊第一个开源我的项目 - CProxy 作者:会玩code 初衷最近在学C++,想写个我的项目练练手。对网络比拟感兴趣,之前应用过ngrok(GO版本的内网穿透我的项目),看了局部源码,想把本人的一些优化想法用C++实现一下,便有了这个我的项目。 我的项目介绍CProxy是一个反向代理,用户可在本人内网环境中启动一个业务服务,并在同一网络下启动CProxyClient,用于向CProxyServer注册服务。CProxyClient和CProxyServer之间会创立一个隧道,外网能够通过拜访CProxyServer,数据转发到CProxyClient,从而被业务服务接管到。实现内网服务被外网拜访。 我的项目地址https://github.com/lzs123/CProxy.git应用办法bash build.sh// 启动服务端{ProjectDir}/build/server/Server --proxy_port=8090 --work_thread_nums=4(另一个终端) // 启动客户端{ProjectDir}/build/client/Client --local_server=127.0.0.1:7777 --cproxy_server=127.0.0.1:8080我的项目亮点应用epoll作为IO多路复用的实现数据转发时,应用splice零拷贝,缩小IO性能瓶颈数据连贯和管制连贯接耦,防止相互影响采纳Reactor多线程模型,充分利用多核CPU性能流程架构角色LocalServer: 内网业务服务CProxyClient: CProxy客户端,个别与LocalServer部署在一起,对接CProxyServer和InnerServerCProxyServer: CProxy服务端PublicClient: 业务客户端数据流PublicClient先将申请打到CProxyServer,CProxyServer辨认申请是属于哪个CProxyClient,而后将数据转发到CProxyClient,CProxyClient再辨认申请是属于哪个LocalServer的,将申请再转发到LocalServer,实现数据的转发。 工作流程先介绍CProxyServer端的两个概念: Control:在CProxyServer中会保护一个ControlMap,一个Control对应一个CProxyClient,存储CProxyClient的一些元信息和管制信息Tunnel:每个Control中会保护一个TunnelMap,一个Tunnel对应一个LocalServer服务在CProxyClient端,也会保护一个TunnelMap,每个Tunnel对应一个LocalServer服务,只不过Client端的Tunnel与Server端的Tunnel存储的内容略有差别 启动流程CProxyServer实现几种工作线程的初始化。监听一个CtlPort,期待CProxyClient连贯。CProxyClient实现对应线程的初始化。而后连贯Server的CtlPort,此连贯称为ctl_conn, 用于client和server之前管制信息的传递。申请注册Control,获取ctl_id。最初再依据Tunnel配置文件实现多个Tunnel的注册。须要留神的是,每注册一个Tunnel,Server端就会多监听一个PublicPort,作为内部拜访LocalServer的入口。数据转发流程Web上的PublicClient申请CProxyServer上的PublicPort建设连贯;CProxyServer接管连贯申请,将public_accept_fd封装成PublicConn。CProxyServer通过ctl_conn向client发送NotifyClientNeedProxyMsg告诉Client须要创立一个proxy。Client收到后,会别离连贯LocalServer和CProxyServer: 3.1. 连贯LocalServer,将local_conn_fd封装成LocalConn。 3.2. 连贯ProxyServer的ProxyPort,将proxy_conn_fd封装成ProxyConn,并将LocalConn和ProxyConn绑定。CProxyServer的ProxyPort收到申请后,将proxy_accept_fd封装成ProxyConn,将ProxyConn与PublicConn绑定。尔后的数据在PublicConn、ProxyConn和LocalConn上实现转发传输。 连贯治理复用proxy连贯为了防止频繁创立销毁proxy连贯,在实现数据转发后,会将proxyConn放到闲暇队列中,期待下次应用。proxy_conn有两种模式 - 数据传输模式和闲暇模式。在数据传输模式中,proxy_conn不会去读取解析缓冲区中的数据,只会把数据通过pipe管道转发到local_conn; 闲暇模式时,会读取并解析缓冲区中的数据,此时的数据是一些管制信息,用于调整proxy_conn自身。 当有新publicClient连贯时,会先从闲暇列表中获取可用的proxy_conn,此时proxy_conn处于闲暇模式,CProxyServer端会通过proxy_conn向CProxyClient端发送StartProxyConnReqMsg,CLient端收到后,会为这个proxy_conn绑定一个local_conn, 并将工作模式置为数据传输模式。之后数据在这对proxy_conn上进行转发。 数据连贯断开解决close和shutdown的区别 close int close(int sockfd)在不思考so_linger的状况下,close会敞开两个方向的数据流。 读方向上,内核会将套接字设置为不可读,任何读操作都会返回异样;输入方向上,内核会尝试将发送缓冲区的数据发送给对端,之后发送fin包完结连贯,这个过程中,往套接字写入数据都会返回异样。若对端还发送数据过去,会返回一个rst报文。留神:套接字会保护一个计数,当有一个过程持有,计数加一,close调用时会查看计数,只有当计数为0时,才会敞开连贯,否则,只是将套接字的计数减一。 shutdown int shutdown(int sockfd, int howto)shutdown显得更加优雅,能管制只敞开连贯的一个方向 howto = 0 敞开连贯的读方向,对该套接字进行读操作间接返回EOF;将接收缓冲区中的数据抛弃,之后再有数据达到,会对数据进行ACK,而后轻轻抛弃。howto = 1 敞开连贯的写方向,会将发送缓冲区上的数据发送进来,而后发送fin包;应用程序对该套接字的写入操作会返回异样(shutdown不会查看套接字的计数状况,会间接敞开连贯)howto = 2 0+1各操作一遍,敞开连贯的两个方向。我的项目应用shutdown去解决数据连贯的断开,当CProxyServer收到publicClient的fin包(CProxyClient收到LocalServer的fin包)后,通过ctlConn告诉对端,对端收到后,调用shutdown(local_conn_fd/public_conn_fd, 2)敞开写方向。等收到另一个方向的fin包后,将proxyConn置为闲暇模式,并放回闲暇队列中。 在解决链接断开和复用代理链接这块遇到的坑比拟多 管制对端去shutdown连贯是通过ctl_conn去告诉的,可能这一方向上对端的数据还没有全副转发实现就收到断开告诉了,须要确保数据全副转发完能力调用shutdown去敞开连贯。从闲暇列表中拿到一个proxy_conn后,须要发送StartProxyConnReq,告知对端开始工作,如果此时对端的这一proxy_conn还处于数据传输模式,就会报错了。数据传输数据在Server和Client都需进行转发,将数据从一个连贯的接收缓冲区转发到另一个连贯的发送缓冲区。如果应用write/read零碎调用,整个流程如下图 数据先从内核空间复制到用户空间,之后再调用write零碎调用将数据复制到内核空间。每次零碎调用,都须要切换CPU上下文,而且,两次拷贝都须要CPU去执行(CPU copy),所以,大量的拷贝操作,会成为整个服务的性能瓶颈。 在CProxy中,应用splice的零拷贝计划,数据间接从内核空间的Source Socket Buffer转移到Dest Socket Buffer,不须要任何CPU copy。 splice通过pipe管道“传递”数据,基本原理是通过pipe管道批改source socket buffer和dest socket buffer的物理内存页 ...

March 6, 2022 · 1 min · jiezi

关于c++:C语言带参宏定义和函数的区别

带参数的宏和函数很类似,但有实质上的区别:宏开展仅仅是字符串的替换,不会对表达式进行计算;宏在编译之前就被解决掉了,它没有机会参加编译,也不会占用内存。而函数是一段能够重复使用的代码,会被编译,会给它分配内存,每次调用函数,就是执行这块内存中的代码。 【示例①】用函数计算平方值。 运行后果:1^2 = 12^2 = 43^2 = 94^2 = 165^2 = 25 【示例②】用宏计算平方值。 在 Visual Studio 和 C-Free 下的运行后果(其它编译器的运行后果可能不同,这个++运算的程序无关):3^2 = 15^2 = 97^2 = 25 在示例①中,先把实参 i 传递给形参 y,而后再自增 1,这样每循环一次 i 的值减少 1,所以最终要循环 5 次。 在示例②中,宏调用只是简略的字符串替换,SQ(i++) 会被替换为 ((i++)*(i++)),这样每循环一次 i 的值减少 2,所以最终只循环 3 次。 由此可见,宏和函数只是在模式上类似,实质上是齐全不同的。 带参数的宏也能够用来定义多个语句,在宏调用时,把这些语句又替换到源程序中,请看上面的例子: 运行后果:sa=12, sb=15, sc=20, vv=60

March 5, 2022 · 1 min · jiezi

关于c:COMP1711XJCO1711-解析

University of Leeds School of ComputingProcedural Programming COMP1711/XJCO1711Semester 1, 2020-2021Coursework 3100 Marks (40% of the total module mark)To be submitted before: 23:00 (UK time) on 11 December 2020Late penalties: 5% will be deducted from the overall mark of this coursework for everylate daySkills TestedThis coursework will test your ability to write C code that correctly uses structures, character strings,pointers, and file i/o. You will also learn how a program can be divided across multiple source files.The BriefYou will write a program that allows people to name pairs of stars in a hypothetical universe by theirnames.The DetailsAn astronomer wanted to surprise their spouse on their anniversary by showing them a simulation ofthe Big Bang on a computer, then naming the closest pair of stars created by this Big Bang with theirnames. Big Bang is the name of a cosmological theory that assumes that the universe started from theexpansion of a single very high-density singularity.Fortunately, the program is not supposed to go anywhere close to a real simulation of the Big Bang.For the purposes of this simple program, our Big Bang simply fills a flat rectangular space with starsscattered at random positions. The program then allows a user to find the closest pair of unnamedstars in this universe and assign the user’s name to the first star in this pair, and the name of the user’sspouse to the second star.The TaskWrite a command driven program that accepts the following commands:The bang commandThis command creates a hypothetical universe comprised of stars only. The stars should be randomlyscattered across the universe.We are assuming that the universe is flat and rectangular and is 60 light years long and 30 light yearswide. A light year is a unit of measure of distance and is equal to the distance that light can travel inone year (5.879x1012 miles). Do not get daunted by this jargon, just assume that your space is arectangle 60 units long and 30 units wide.The bang command takes one integer argument representing the number of stars to be created. Forexample, if the player types: ...

March 5, 2022 · 9 min · jiezi

关于c++:C-重载运算符和重载函数

C++ 容许在同一作用域中的某个函数和运算符指定多个定义,别离称为函数重载和运算符重载。 重载申明是指一个与之前曾经在该作用域内申明过的函数或办法具备雷同名称的申明,然而它们的参数列表和定义(实现)不雷同。 当您调用一个重载函数或重载运算符时,编译器通过把您所应用的参数类型与定义中的参数类型进行比拟,决定选用最合适的定义。抉择最合适的重载函数或重载运算符的过程,称为重载决策。 C++ 中的函数重载在同一个作用域内,能够申明几个性能相似的同名函数,然而这些同名函数的形式参数(指参数的个数、类型或者程序)必须不同。您不能仅通过返回类型的不同来重载函数。 C++ 中的运算符重载您能够重定义或重载大部分 C++ 内置的运算符。这样,您就能应用自定义类型的运算符。 重载的运算符是带有非凡名称的函数,函数名是由关键字 operator 和其后要重载的运算符符号形成的。与其余函数一样,重载运算符有一个返回类型和一个参数列表。 Box operator+(const Box&);申明加法运算符用于把两个 Box 对象相加,返回最终的 Box 对象。大多数的重载运算符可被定义为一般的非成员函数或这被定义为类成员函数。如果咱们定义下面的函数为类的非成员函数,那么咱们须要为每次操作传递两个参数,如下所示: Box operator+(const Box&, const Box&); 可重载运算符/不可重载运算符上面是可重载的运算符列表:

March 5, 2022 · 1 min · jiezi

关于c:C语言字符串处理函数

C语言提供了丰盛的字符串处理函数,能够对字符串进行输出、输入、合并、批改、比拟、转换、复制、搜寻等操作,应用这些现成的函数能够大大加重咱们的编程累赘。 用于输入输出的字符串函数,例如printf、puts、scanf、gets等,应用时要蕴含头文件stdio.h,而应用其它字符串函数要蕴含头文件string.h。 string.h是一个专门用来解决字符串的头文件,它蕴含了很多字符串处理函数,解说几个罕用的。 字符串连贯函数 strcat() strcat 是 string catenate 的缩写,意思是把两个字符串拼接在一起,语法格局为: strcat(arrayName1, arrayName2); arrayName1、arrayName2 为须要拼接的字符串。 strcat() 将把 arrayName2 连贯到 arrayName1 前面,并删除原来 arrayName1 最初的完结标记'\0'。这意味着,arrayName1 必须足够长,要可能同时包容 arrayName1 和 arrayName2,否则会越界(超出范围)。 strcat() 的返回值为 arrayName1 的地址。 字符串复制函数 strcpy() strcpy 是 string copy 的缩写,意思是字符串复制,也行将字符串从一个中央复制到另外一个中央,语法格局为: strcpy(arrayName1, arrayName2); strcpy() 会把 arrayName2 中的字符串拷贝到 arrayName1 中,字符串完结标记'\0'也一起拷贝。 strcpy() 要求 arrayName1 要有足够的长度,否则不能全副装入所拷贝的字符串。 字符串比拟函数 strcmp() strcmp 是 string compare 的缩写,意思是字符串比拟,语法格局为: strcmp(arrayName1, arrayName2); arrayName1 和 arrayName2 是须要比拟的两个字符串。 字符自身没有大小之分,strcmp() 以各个字符对应的 ASCII 码值进行比拟。strcmp() 从两个字符串的第 0 个字符开始比拟,如果它们相等,就持续比拟下一个字符,直到遇见不同的字符,或者到字符串的开端。 ...

March 4, 2022 · 1 min · jiezi

关于c:C语言形参和实参的区别

C语言函数的参数会呈现在两个中央,别离是函数定义处和函数调用处,这两个中央的参数是有区别的。 形参(形式参数)在函数定义中呈现的参数能够看做是一个占位符,它没有数据,只能等到函数被调用时接管传递进来的数据,所以称为形式参数,简称形参。 实参(理论参数)函数被调用时给出的参数蕴含了实实在在的数据,会被函数外部的代码应用,所以称为理论参数,简称实参。 形参和实参的性能是传递数据,产生函数调用时,实参的值会传递给形参。形参和实参的区别和分割 1) 形参变量只有在函数被调用时才会分配内存,调用完结后,立即开释内存,所以形参变量只有在函数外部无效,不能在函数内部应用。 2) 实参能够是常量、变量、表达式、函数等,无论实参是何种类型的数据,在进行函数调用时,它们都必须有确定的值,以便把这些值传送给形参,所以应该提前用赋值、输出等方法使实参取得确定值。 3) 实参和形参在数量上、类型上、程序上必须严格统一,否则会产生“类型不匹配”的谬误。当然,如果可能进行主动类型转换,或者进行了强制类型转换,那么实参类型也能够不同于形参类型。 4) 函数调用中产生的数据传递是单向的,只能把实参的值传递给形参,而不能把形参的值反向地传递给实参;换句话说,一旦实现数据的传递,实参和形参就再也没有瓜葛了,所以,在函数调用过程中,形参的值产生扭转并不会影响实参。

March 4, 2022 · 1 min · jiezi

关于c:62-不同路径

一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为 “Start” )。 机器人每次只能向下或者向右挪动一步。机器人试图达到网格的右下角(在下图中标记为 “Finish” )。 问总共有多少条不同的门路? 示例 1:输出:m = 3, n = 7输入:28 示例 2:输出:m = 3, n = 2输入:3解释:从左上角开始,总共有 3 条门路能够达到右下角。 向右 -> 向下 -> 向下向下 -> 向下 -> 向右向下 -> 向右 -> 向下示例 3:输出:m = 7, n = 3输入:28 示例 4:输出:m = 3, n = 3输入:6 提醒:1 <= m, n <= 100题目数据保障答案小于等于 2 * 109 解决办法1:递归遍历通过递归,列出所有可能性,递归进行条件为机器人走到边界或走到起点,如果是起点,total+1 void move(int curX,int curY,int m, int n,int *total) { if (curX < n - 1) { move(curX + 1, curY, m, n,total); } if (curY < m - 1) { move(curX, curY + 1, m, n,total); } if (curX == n - 1 && curY == m - 1) { *total = *total + 1; }}int uniquePaths(int m, int n) { int total = 0; move(0, 0, m, n,&total); printf("%d\n", total); return total;}解决办法2.每列求门路可能性 ...

March 3, 2022 · 2 min · jiezi

关于c:会计培训网站搭建免费开源net源码

举荐一个会计培训零碎,能够看视频,刷题,考试。试题能够间接excel批量导入,领取接口是支付宝和微信领取,后盾能够本人配置,已测能购买课程。直播性能还没有测试,有须要的能够本人下载测试,总体性能还是很欠缺的,现有的性能曾经能满足应用了,有想做二次开发的也能够下载源代码,本人批改,五星举荐。 1、选课核心:视频,课件,图文,付费课程都可自定义增减,防录屏2、直播版块:屏幕共享,电子白板,文字交换,千人在线晦涩直播3、模仿考场:试题批量导入导出,多种形式模仿练习4、学习记录:可查问追溯,禁止后盾播放,准确统计学习进度,打印学习证实5、考务核心:无纸化在线考试,千人同考,强制交卷,防舞弊,批量导出问题6、营销引流性能:积分,优惠券,学习卡,三级分销7、在线领取:对接支付宝,微信领取,主动开课8、后盾治理:对平台学员的增、删、改、查,反对分组和 excel 批量导入导出 运行环境:服务器操作系统:windows server 2012 64位中文版数据库:Microsoft SQL Server 2008.NET版本:.NET4.6 开发环境:采纳C#;基于.Net 4.6 数据库采纳Sqlserver2008或更高版本开发工具 Microsoft Visual Studio Community 2019 下载:https://pan.baidu.com/s/1koQy... 提取码:xekq源码:https://gitee.com/weishakeji/...或者源码技术十483828432备注“须要源码”开发交换kiu峮:10237400 留神:零碎装置后用记事本关上db.config文件里配置以下主域用域名拜访:例如拜访域名是:www.weisha100.net,主域处填写:weisha100.net,示例如下:add name="weisha100.net" 内网以及应用ip拜访:间接填写ip地址,示例如下:add name="122.114.68.70"留神:不须要带端口号。

March 3, 2022 · 1 min · jiezi

关于c#:C语言预处理命令总结

预处理指令是以#号结尾的代码行,# 号必须是该行除了任何空白字符外的第一个字符。# 后是指令关键字,在关键字和 # 号之间容许存在任意个数的空白字符,整行语句形成了一条预处理指令,该指令将在编译器进行编译之前对源代码做某些转换。 预处理指令: 预处理性能是C语言特有的性能,它是在对源程序正式编译前由预处理程序实现的,程序员在程序中用预处理命令来调用这些性能。 宏定义能够带有参数,宏调用时是以实参代换形参,而不是“值传送”。 为了防止宏代换时产生谬误,宏定义中的字符串应加括号,字符串中呈现的形式参数两边也应加括号。 文件蕴含是预处理的一个重要性能,它可用来把多个源文件连接成一个源文件进行编译,后果将生成一个指标文件。 条件编译容许只编译源程序中满足条件的程序段,使生成的目标程序较短,从而缩小了内存的开销并进步了程序的效率。 应用预处理性能便于程序的批改、浏览、移植和调试,也便于实现模块化程序设计。

March 3, 2022 · 1 min · jiezi

关于c#:对C语言选择结构和循环结构的总结

C语言中罕用的编程构造有三种(其它编程语言也是如此),它们别离是: 程序构造:代码从前往后顺次执行,没有任何“旁敲侧击”,不跳过任何一条语句,所有的语句都会被执行到。 抉择构造:也叫分支构造。代码会被分成多个局部,程序会依据特定条件(某个表达式的运算后果)来判断到底执行哪一部分。 循环构造:程序会从新执行同一段代码,直到条件不再满足,或者遇到强行跳出语句(break 关键字)。 抉择构造 抉择构造(分支构造)波及到的关键字包含 if、else、switch、case、break,还有一个条件运算符? :(这是C语言中惟一的一个三目运算符)。其中,if...else 是最根本的构造,switch...case 和? :都是由 if...else 演变而来,它们都是为了让程序员书写更加不便。 你能够只应用 if,也能够 if...else 配对应用。另外要长于应用 switch...case 和? :,有时候它们看起来更加清新。 if...else 能够嵌套应用,原则上嵌套的档次(深度)没有限度,然而过多的嵌套档次会让代码构造凌乱。 循环构造 C语言中罕用的循环构造有 while 循环和 for 循环,它们都能够用来解决同一个问题,个别能够相互代替。 除了 while 和 for,C语言中还有一个 goto 语句,它也能形成循环构造。不过因为 goto 语句很容易造成代码凌乱,保护和浏览艰难,饱受诟病,不被举荐,而且 goto 循环齐全能够被其余循环取代,所以起初的很多编程语言都勾销了 goto 语句,咱们也不再解说。 对于 while 和 do-while 循环,循环体中应包含使循环趋于完结的语句。 对于 while 和 do-while 循环,循环变量的初始化操作应该在 while 和 do-while 语句之前实现,而 for 循环能够在外部实现循环变量的初始化。 for 循环是最罕用的循环,它的功能强大,个别都能够代替其余循环。 最初还要留神 break 和 continue 关键字用于循环构造时的区别:break 用来跳出所有循环,循环语句不再有执行的机会;continue 用来完结本次循环,间接跳到下一次循环,如果循环条件成立,还会持续循环。 此外,break 关键字还能够用于跳出 switch...case 语句。所谓“跳出”,是指一旦遇到 break,就不再执行 switch 中的任何语句,包含以后分支中的语句和其余分支中的语句;也就是说,整个 switch 执行完结了,接着会执行整个 switch 前面的代码。 ...

March 3, 2022 · 1 min · jiezi

关于c:ifndef作用

最次要的作用:1、避免头文件的反复蕴含和编译;上面是谬误示范: headfile_1.h 1 #include <iostream> 2 class CTest_1 { 3 CTest_1() { 4 //do something,eg:init; 5 } 6 ~CTest_1() { 7 //do something ,eg:free; 8 } 9 void PrintScreen()10 {11 std::cout << "this is Class CTest_1!" << std::endl;12 }13 };headfile_2.h 1 #include "headfile_1.h" 2 class CTest_2 { 3 CTest_2() { 4 //do something,eg:init; 5 } 6 ~CTest_2() { 7 //do something,eg:free; 8 } 9 void PrintScreen()10 {11 std::cout << "this is Class CTest_2!" << std::endl;12 }13 };sourcefile.cpp ...

March 2, 2022 · 1 min · jiezi

关于c:旋转链表

给你一个链表的头节点 head ,旋转链表,将链表每个节点向右挪动 k 个地位。 示例 1: 输出:head = [1,2,3,4,5], k = 2输入:[4,5,1,2,3] 示例 2: 输出:head = [0,1,2], k = 4输入:[2,0,1] 提醒:链表中节点的数目在范畴 [0, 500] 内-100 <= Node.val <= 1000 <= k <= 2 * 109 思路:将k对链表长度(后记为len)取模,如果k与len相等,则k = len,再进行旋转(余数为多少就旋转多少次)。 获取链表长度(帮忙函数): int length(struct ListNode* p) { struct ListNode* q = p; int length = 0; while (q != NULL) { length++; q = q->next; } return length;}单次旋转: void rotate(struct ListNode **p) { struct ListNode* q = *p; struct ListNode *secondToLast = *p; while (q != NULL) { if (q->next != NULL) { secondToLast = q; } q = q->next; } secondToLast->next->next = *p; *p = secondToLast->next; secondToLast->next = NULL;}struct ListNode* rotateRight(struct ListNode* head, int k) { int len = length(head); if (len == 0 || len == 1) return head; int _k; if (k % len == 0) { _k = len; } else { _k = k % len; } for (int i = 0; i < _k; i++) { rotate(&head); } return head;}

March 2, 2022 · 1 min · jiezi

关于c:为什么INLINE-一般要加static

为什么__INLINE 个别要加static起因如下:开发者决定不了一个函数是否被内联,开发者只有建议权,只有编译器具备决定权。上面,咱们来看看一个被static inline润饰的非内联函数: static __inline int Fake_StaticInline_Add(int n1,int n2,int n3,int n4,int n5){ /只是为了多凑几条指令/ n1++;n1++;n1++;n1++;n1++;n1++;n1++;n1++;n1++;n1++;n1++;return (n1+n2+n3+n4+n5);;}这个函数咱们把他放在main.c中,并在main函数这样调用:i = Fake_StaticInline_Add(6,6,6,6,6);。当初咱们来看看他的反汇编代码: MOVS r0,#5 MOV r3,r0 MOV r2,r0 MOV r1,r0 STR r0,[sp,#0] BL Fake_StaticInline_Add MOV r4,r0 NOP惊不惊喜,意不意外? 这个函数竟然是被调用了的,而并没有被内联到调用它的中央。那么,为什么这个函数没变成内联函数呢?我推断是因为我在这个函数中写入了太多指令,编译器判断如果它变成内联函数,会极大占用空间,所以不将它编译成内联函数。但你还记得咱们之前把Inline_Add函数放在哪里吗?放在了一个头文件。试想,如果这个Inline_Add在没有被编译成内联函数的状况下,被include到了多个源文件中,势必会产生函数反复定义的问题。 因而,咱们要再加一个关键字static,能力防止这个问题。

March 2, 2022 · 1 min · jiezi

关于c#:讨论下封装

C# 封装封装 被定义为"把一个或多个我的项目关闭在一个物理的或者逻辑的包中"。在面向对象程序设计方法论中,封装是为了避免对实现细节的拜访。 形象和封装是面向对象程序设计的相干个性。形象容许相干信息可视化,封装则使开发者实现所需级别的形象。 C# 封装依据具体的须要,设置使用者的拜访权限,并通过 拜访修饰符 来实现。 一个 拜访修饰符 定义了一个类成员的范畴和可见性。C# 反对的拜访修饰符如下所示: public:所有对象都能够拜访;private:对象自身在对象外部能够拜访;protected:只有该类对象及其子类对象能够拜访internal:同一个程序集的对象能够拜访;protected internal:拜访限于以后程序集或派生自蕴含类的类型。 Public 拜访修饰符Public 拜访修饰符容许一个类将其成员变量和成员函数裸露给其余的函数和对象。任何私有成员能够被内部的类拜访。 上面的实例阐明了这点: 实例using System; namespace RectangleApplication{ class Rectangle{ //成员变量 public double length; public double width; public double GetArea() { return length * width; } public void Display() { Console.WriteLine("长度: {0}", length); Console.WriteLine("宽度: {0}", width); Console.WriteLine("面积: {0}", GetArea()); }}// Rectangle 完结class ExecuteRectangle{ static void Main(string[] args) { Rectangle r = new Rectangle(); r.length = 4.5; r.width = 3.5; r.Display(); Console.ReadLine(); }}}当下面的代码被编译和执行时,它会产生下列后果: ...

February 26, 2022 · 1 min · jiezi

关于c#:你所不知道的-C-10新特性

咱们很快乐地发表 C# 10 作为 .NET 6 和 Visual Studio 2022 的一部分曾经公布了。在这篇文章中,咱们将介绍 C# 10 的许多新性能,这些性能使您的代码更丑陋、更具表现力和更快 . 浏览 Visual Studio 2022 布告 和 .NET 6 布告 以理解更多信息,包含如何装置。 全局和隐式usingsusing 指令简化了您应用命名空间的形式。 C# 10 包含一个新的全局 using 指令和隐式 usings,以缩小您须要在每个文件顶部指定的 usings 数量。 全局using指令如果关键字 global 呈现在 using 指令之前,则 using 实用于整个我的项目: global using System; 您能够在全局 using 指令中应用 using 的任何性能。 例如,增加动态导入类型并使该类型的成员和嵌套类型在整个我的项目中可用。 如果您在 using 指令中应用别名,该别名也会影响您的整个我的项目: global using static System.Console;global using Env = System.Environment;您能够将全局应用放在任何 .cs 文件中,包含 Program.cs 或专门命名的文件,如 globalusings.cs。 全局usings的范畴是以后编译,个别对应以后我的项目。 无关详细信息,请参阅 全局 using 指令。 ...

February 26, 2022 · 4 min · jiezi

关于c++:认识-LLVM

简介LLVM是一套提供编译器基础设施的开源我的项目,是用 C++ 编写,蕴含一系列模块化的编译器组件和工具链,用来开发编译器前端和后端。它是为了任意一种编程语言而写成的程序,利用虚构技术发明出编译期间、链接期间、执行期间以及“闲置期间”的优化。 LLVM的命名源自于底层虚拟机(Low Level Virtual Machine)的首字母缩写,导致不理解它的人认为它是相似于 JVM(Java Virtual Machine) 的虚拟机,实际上这个我的项目的范畴并不局限于创立一个虚拟机,而是包含 LLVM 中介码(LLVM IR)、LLVM调试工具、LLVM C++ 规范库等一系列编译工具及低端工具技术的汇合。 传统的动态编译器设计是三阶段设计,其次要组件是前端、优化器和后端。 前端负责词法剖析、语法分析、语义剖析、生成中间代码等性能。 优化器负责进行各种转换以尝试进步代码的运行工夫,例如打消冗余计算,并且通常或多或少独立于语言和指标。 后端(也称为代码生成器)负责将代码映射到指标指令集。除了编写正确的代码外,它还负责生成利用所反对架构的不寻常个性的良好代码。编译器后端的常见局部包含指令抉择、寄存器调配和指令调度。 该模型同样实用于解释器和 JIT 编译器。JVM 也是该模型的一个实现,它应用 Java 字节码作为前端和优化器之间的接口。 而 LLVM 被设计为反对多种源语言或指标架构,它提供了一套适宜编译器零碎的两头语言,如果编译器在其优化器中应用这个两头语言示意,则能够为任何能够编译到它的语言编写前端,并且能够为任何能够从它编译的指标编写后端。 应用这种设计,移植编译器以反对新的源语言只须要实现新的前端,即能够重用现有的优化器和后端;同样想减少反对新的指标架构也只须要实现新的后端。而如果按传统设计,前端和后端理论是耦合在一起,实现新的源语言或反对新的指标架构将须要从头开始,要反对 N 指标和 M 源语言将须要 N*M 个编译器。 LLVM IRLLVM提供了一套适宜编译器零碎的两头语言(Intermediate Representation,IR),有大量变换和优化都围绕其实现,通过变换和优化后的两头语言,能够转换为指标平台相干的汇编语言代码。 该两头语言与具体的语言、指令集、类型零碎无关,其中每条指令都是动态单赋值模式(SSA), 即每个变量只能被赋值一次。这有助于简化变量之间的依赖剖析。 以下是简略的 LLVM IR 代码: define i32 @add1(i32 %a, i32 %b) {entry: %tmp1 = add i32 %a, %b ret i32 %tmp1}define i32 @add2(i32 %a, i32 %b) {entry: %tmp1 = icmp eq i32 %a, 0 br i1 %tmp1, label %done, label %recurserecurse: %tmp2 = sub i32 %a, 1 %tmp3 = add i32 %b, 1 %tmp4 = call i32 @add2(i32 %tmp2, i32 %tmp3) ret i32 %tmp4done: ret i32 %b}上述代码对应的 C 语言代码为: ...

February 26, 2022 · 1 min · jiezi

关于c++:CSE310-堆排序

CSE310 Project 2: Min-HeapIn your second programming project, you will expand your first project. As in the case ofthe first programming project, it should be implemented in C++, on a Linux platform such asgeneral.asu.edu. Your program will be graded on Gradescope, which uses a Linux platform. Youwill continue to have modular design, provide a Makefile to compile various modules to generatethe executable file named run. Among other things, you need to have ...

February 25, 2022 · 7 min · jiezi

关于c:CSE240-实现链表

CSE240 – Introduction to Programming Language 1 | PageHomework 07CSE 240 Spring 2021 Homework 7:Linked List of Containers (50 points)Due Saturday, March 13, 2021 at 11:59PM, plus a 24-Hour grace periodIntroductionThe aim of this assignment is to make sure that you understand and are familiar with theconcepts covered in the lectures, including linked list, pointer operations, and parameterpassing mechanisms. This two-assignment combination allows you to put all together that youhave learned in C programming language into a large program. By the end of the assignment,you should have understood and exercised● Pointer and pointer to pointer operations accessing structured data● Linked list of structures, with complex manipulations of pointer and structure● Different types of parameter passing mechanisms and return values of different types.● Solving problems in recursionReading: Textbook Chapter 2, Section 2.5.4 on linked list and Section 2.6 on parameter passingand Section 2.10.Preparation: Complete the multiple choice questions in the textbook exercise section. Theanswer keys can be found in the course Web site. These exercises can help you prepare for yourweekly quiz and the exam. You are encouraged to read the other exercise questions and makesure you understand these questions in the textbook exercise section, which can help youbetter understand what materials are expected to understand after the lectures and homeworkon each chapter.You are expected to do the majority of the assignment outside of class meetings. Should youneed assistance, or have questions about the assignment, please contact the instructor or TAduring their office hours.You are encouraged to ask and answer questions on the course discussion board. However, donot share your answers and code in the course discussion board.Homework DescriptionThe following figure shows an instance of the linked list that you will be building and managingin these two homeworks. The node of the main linked list ‘list’ is called libraryList, whichcontains two members: (1) book member is a pointer to the book node, (2) a pointer to nextlibraryList node. The book node contains three members: (1) book title, (2) aisle number, and(3) a pointer to bookType list. The node in the bookType list has two members: (1) book type (2)a pointer to next bookType node.CSE240 – Introduction to Programming Language 2 | PageHomework 07 libraryListHW 7 Programming Assignment (50 points)You are given a partially completed program hw7.c. You should follow the instructions given inthe program to complete the functions so that the program executes properly. You will becompleting a program that creates a list of books. It is a menu driven program where user isgiven following options:a) Add an book’s information (Book title and aisle number) is already implemented. Thenew book is added to the head of the linked list. We do not ask user for bookTypes toadd in this function. So simply NULL is assigned to *bookType member of the ‘book‘node when a new book is added to the list in this function. (Note: *bookType is used infurther functions)b) Display the book list is already implemented. This function prints each book’s title andaisle number. It does not print bookType of the book.These functions need to be implemented:c) Search a book in the list by book title. It prints if the book exists on the list or not. Thisfunction should return the ‘book‘ node if that book is found in the list, else return NULL.It is used as a helper function in executeAction() to check if the book exists in the list.The next part focuses on using ‘bookType’ linked list. In this part, the user should be able to usethe following menu options:a) Add a bookType to an book’s profile. This function assumes that the book is added inthe list and assigns book type using the *bookType member of ‘book’ node. You mayadd the new bookType to the head or tail of the ‘bookType’ linked list. (Sample solutionadds the bookType to the tail)list book*next*book*next*book*nextBook titleaisle*bookTypeBook titleaisle*bookTypeBook titleaisle*bookTypetype*nexttype*nexttype*nextnullnullnul null lbookbookTypeCSE240 – Introduction to Programming Language 3 | PageHomework 07b) This function prompts the user to input a book type. Then it displays the list of booksthat have the entered book type only. Lastly, it should display the number of books thatmet this requirement. This function should display both book’s title and aisle number.See expected output below.c) Removes the book from the list. This function removes the book’s title, aisle numberand bookType list of the book when removing the book from the list.Expected outputs:addBook (already implemented)CSE240 – Introduction to Programming Language 4 | PageHomework 07displayLibraryList (already implemenetd)(New books are added to the head of ‘list’. So newer books appear first. Not necessary to print‘end of list’ message.)searchBook (5 points)CSE240 – Introduction to Programming Language 5 | PageHomework 07addBookType (15 points)displayBookTypeList (15 points)( Sapiens recently added book type as ‘Nonfiction’ which was added to tail of her *bookTypelist. So, it’s name appears when ‘l’ option is used ).CSE240 – Introduction to Programming Language 6 | PageHomework 07removeBook (15 points)(After removing a book, you should use the display option to verify it functioned correctly)What to Submit?You are required to submit your solution in a compressed format (.zip). Make sure yourcompressed file is label correctly - lastname_firstname7.zip. (All lowercase, do not putanything else in the name like "hw7".)The compressed file MUST contain the following:hw7.c (completed code)No other files should be in the compressed folder.If multiple submissions are made, the most recent submission will be graded. even if theassignment is submitted late.Submission preparation notice: The assignment may consist of multiple files. You must copythese files into a single folder for canvas submission. To make sure that you have all the filesincluded in the zip file and they work after unzip operation, you must test them beforesubmission. You must also download your own submission from the canvas. Unzip the file on adifferent machine and test your assignment and see if you can open and test the files in adifferent location, because the TA will test your application on a different machine. If yousubmitted an empty project folder, an incomplete project folder, or a wrong folder, you cannotresubmit after the submission linked is closed! We grade only what you submitted in the canvas. CSE240 – Introduction to Programming Language 7 | PageHomework 07We cannot grade the assignment on your computer or any other storage, even if the modificationdate indicated that the files were created before the submission due dates. The canvas submissionmay take a few minutes. Be patient and wait for it to complete.Where to Submit?All submissions must be electronically submitted to the respected homework link in the courseweb page where you downloaded the assignment.Late submission deduction policy● No penalty for late submissions that are received within 24 hours after the deadline;● 10% grade deduction for every day it is late after the grace period;● No late submission after Tuesday at 11:59PM.Grading RubricsEach sub-question (programming tasks) has been assigned certain points. We will grade yourprograms following these steps:(1) Compile the code. If it does not compile, 50% of the points given for the code undercompilation will be deducted. Then, we will read the code and give points between 50%and 0, as shown in right part of the rubric table.(2) If the code passes the compilation, we will execute and test the code using test cases. Wewill assign points based on the left part of the rubric table.(3) In both cases (passing compilation and failed compilation), we will read your program andgive points based on the points allocated to each sub-question, the readability of your code(organization of the code and comments), logic, inclusion of the required functions, andcorrectness of the implementations of each function.(4) Please notice that we will not debug your program to figure out how big or how small theerror is. You may lose 50% of your points for a small error such missing a comma or aspace!(5) We will apply the following rubrics to each sub-question listed in the assignment. Assumethat points assigned to a sub-question is pts:Major Code passed compilation Code failed compilationPlease read the FAQ file in the Course Information folder:Q: For some reason, my assignment submission did not go through, but I thought it wentthrough. I can show you on my local disk or in my Dropbox that I completed the assignmentbefore the due date. Can my assignment be graded?A: You should always download your own submission from the blackboard after submission andtest if the submission contains all the required files. We will grade the assignment submitted toCanvas only. We cannot grade the assignment sent from email or stored in any other places,regardless its last-modified-time. If you submitted your assignment into the blackboard, it cannotbe downloaded from the instructor side, but it can download from your side, we can downloadfrom your blackboard and grade the assignment. Please meet the instructor or TA in this case. ...

February 24, 2022 · 7 min · jiezi

关于c++:C并发编程如何调用类内部函数

C11之后,C++引入了多线程规范库thread,这里间接说如何在一个类的成员函数中应用多线程调用起他成员函数的问题。间接上答案。 #include <iostream>#include <thread>using namespace std;class ThreadInClass { public: void threadFun() { cout << "I am a method of ThreadInClass from thread : ." << this_thread::get_id() << endl; } void invokeThreadFun() { thread call(&ThreadInClass::threadFun, ref(*this)); call.join(); }};int main() { ThreadInClass threadClass; threadClass.invokeThreadFun(); return 0;}以上代码中定义了一个ThreadInClass的类,其有两个函数,一个是用来在新的线程中执行的threadFun,一个是在主线程调用的invokeThreadFun,应用是只须要把this指针转换为援用传递给thread的构造函数即可。

February 24, 2022 · 1 min · jiezi

关于c:Permutation-Sequence

The set [1, 2, 3, ..., n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, we get the following sequence for n = 3: "123""132""213""231""312""321" Given n and k, return the kth permutation sequence. 思路:通过给定的n和k,一直的递加n,获取每一次的数组的索引值及k的新值,直到n为0,终止循环将获取的每一次的索引值,从数组(数据每一次取值后,都须要删除该值)内取出值即可。 int* copyIntList(int* list, int length) { int* result = (int*)malloc(length * sizeof(int)); for (int i = 0; i < length; i++) { result[i] = list[i]; } return result;}int getIndex(int n, int k) { return (double)ceil((double)k / getFabric(n - 1)) - 1;}int getFabric(int n) { if (n == 0) return 1; int total = 1; for (int i = 1; i <= n; i++) { total *= i; } return total;}void deleteElementByIndex(int* list, int length, int position) { for (int i = position; i < length; i++) { list[i - 1] = list[i]; }}char* getPermutationSequenceByIndex(int* list, int n, int k) { int _n = n, _k = k; int* _list = copyIntList(list, n); char* result = (char*)malloc((n + 1) * sizeof(char)); result[n] = '\0'; int curResultIndex = 0; while (_n > 0) { int curIndex = (int)getIndex(_n, _k); //dosomething 1.get index from list , then remove the index val of list; result[curResultIndex] = '0' + _list[curIndex]; curResultIndex++; deleteElementByIndex(_list, _n, curIndex + 1); int nextLen = getFabric(_n - 1); int nextK = _k % nextLen == 0 ? nextLen : _k % nextLen; _k = _k <= nextLen ? _k : nextK; _n--; } free(_list); return result;}char* getPermutation(int n, int k) { //生成int动静数组 int* p = (int*)malloc(n * sizeof(int)); for (int i = 0; i < n; i++) { p[i] = i + 1; } char* result = getPermutationSequenceByIndex(p, n, k); free(p); return result;}

February 24, 2022 · 2 min · jiezi

关于c:COMP282-重点解析

University of LiverpoolDepartment of Computer ScienceCOMP282 – Advanced Object-Oriented C LanguagesCoursework 1 – C++Deadline: Tuesday 13th April at 17:00Weighting: 50%Make sure your student ID is clearly shown in a comment at the top of your source code. Compress yourVisual Studio project into a single zip file and submit it via SAM. Penalties for late work will be applied inaccordance with the Code of Practice on Assessment.Project OverviewYou will create a small interactive program toinput details about people, manipulate them, anddisplay them. The project consists of severaltasks, which you should tackle in order. Each taskbuilds on the previous one. Do as much as youcan and then package your project forsubmission. Begin by downloading the VisualStudio project template for this assessment.Read through this entire document before youstart coding, so you’re aware of all tasks and theoverall structure of the program. Your solutionshould demonstrate your knowledge of C++.Important: Each task requires you to add extracode. You shouldn’t need to remove any code.Keep the code from previous tasks in yourprogram so we can see it and mark it.Important: Each part requires you to change thecode in the main() function, potentially losing theprevious version. Therefore we have providedfunctions called main_part1(), main_part2() andmain_part3(). Place your code for each partinside the relevant function. You can uncommentthe relevant lines in the real main() function torun and test each part.Part 1 (Worth 15%)Task 1 – Person Class Definition (5%)Create a Person class that stores a name and age. The name should be stored as a string, and the age as aninteger. Declare and define a constructor that takes appropriate parameters and stores them in the object.Also declare and define a default constructor that sets the name to an empty string and the age to zero.Task 2 – Person I/O (5%)Implement the << and >> operators so you can output and input a Person object with the following stringformat.Jasmine 18In other words, the name of the person is output followed by the age. When the user types a similar stringas input, the first token (up to the space) should be stored as the name, and the second (after the space) asthe age. For this task you do not need to do any input validation or error handling. Assume the user willalways type the correct format.Task 3 – Comparison Operators (5%)Implement comparison operators (<, >, and ==) for the Person class. These should work numerically, basedon the ages of the people involved.Add relevant test code to the main_part1() function. Make sure it’s sufficient to test all the implementedaspects of the Person class from all tasks so far.Part 2 (Worth 45%)Task 4 – Adding & Listing People (Fixed Storage) (20%)Implement this and subsequent tasks in the main_part2() function. Create a loop to present menu itemsand input user choices. At this stage the menu will only have three options. ...

February 24, 2022 · 6 min · jiezi