自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(21)
  • 收藏
  • 关注

原创 20191230 C++组合、聚合的用法

1、需求:构建一个计算机类,一台计算机,由CPU芯片,硬盘,内存等组成。CPU芯片也使用类来表示。-----根据分析。CPU是计算机的一部分,属于组合用法。2、需求给计算机配一台音响。–根据分析,音响和计算机是聚合关系。//cpu.h#pragma onceclass cpu{public: cpu(const char* brand="intel",const char*...

2019-12-30 10:11:31 166

原创 20191228 C++面向对象的作业

需求:创建一个类, 用来表示“玩具”文具, 有以下数据:名称,价格,产地。在使用中,需要获取它的名称, 价格, 产地。注意:根据自己当前的优惠情况,有一个对外的价格。定义的toy.h类的头文件//toy.h#pragma once#include<Windows.h>#include<iostream>#include<string>u...

2019-12-28 10:40:34 201

原创 20191225C++对象之构造函数,包括带参数的构造函数、拷贝函数、赋值构造函数

#include <Windows.h>#include<iostream>#include<string>#define ADDR_LEN 128using namespace std;class Human { public: Human();//默认的构造函数 Human(string name, int salary, int ag...

2019-12-25 18:37:49 282

原创 20191223同时检测多个按键和按键平滑处理

getch() 函数,用于返回用户输入的字符。当连续按键时,该函数返回第一个字符和第二个字符之间,默认有 0.5 秒的延时,并且之后的连续字符,默认是每秒钟 15 次输入。这两个数值可以在控制面板中设置。如果需要平滑的按键输入,或者同时按下多个按键,就不能用 getch() 了,需要使用另一个 Windows API 函数:GetAsyncKeyState()。该函数原型如下:SHORT Ge...

2019-12-23 16:59:26 987

原创 20191216连接两个字符串

/*编写一个程序,连接两个字符串字面常量,将结果保存在一个动态分配的 char 数组中。重写这个程序,连接两个标准 string 对象。*/#include<Windows.h>#include<iostream>#include<stdio.h>#include <string>#define N 1024using namesp...

2019-12-16 17:37:04 219

原创 20191216从标准输入流中输入三个字符串,每输入一段字符串动态分配内存,实时存储在动态内存中

/*编写一个程序,使用 cin 从标准输入输入 3 段文字,保存到一段动态分配的 内存中, 每一段文字输入后,必须要即时保存到动态内存中。*/#include <Windows.h>#include<iostream>#include<string>#include<stdio.h>using namespace std;int m...

2019-12-16 17:06:17 384

原创 20191216动态分配数组,而且用一维数组来表示二维数组

/*首先,根据输入的二维数组的行数和列数,动态地为该数 组分配存储空间;其次,向二维数组中 输入数据;最后输出该数组中的所有元 素。请完善下面的程序。*/#include<iostream>#include <stdlib.h>using namespace std; int main(void){ int *p; int row, col...

2019-12-16 12:46:59 256

原创 20191214将输入的字符串进行逆转输出

/*实现含有中文字符串的逆转,如“我是小萌新”转换成“新萌小是我”**首先要搞明白一件事,就是一个中文字占两个字节*/#include<Windows.h>#include<iostream>using namespace std;int main() { char input[256]; char* p = input; gets_s(input,...

2019-12-14 11:50:52 179

原创 20191213 指针的引用02

使用指针的引用,将函数内部的数据带到函数外部来,good idea!#include <Windows.h>#include <iostream>using namespace std;int swap(int* a, int* b) { int temp = *a; *a = *b; *b = temp; return 0;}void boy_h...

2019-12-13 21:01:49 55

原创 20191213引用

#include<Windows.h>#include <iostream>using namespace std;//引用作为函数的形参时,不需要进行初始化int swap(int& x, int& y) { int temp = x; x = y; y = temp; return 0;}int main() { int a = 1...

2019-12-13 20:42:27 61

原创 20191213 函数指针的使用方法02

