![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c/c++
坑货的成长史
个性也是一种生活态度!
展开
-
用函数实现金字塔打印,打印的层数用参数指定。
//用函数实现金字塔打印. 打印的层数由参数指定./** * *** ***** ******* ********* **///打印定制金字塔#include <iostream>#include <windows.h>using namespace std;void pyramid(int n, char custom) ...原创 2020-03-24 12:52:25 · 1316 阅读 · 0 评论 -
制作自己的静态库
#include <iostream>#include <Windows.h>#include "第十四节-制作自己的静态库1.h"using namespace std;int main(void) { cout << add(6,8) << endl; system("pause"); return 0;}//第一步 ...原创 2020-03-24 12:42:08 · 139 阅读 · 0 评论 -
常见错误结
//第11节 项目精讲-常见错误总结//问题1: 在函数体内定义其他函数[错误]int main(void) { int add(int a, int b) { return a+b; } cout << add(1,3); system("pause"); return 0; }//问题2: 函数的返回类型和实际返回值的类型不匹配.[此时发生”强制类型...原创 2020-03-23 18:55:32 · 134 阅读 · 0 评论 -
多重梦境之递归函数
#include <iostream>#include <Windows.h>using namespace std;int Fibonacci(int n) { //斐波那契数列 if(n==1 || n==2) { return 1; } return Fibonacci(n-1)+Fibonacci(n-2);}void dream(int...原创 2020-03-23 18:49:40 · 185 阅读 · 0 评论 -
极速调用之内联函数
#include <iostream>#include <Windows.h>using namespace std;inline int call(int a, int b) { //调用 return a+b;}int main(void) { call(36, 54); cout << call(36, 54) <<...原创 2020-03-23 18:42:52 · 93 阅读 · 0 评论 -
函数的栈空间
#include <iostream>#include <windows.h>using namespace std;void test(void) { //运行时因为栈帧空间溢出,而崩溃 char bug[1200000]; cout << (int)bug[sizeof(bug)-1] << endl;}void ...原创 2020-03-23 18:35:09 · 313 阅读 · 0 评论 -
同名不同命之函数重载
#include <iostream>#include <Windows.h>using namespace std;int add(int a, int b) { cout << "调用版本一" << endl; return a+b;}int add(int a, int b, int c) { cout <<...原创 2020-03-23 18:29:49 · 307 阅读 · 0 评论 -
沉默是金之默认参数
#include <iostream>#include <Windows.h>using namespace std;void scoreprint(int score[], int n) { //12 { //形参本质上是一个指针 只是吧数组的第一个地址传进过来 for(int i=0; i<n; ++i) { cout << "...原创 2020-03-23 18:22:26 · 119 阅读 · 0 评论 -
使用数组作为函数参数
#include <iostream>#include <Windows.h>using namespace std;void scoreprint(int score[], int n) { //12 { //形参本质上是一个指针 只是吧数组的第一个地址传进过来 for(int i=0; i<n; ++i) { cout << "...原创 2020-03-23 18:17:28 · 1929 阅读 · 0 评论 -
函数参数的传递方式
#include <iostream>#include <windows.h>using namespace std;//比如要加薪void addsalary(int salary, int add) { salary = salary+add; cout << "加薪中" << salary << endl...原创 2020-03-23 18:12:35 · 157 阅读 · 0 评论 -
函数的声明和调用
/*1)先确定函数的功能 设计函数时,每个函数,只有一个特定的功能 计算1+2+3+...n2)确定函数的参数 是否需要参数,参数的个数,参数的类型3)确定函数的返回值 是否需要函数的返回值,返回值类型4)确定函数名 函数名,一定要顾名思义5)函数点名的命名方法,和变量相同6)函数实现*/#include <iostream>#include...原创 2020-03-23 18:08:45 · 192 阅读 · 0 评论 -
函数的定义
/*1)先确定函数的功能 设计函数时,每个函数,只有一个特定的功能 计算1+2+3+...n2)确定函数的参数 是否需要参数,参数的个数,参数的类型3)确定函数的返回值 是否需要函数的返回值,返回值类型4)确定函数名 函数名,一定要顾名思义5)函数点名的命名方法,和变量相同6)函数实现*/#include <iostream>#include...原创 2020-03-23 17:51:51 · 374 阅读 · 0 评论 -
为什么使用函数
/**第2节 项目精讲-为什么要使用函数已经有main函数,为什么还要自定义函数?1)“避免重复制造轮子”,提高开发效率strcmp(str1, str2);2)便于维护初学者的创建错误:1)函数很长, 常常超过100行2)不知道怎样定义函数**/...原创 2020-03-23 17:47:43 · 351 阅读 · 0 评论 -
项目优化4-隐藏密码输入-别看了,看懂的都不是一般人
```cpp#include <iostream>#include <windows.h>#include <string>#include "hacker.h"using namespace std;#define WIDTH 60//宽度#define HIEGHT 30//高度//设置终端 界面大小void termi...原创 2020-03-23 17:40:37 · 136 阅读 · 0 评论 -
项目优化3
能看懂的都是大神#include <stdio.h>#include <WinSock2.h>#include <stdlib.h>#include <memory.h>#include <iostream>#include <string.h>#include "hacker.h"#pragma comm...原创 2020-03-23 17:34:09 · 121 阅读 · 0 评论 -
项目优化2-调整终端大小,居中显示
#include #include <windows.h>#include using namespace std;//定义宏#define WIDTH 60 //宽度#define HIEGHT 20 //高度//设置控制台大小void The_console(void) {//设置终端窗口的大小// cols=宽度 lines=高度//mode...原创 2020-02-26 19:58:11 · 410 阅读 · 0 评论 -
项目优化1-封装函数
项目优化11.封装login函数,实现登录2.封装菜单显示代码3.添加主循环,以实现反复操作#include #include <windows.h>#include using namespace std;//初始化void Initialize_the(void) {string name; //名字string password; //密码while (...原创 2020-02-24 19:13:53 · 145 阅读 · 0 评论 -
输入一句话-实现字符串逆转—项目练习13
#include #include <Windows.h>#include using namespace std;int main(void) {char learn[88]; //一句话int i=0;int j=0;cout << "请输入一句话: ";gets_s(learn, sizeof(learn));//循环判断while(lear...原创 2020-02-06 17:46:05 · 167 阅读 · 0 评论 -
输入一句英文字符串-统计单词个数—循环练习12
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200206173215876.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTM5OTE3OA==,size_16,color_...原创 2020-02-06 17:40:01 · 999 阅读 · 0 评论 -
千鸡百钱—循环练习11
#include #include <Windows.h>using namespace std;int main(void) {//公鸡 20只for(int i=1; i<20; ++i) { //母鸡 33只 for(int j=1; j<33; ++j) { int p = 100-i-j; if(p%3==0 && i*5...原创 2020-02-06 17:21:33 · 597 阅读 · 0 评论 -
输入字符串逆转输出—循环练习10
#include #include <Windows.h>#include using namespace std;int main(void) {string str;int j;int i;char age;cout << "请输入一个整数字符串:";cin >> str;i = 0; //初始j = str.length()...原创 2020-02-06 17:11:24 · 183 阅读 · 0 评论 -
输入一个2进制数转换成10进制输出—循环练习9
*#include #include <Windows.h>#include using namespace std;int main(void) {string str; //二进制数据int q = 0; //int p = 1;cout << "请输入一个人二进制数据: ";cin >> str;for(int i=str.le...原创 2020-02-06 17:01:50 · 1221 阅读 · 0 评论 -
10进制转换成2进制输出—循环练习8
/**#include #include <Windows.h>using namespace std;int main(void) {int ret[32]; //收集变换的数据int p; //二进制整数int s; //变换的数据cout << "请输入一个二进整数: ";cin >> p;if(p &...原创 2020-02-06 16:44:19 · 648 阅读 · 1 评论 -
斐波那契数列打印—循环练习7
#include #include <windows.h>using namespace std;int main(void) {int p; //共几位数列int a=1; //数列前一位int b=1; //数列后一位int column; //斐波那契数cout << "请输入几位斐波那契数列:";cin >> p;if(p &...原创 2020-02-06 16:21:54 · 184 阅读 · 0 评论 -
输出水仙花数—循环练习六
#include #include <Windows.h>using namespace std;int main(void) {int a,b,c;for(int i=0; i<=999; ++i) { a = i%10; //取余 个位 b = i/10 %10; //十位、 c = i/100; //百位 if( a*a*a + b*b*b + c*...原创 2020-02-06 16:13:10 · 328 阅读 · 0 评论 -
打印乘法口诀—循环练习5
#include #include <Windows.h>#include //对齐using namespace std;int main(void) {/**int p; //嵌入式循环计算for(int i=1; i<=9; ++i) { for(int j=1; j<=i; ++j) { p = i*j; cout <&l...原创 2019-11-21 02:09:10 · 117 阅读 · 0 评论 -
用星号打印金字塔-循环练习4
#include #include <Windows.h>using namespace std;int main(void) {int lien; //层数cout << "请输入打印层数:";cin >> lien;//嵌入式循环打印 先打印 (空格 *号 换行)// p<=i*2 等同于 p<i*2+1...原创 2019-11-21 02:00:06 · 689 阅读 · 0 评论 -
用星号打印立起来的三角-循环练习3
#include #include <Windows.h>using namespace std;int main(void) {int lien; //行cout << "请输入打印多少行:";cin >> lien; for(int i=0; i<lien; ++i) { for(int j=0; j<lien-i; ++j...原创 2019-11-13 02:44:32 · 159 阅读 · 0 评论 -
星号打印楼梯形状-循环练习2
//用*号打印如下/*******/#include #include <Windows.h>using namespace std;int main(void) {int line; //行cout << "请输入打印多少行:";cin >> line;for(int i=0; i<line; ++i) { for(i...原创 2019-11-13 02:39:17 · 340 阅读 · 0 评论 -
由用户输入行数和每行(*)的个数-循环练习1
//由用户输入 行数和列数 并用*号打印出来#include #include <Windows.h>using namespace std;int main(void) {int line; //行int column; //列cout << "请输入打印多少行:";cin >> line;cout << "请输入打印多少...原创 2019-11-13 02:31:46 · 786 阅读 · 0 评论 -
输入一个英文字符-- 然后进行转换大小写
#include #include #include <Windows.h>using namespace std;int main(void) {char p;char s;cout << “请输入一个大写字母:”;cin >> p;s = p;if (p >= 'a' && p <= 'z') { p = ...原创 2019-08-31 02:23:55 · 928 阅读 · 0 评论 -
string字符串的加法
#include #include <Windows.h>#include using namespace std;int main(void) {string q1 = “我”;string q2 = “想”;string q3 = “揍你”;string q4;q4 = q1+q2;cout << "q1+q2=" << q4 <&...原创 2019-08-10 02:31:49 · 3449 阅读 · 0 评论 -
循环的经典应用——暴力破解密码
#include #include <windows.h>#include using namespace std;int main(void) {string password; //密码while (1) { cout << "请输入密码:"; //忘了写字符串的头文件 cin >> password; if (password ==...原创 2019-09-24 21:55:14 · 917 阅读 · 1 评论 -
甜蜜谎言for循环嵌套运用
#include #include <Windows.h>using namespace std;int main(void) {int h; //时间h = 0;//1小时 60分钟 60秒 100毫秒for (int j=1; j<=1; ++j) { for (int j=1; j<=60; ++j) { for (int j=1; ...原创 2019-09-24 21:50:33 · 140 阅读 · 0 评论 -
代码世界中的传送阵goto运用
#include #include <Windows.h>#include using namespace std;int main(void) {string girl; //女孩while (1) { cout << "你是发否喜欢美女?"; cin >> girl; if (girl == "我喜欢女孩哦") { goto hap...原创 2019-09-24 21:42:29 · 198 阅读 · 0 评论 -
逻辑&& || !运算用法
#include #include <Windows.h>#include using namespace std;int main(void) {string west; //西西string jade; //小玉cout << "西西跟我走吧!";cin >> west;cout << "小玉跟我走吧!";cin &g...原创 2019-08-16 03:01:17 · 1789 阅读 · 0 评论 -
连续读入多个单词,然后统计这些单词的总的长度、以及单词个数。分别使用C和C++实现。
#include #include #include <Windows.h>using namespace std;int main(void) {string age;int Long_degrees = 0; //长度int quantity = 0; //数量cout << "输入一句话:";while (1) { if (!(cin &g...原创 2019-08-12 03:09:39 · 509 阅读 · 0 评论 -
C语言字符串的存储初始化
#include #include <stdio.h>#include #include <Windows.h>int main(void) {char name[12]; //名称//你是坑货name[0] = 'n';name[1] = 's';name[2] = 'k';name[3] = 'h';name[4] = 0; printf...原创 2019-08-11 03:20:42 · 657 阅读 · 0 评论 -
字符串比较的“运算符” ==bool类型使用场合:其它数据类型的比较运算
第2节 项目精讲-string字符串的比较复习字符串的比较规则:按顺先从前往后比较同序号的字符按“ASCII”码值比较直到遇到对应字符不等或者字符串结束字符串比较的“运算符”<= (大于或者等于)<= (小于或者等于)!=c++中,字符串的比较, 可以直接使用以上的”比较运算符”比如:str1 == str2字符串比较的“结果”:bool类型逻...原创 2019-08-15 00:46:09 · 1370 阅读 · 0 评论 -
路由器管理系统-权限判断
#include #include <windows.h>#include using namespace std;int main(void) {string name; //账号string psw; //密码cout << "请输入账号:";cin >> name;cout << "请输入密码:";cin >...原创 2019-08-15 00:40:40 · 139 阅读 · 0 评论