- 博客(50)
- 资源 (8)
- 收藏
- 关注
原创 sqlite3+FILE实现停车场
car.h#ifndef _CAR_H_#define _CAR_H_#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sqlite3.h>#include <errno.h>#define MAX_COUNT 3 //宏定义停车场车位void welcome(); //欢迎界面void m
2022-03-04 14:22:27
703
原创 LinuxC SQLite3数据库实现通讯录
tongxunlu.h#ifndef _TONGXUNLU_H_#define _TONGXUNLU_H_#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sqlite3.h>void welcome(); //欢迎界面void menu(); //菜单界面int create_table(sqlite3
2022-03-02 10:32:00
383
原创 带文件存储操作的双向带头结点的单链表通讯录
tongxunlu.h:#ifndef _TONGXUNLU_H_#define _TONGXUNLU_H_#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <errno.h>enum ret_vlu{MALLOC_OK, MALLOC_NO, CREATE_OK, CREATE_NO, EMPTY_OK, EM
2022-02-26 20:02:17
185
原创 【通讯录】(带表头的双向不循环链表实现(只是为了删除时偷懒所以用了双向)
源代码:makefile文件OBJS=main.o tongxunlu.otxl:$(OBJS) gcc $(OBJS) -o txltongxunlu.o:$< gcc -c tongxunlu.cmain.o:main.c gcc -c main.c.PHONY:cleanclean: rm *.o txl头文件tongxunlu.h#ifndef _TONGXUNLU_H_#define _TONGXUNLU_H_#include <stdio.h>
2022-02-22 11:40:58
613
原创 通讯录(结构体指针数组存储数据)
头文件:tongxunlu.h#ifndef _TONGXUNLU_H_#define _TONGXUNLU_H_#include <stdio.h>#include <stdlib.h>#include <unistd.h>#define MAX 1024typedef struct ContactPerson{ int id; char name[32]; int age; char tel[12];}Person;void Wel.
2022-01-29 13:50:06
1239
原创 输入两个字符串,判断一个字符串是否为另一个的子串(有BUG,切勿采用)
源程序:#include <stdio.h>#include <string.h>int main(){ char s1[32], s2[32]; printf("Please in put s1[32]:\n"); scanf("%s", s1); printf("Please in put s2[32]:\n"); scanf("%s", s2); char *p1 = s
2022-01-20 21:05:21
988
原创 输入一个字符串,输出字符串中有多少个空格
源程序:#include <stdio.h>int main(){ int i, count = 0; char arr[32]; printf("Please input s[32]:\n"); scanf("%[^\n]", arr); char *p = arr; while (*p != '\0') { if ( *p == 32) { count++; } p++; } printf("space = %d\n", count);
2022-01-20 20:28:19
901
原创 通过指针实现strcat功能
源程序:#include <stdio.h>int main(){ char s1[32] = "abcdefg"; char s2[32] = "Hello"; char *p1, *p2; p1 = s1; p2 = s2; while ( *p1 != '\0') { p1++; } while ( *p2 != '\0') { *p1 = *p2; p1++; p2++; } *p1 = *p2; printf("%s\n", s1
2022-01-20 19:52:43
611
原创 输入一个日期,输出当前日期是这一年的第几天
2021年1月10日是2021年的第10天2021年2月10日是2021年的第31+10=41天2021年3月10日是2021年的第31+28+10=69天闰年和平年2月份的天数不一样每一月的天数都有区别输入的年月日也得满足实际情况不满足条件,可以使用return -1;结束整个程序源程序:#include <stdio.h>int main(){ int year, month, day; int mark, i; int m_count[12], d_count
2022-01-18 20:49:13
3010
原创 编写程序计算身高
每个做父母的都关心自己孩子成人后的身高,据有关生理卫生知识与数理统计分析表明,影响小孩成人后身高的因素有遗传、饮食习惯与坚持体育锻炼等。小孩成人后身高与其父 母身高和自身性别密切相关。 设faHeight为其父身高,moHeight为其母身高,身高预测公式为: 男性成人时身高 = (faHeight + moHeight) * 0.54(cm) 女性成人时身高 = (faHeight * 0.923 + moHeight) / 2(cm) 此外,如果喜爱体育锻炼,那么可增加身高2%
2022-01-18 20:08:23
2312
原创 两个数运算 :输入两个数,再输入运算符(加减乘除),实现两个数字之间的运算
源代码:switch…case 的运用#include <stdio.h>int main(){ float a, b; char c; printf("Please input two numbers(a and b):\n"); scanf("%f %f", &a, &b); printf("Please input + or - or * or /:\n"); scanf(" %c", &c); switch(c) { case '+'
2022-01-18 19:30:13
3209
1
原创 题目:输入一个整数a,再输入两个整数p1,p2(p1,p2<32),将该整数的二进制表示方法中从右端开始的p1到p2位取反后输出
源程序:#include <stdio.h> int main(){ int a, p1, p2, i; int arr[32]; printf("Please input a p1 p2(p1, p2 < 32):\n"); scanf("%d %d %d", &a, &p1, &p2); a = (a >> (p1 - 1)); //先往右移(p1 - 1)位
2022-01-17 16:35:10
227
原创 题目:输入一个整数a,再输入两个整数p1,p2(p1,p2<32),输出该整数的二进制表示方法中从右端开始的p1到p2位.
源程序:#include <stdio.h> int main(){ int a, p1, p2, i; int arr[32]; printf("Please input a p1 p2(p1, p2 < 32):\n"); scanf("%d %d %d", &a, &p1, &p2); a = (a >> (p1 - 1)); //先往右移(p1 - 1)位
2022-01-17 16:23:41
138
原创 题目:请编写一个c函数,该函数给出一个字节中被置为1的位的个数
源程序:#include <stdio.h> void fun (int num){ int i; int count = 0; for(i = 0; i < 8; i++) { if(((num >> i)& 1) == 1) { count++; }
2022-01-17 15:39:15
170
原创 题目: 一个数如果恰好等于它的因子之和,这个数被成为”完数”,例如:6=1+2+3.请编程找出1000以内的完数
源程序:#include <stdio.h> int main(){ int num, i; //num表示要判断的数,i表示因子 int sum = 0; //sum表示因子之和 for (num = 2; num <= 1000; num++) { for (i = 1; i <= num / 2; i++) {
2022-01-17 15:18:34
320
原创 4. 题目:求100以内的素数,全部打印出来
源程序#include <stdio.h> int main(){ int i, j; for (i = 2; i <= 100; i++) { for (j = 2; j < i; j++) { if (i % j == 0) {
2022-01-17 14:55:09
201
原创 3. 题目:输入5个数(含负数、小数)将它们按由小到大的顺序排列起来 提示:需要排数的数字通过参数传递进来
源程序:#include <stdio.h>int main(){ int i, j; float arr[5]; printf("please input 5 number:\n"); for (i = 0; i < 5; i++) { scanf("%f", &arr[i]); } for (i = 0; i < 5; i++) //冒泡排序 { for (j = i + 1; j < 5; j++) {
2022-01-17 14:53:21
156
原创 题目:有n个人围成一圈,顺序排号,从第一个开始报数(从1到3报数),凡报到3的人退出圈子,问最后最后留下的是原来第几号的那位.
源程序:#include <stdio.h> int main(){ int n, i; int mark = 0; printf("请输入一个正整数n:\n"); scanf("%d", &n); int sum = n; //用来计总数 int arr[n]; for (i = 0; i < n; i++) {
2022-01-17 14:07:37
512
3
原创 1. 题目:通过编程实现,统计1~n有多少个9 提示:n通过参数传入
源程序:#include <stdio.h>int main(){ int n, i; int count = 0; //计数 int tmp; printf("请输入一个正整数n:\n"); scanf("%d", &n); for (i = 1; i <= n; i++) { tmp = i; while (tmp != 0) { if ((tmp % 10) == 9) //计算个位是否为9
2022-01-17 10:27:22
139
原创 二叉树深度优先遍历
源代码:#include <iostream>#include <cstdlib>#include <stack>using namespace std;typedef struct BiTNode{ char root; struct BiTNode * lchild, * rchild;}BiTNode, * BiTree;//创建二叉树void CreateBtree(BiTree * T){ char ch;
2021-02-03 17:11:24
114
原创 二叉树广度优先遍历算法
源代码:#include <iostream>#include <cstdlib>#include <queue>using namespace std;typedef struct Node { char root; struct Node *lchild; struct Node *rchild;} *Tree;//广度优先遍历void breadthFirstSearch(Tree root){ if (!roo
2021-02-03 17:00:02
358
原创 二叉树的建立及三种遍历
源代码:#include <iostream>#include <cstdlib>using namespace std;typedef struct BiTNode{ char root; struct BiTNode * lchild, * rchild;}BiTNode, * BiTree;//创建二叉树void CreateBtree(BiTree * T){ char ch; cout << "请输入字符:
2021-02-03 16:55:28
85
原创 数组类封装
源代码://test.cpp#include <iostream>#include "MyArray.h" using namespace std; int main(){ // 自己写MyArray.h 头文件和 MyArray.cpp 源文件 实现数组类 Array // 数组类的构造函数有一个 int 型参数 表示数组的大小 Array a1(10); // 数组类有一个 length 方法 用于获取数组的大小 for (in
2021-02-03 16:33:29
155
原创 贪心法解决0_1背包问题
源代码:#include <iostream>#define BACKSIZE 50.0using namespace std;struct node{ float weight; float value; float average_value; int index;};int main(){ int n; cout << "请输入物体的数量:" << endl; cin >> n;
2021-02-03 16:24:50
263
原创 设计一个类 实现包括成员数据以及求两个数的最大公约数和最小公倍数的成员函数。并编写主函数测试
设计一个类 实现包括成员数据以及求两个数的最大公约数和最小公倍数的成员函数。并编写主函数测试源代码:#include <iostream>using namespace std;class max_min{private: int x; int y;public: max_min(int x, int y); ~max_min(); void get();};max_min::max_min(int x, int y){
2021-02-03 16:01:24
760
原创 设计一个类 实现十进制到十六进制的转换。并编写主函数测试
设计一个类 实现十进制到十六进制的转换。并编写主函数测试源代码:#include <iostream>using namespace std;class change{private: int n;public: change(int n); ~change(); void exchange();};change::change(int n){ this->n = n;}change::~change(){}
2021-02-03 15:59:27
352
原创 设计一个类 实现求n!(n的阶乘)。并编写程序输出8
设计一个类 实现求n!(n的阶乘)。并编写程序输出8;源代码:#include <iostream>using namespace std;class jiecheng{private: int n;public: jiecheng(int n); ~jiecheng(); int getjiecheng(); //计算阶乘结果 void showsum(); //打印阶乘结果};jiecheng::jiecheng(int
2021-02-03 15:57:40
1807
原创 利用多态的思想写一个王者荣耀的框架
头文件1:hero.h#ifndef HERO_H_#define HERO_H_#include "skin.h"#include <iostream>using namespace std;class Hero{protected: char * name; Skin * sk;public: ~Hero() { delete sk; } char * get_name() { return name; } Skin * get_skin(
2021-02-02 10:14:50
441
原创 C++的学习日记day8(类型转换、异常、输入输出流、文件)
C语言类型转换隐式类型转换:int myMax(int a,int b){}调用:myMax(1,‘A’);强制类型转换(显式类型转换):int *p = (int *)malloc(…)typename1 a = (typename2)b;C++里面提供一组可以在不同场合使用的强制转换(本质就是类模板)static_cast(exp)1.用于基本的类型转换,不能用于指针间的转换(pc = static_cast<char*>(pi)????比如将Int转为char型(和C语
2021-01-31 09:27:43
159
原创 C++的学习日记day7(模板)
模板生活中 模具外形不变,(球体模具) 铁球,塑料球int myadd(int a,int b)double myadd(double a,double b)char myadd(char a,char b);void swap(int *,int *)值传递 指针传递 引用传递假如一个程序的功能仅仅是针对某种特定的数据类型进行处理,可以将这些特定的数据类型说明为参数,即将该程序说明为模板优点:节省代码量;函数模板用法:template <模板参数表><函数返
2021-01-30 11:59:01
161
1
原创 C++的学习日记day6(多态)
多态:(多种状态)C:switch/case , if条件语句C++: 函数/运算符重载编译时:函数重载运行时:switch/case现象:类型兼容性原则+重写重写:发生在继承关系,父类和子类都有相同的函数原型(成员覆盖)重载:同名不同作用(重载的函数原型不同)相同点:名字相同早期联编(静态链接):(编译时的多态)后期联编(动态链接)(运行时的多态)虚函数:语法: virtual <类型> 成员函数名(<参数列表>)必须是基类中成员函数,且当基类的某
2021-01-28 15:35:20
195
原创 C++学习日记day5(运算符重载)
运算符重载运算符:单目/双目/三目重载:(函数重载) 名称相同,作用不同(“一名多用”)* 乘号/指针& 引用/取地址<<,>> 位移运算符/输出. :: ?: *(指针) sizeofCPoint (3,4)c1 ,c2; c1+c2不能改变优先级,结合性不能改变所需要的操作数不能创建新的运算符单目运算符 ++ – (前置/后置)前置:运算符重载本质是一个成员函数;CPoint c1;c1++;成员函数<返回值
2021-01-25 19:42:57
217
2
原创 C++实现快速排序算法(递归法)
快速排序是对冒泡排序的一种改进,又称为分区交换排序,它是由托尼·霍尔(C.A.Hoare)提出并发展而来的。快速排序采用的是分治策略,它是目前已知的排序速度最快的一种排序方法。由于在冒泡排序中记录的比较和交换总是在相邻的单元间进行的,记录每次交换只能向前或向后移动一个位置,故而比较和移动的总次数较多。而在快速排序中,记录的比较和交换是从两端向中间进行的,关键字较小的记录可能会一次从后面单元交换到前面去,与之类似,关键字较大的记录一次就能从前面单元交换到后面去,记录移动的距离较远,因而减小了总的比较次数和移
2021-01-24 11:36:34
1035
原创 C++实现冒泡排序
冒泡排序又称起泡排序,是一种简单的交换排序方法。其基本思想是:依次比较整个序列中相邻的两个记录的关键字,如果逆序(即前一个记录的关键字大于后一个记录的关键字)就交换这两个记录,直到没有逆序的记录为止。假设有待排序的n个记录存放在数组R[n]中,在使用冒泡排序时,首先将R[1]的关键字与R[2]的关键字进行比较,如果为逆序(即R[1].key>R[2].key),就交换这两个记录,若为顺序,则不交换位置,然后再比较R[2]的关键字和R[3]的关键字,依此类推,直到比较R[n-1]与R[n]的关键字后为
2021-01-24 09:25:58
194
原创 C++实现选择排序算法(个人理解编写)
源代码:#include <iostream>#include <cstdlib> //rand() 和 srand()的头文件#include <ctime> //time的头文件#define MAXSIZE 10 //宏定义数组最大容量using namespace std;void make_sorted(int * array) //随机生成100以内的乱序整数{ //这里把array[0]留着当中转站用 srand((unsigned
2021-01-23 21:59:53
331
1
原创 C++实现插入排序算法(个人理解编写)
源代码:#include <iostream>#include <cstdlib> //rand() 和 srand()的头文件#include <ctime> //time的头文件#define MAXSIZE 10 //宏定义数组最大容量using namespace std;void make_sorted(int * array) //随机生成100以内的乱序整数{ srand((unsigned int)time(NULL));
2021-01-23 21:46:57
167
原创 C++学习日记day4(继承和派生)
通过继承:1.可以在已有的类的基础上添加新的功能;2.可以在已有的类的基础上添加新的变量;3.可以修改类的方法;(不常用)什么时候需要用到继承?1.创建一个新的类的时候,这个类与现有的类相似(只是多出若干成员变量或成员函数时候)2.当你创建多个类的时候,拥有很多相似的成员函数或者成员变量,可以将这几个类中通用的部分提取出来作为一个基类。(节省代码节省代码)继承权限:class Car{};class BMW:<继承权限> Car{};class 派生类名:<继承权限
2021-01-23 17:39:20
107
原创 C++的学习日记3(类和对象)
浅拷贝:(现象)用一个对象给另一个对象做初始化 会调用默认拷贝构造(只是做简单指针赋值)释放空间的时候会造成(“野指针”/“指针悬挂”/)浅拷贝 “让新旧两个对象中的指针指向了同一块存储空间”深拷贝:手动写拷贝构造函数,程序员自己给指针分配存储空间m_name = (char*)malloc(sizeof(char)20);malloc: 返回值(void)free(m_name);#include <iostream>using namespace std;class t
2021-01-21 19:53:57
289
原创 C++的学习日记2(函数重载)
面向过程(思想):以什么正在发生为目标(强调的是算法)缺点:不容易维护,灵活性差,不容易扩展,不能复用;面向对象:以什么正在受影响为目标(建模)耦合度:模块与模块存在的联系(越低越好) 多态可复用,耦合度低(职责分离)封装:把“数据(属性)”和“函数(操作)”合成一个整体内联函数关键字 inline 必须加在函数定义之前,放在函数声明之前无效内联函数不需要像函数调用一样 寻址、压栈、出栈编译器直接将使用相应的函数代码替换函数调用优势 内联函数不需要像函数调用一样 寻址、压栈、出栈节
2021-01-20 14:51:23
98
原创 C语言(带头节点)单链表实现栈(进、出、遍历)
源程序:#include <stdio.h>#include <stdlib.h>typedef struct stack_link{ int data; stack_link *next;}Stack, *HStack;void create_node(HStack *new_node){ *new_node = (HStack)malloc(sizeof(Stack));}void Push(HStack Head, int x)
2021-01-20 11:38:40
509
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人