#include<Windows.h>#include<iostream>using namespace std;int compare_int( void* a, void* b) { int* a1 = (int*)a; int* b1 = (int*)b; //printf_s("a的地址:0x%p,b的地址:0x%p\n",a, b); return...

2019-12-13 20:24:06 161

原创 20191213 函数指针的使用01

使用函数指针对数组进行排序,好用qsort#include<Windows.h>#include<iostream>using namespace std;int compare_int( void* a, void* b) { int* a1 = (int*)a; int* b1 = (int*)b; //printf_s("a的地址:0x%p,b的地址:...

2019-12-13 17:46:49 130

原创 20191213 函数指针 的定义,初始化,调用

函数指针进行初始化时,把整个函数copy过来,然后将其函数名用 (*fp)来代替,同时去掉形参,就可以了!#include<Windows.h>#include<iostream>using namespace std;int compare_int( void* a, void* b) { int* a1 = (int*)a; int* b1 = (int...

2019-12-13 17:31:00 217

原创 20191212 数组指针的使用方法

#include<Windows.h>#include<iostream>using namespace std;//采用数组指针的方式找出二维数组中的最小值int main() { int A[4][3] = { {173, 158, 166}, {168, 155, 171}, {163, 164, 165}, {163, 164, 1...

2019-12-12 21:02:35 83

原创 20191211求取二维数组中的最大值和次大值

1、直接用数值列举法/*要求:从女兵方针中挑出最高个的和次高个的,并打印出来*/#include<Windows.h>#include<iostream>using namespace std;int main() { int girls[][4] = { {179,171,165,156}, {162,157,168,166}, {158,1...

2019-12-11 21:46:40 440

原创 20191210 使用二级指针实现将函数内部的数据带出来

/*以下是错误的用法,打印出来会报错,原因查明是引用了空指针,传递给函数以后,实际他本身没有任何变化void boy_home(int* meipo) { static int boy = 19; meipo = &boy;}int main() { int x = 10, y = 100; swap(&x, &y); printf_s("x=%d,y...

2019-12-10 22:38:36 129

原创 20191210 使用指针实现数据的交换

使用函数,配合着指针实现数据的交换,萌萌的!#include <Windows.h>#include <iostream>using namespace std;int swap(int* a, int* b) { int temp = *a; *a = *b; *b = temp; return 0;}int main() { int x = 1...

2019-12-10 22:05:08 215

原创 20191208 指针的妙用,让你掉下巴的对比!

前面写程序的时候出了点问题,经过Martin老师的远程调试,发现错误所在。因为在创建指针的时候没有初始化,将其指向具体的内存。// 指针的妙用.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。#include <Windows.h>#include <iostream>#include<stdio.h>#include<...

2019-12-08 21:49:00 55

原创 20191208 C++实现杨辉三角

/*11 1 1 2 1 1 3 3 1 1 4 6 4 1---->杨辉三角 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 在表格上初步打印出杨辉三角,更容易观察出规律,见Martin老师的教程*/#include<Windows.h>#include<iostream...

2019-12-08 16:13:48 173

原创 20191206二维数组和三维数组的初始化,简单即是最有效的。加深对数组的理解!

不多BB,直接上代码`/* 二维数组和三维数组的初始化操作*/#include <Windows.h>#include <iostream>#include <stdio.h>using namespace std;int main(){ int a[3][4] = { {1}, {4,5,6}, {7,8,9} }; ...

2019-12-06 17:54:43 102

原创 20191204调用函数申请的栈空间注意事项

要避免栈空间溢出。当调用一个函数时,就会在栈空间,为这个函数,分配一块内存区域,这块内存区域,专门给这个函数使用。这块内存区域,就叫做“栈帧”。每调用一次函数,就申请一次栈幀。循环调用时,注意是否会出现栈空间爆掉的情况。#include<Windows.h>#include<iostream>#include<stdio.h>using nam...

2019-12-04 17:08:20 186

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除