- 博客(19)
- 收藏
- 关注
原创 运算符重载.cpp[运算符重载][C++,类]
//#define _CRTDEG_MAP_ALLOC //检测动态内存泄漏#include #include <stdlib.h>//检测动态内存泄漏#include “Cow.h”#include “Goat.h”#include “pork.h”/*//检测动态内存泄漏#include <crtdbg.h>//替代new#ifdef _DEBUG...
2020-02-08 11:01:54 350
原创 Goat.cpp[运算符重载][C++,类]
#include “Goat.h”Goat::Goat(int weight){this->weight = weight;}int Goat::getweight()const{return weight;}bool Goat::operator>(Goat& goat){if (weight > goat.weight) { return tru...
2020-02-08 11:00:18 214
原创 Goat.h[运算符重载][C++,类]
#pragma onceclass Goat //羊类{public:Goat(int weight = 0);int getweight()const;//关系运算符重载bool operator>(Goat& goat);bool operator<(Goat& goat);bool operator==(Goat& goat);pri...
2020-02-08 10:59:29 257
原创 Cow.cpp[运算符重载][C++,类]
#include “Cow.h”#include “pork.h”#include “Goat.h”Cow::Cow(int weight){this->weight = weight;}pork Cow::operator+(const Goat& goat){/*加法规则:一斤牛肉:两斤猪肉一斤羊肉:三斤猪肉/int tmp = this->wei...
2020-02-08 10:58:22 230
原创 Cow.h[运算符重载][C++,类]
#pragma once#include #include using namespace std;class pork;class Goat;class Cow //牛类{public:Cow(int weight = 0);//使用运算符重载来实现变态加法//使用operator运算符重载有一个默认参数是对象本身如自己(Cow)pork operator+(const ...
2020-02-08 10:57:07 237
原创 pork.cpp[运算符重载][C++,类]
#include “pork.h”#include int pork::id = 0;pork::pork(int weight){this->weight = weight;}pork::pork(const char* name, int weight, int price){if (!name)name = “空”;this->name = new char[...
2020-02-08 10:55:34 165
原创 pork.h[运算符重载][C++,类]
#pragma once#include #include #include using namespace std;#define WEIGHT_KEY “体重”#define PRICE_KEY “单价”#define ID_KEY “编号”#define NAME_KEY “姓名”typedef enum {id_key,weight_key,price_ke...
2020-02-08 10:54:34 143
原创 友元.cpp [友元][C++,类,面向对象]
#include “Computer.h”#include “ComputerService.h”void upgrade(Computer *computer) {computer->cpu = “i7”;}//全局函数做为友元函数int main(void) {while (0) { //全局函数做为友元函数示例:Computer dn;cout << "cpu:...
2020-02-08 10:51:14 170
原创 ComputerService.cpp [友元][C++,类,面向对象]
#include “ComputerService.h”#include “Computer.h”void ComputerService::upgrade1(Computer* computer){computer->cpu = “i9”;}void ComputerService::clean(Computer* computer){cout << “正在对[...
2020-02-08 10:49:54 114
原创 computerservice.h [友元][C++,类,面向对象]
#pragma onceclass Computer;class ComputerService//计算机服务类{public:void upgrade1(Computer* computer);//类的成员函数作为友元函数void clean(Computer* computer);//友元类,清理void kill(Computer* computer);//友元类,杀毒};...
2020-02-08 10:48:27 125
原创 Computer.h [友元] C++ 类
#pragma once#include #include <stdlib.h>#include using namespace std;//#include “ComputerService.h”//使用类的成员函数作为友元函数,必须包含其头文件class Computer{public:string getcpu() { return cpu; }private...
2020-02-08 10:46:43 139
原创 杨辉三角型,二维数组,C\C++
#include #include <Windows.h>//输出格式化的头文件,cout<<setw()<<a[][];打印空格setw(2++)就打印1++个空格#include using namespace std;#define N 10 //int a[N][N]/*杨辉三角形条件:每行端点与结尾的数为1.每个数等于它上方两数之和。...
2019-11-26 15:16:13 543
原创 递归函数(多重梦境),示例说明
#include #include <Windows.h>using namespace std;/*递归函数:直接或者间接调用函数本身缺点:开销大,效率低*///斐波那契数列,递归函数unsigned long long b(int n) {unsigned long long bb;if (n == 1 || n == 2) {return 1;//结束条件...
2019-11-24 15:49:34 201
原创 函数的栈空间(栈帧),调用一次函数即开一个空间(大小=函数体的空间大小)
#include #include <Windows.h>using namespace std;/*void bug() {//运行时因栈帧空间溢出而崩溃char buff[2000000];//2Mcout << (int)buff[sizeof(buff) - 1] << endl;}*///函数栈帧地址示例/*栈空间该函数的本地...
2019-11-23 17:14:27 1057
原创 数组作为函数参数使用,改变实参
#include #include <Windows.h>using namespace std;//成绩void Bchievementprint(int achievement[],int n) {//形参本质上是指针,占用int4字节for (int i = 0; i < n; i++) {cout << “第” << i + 1 <...
2019-11-23 11:22:23 2893
原创 函数调用及参数传递
#include #include <Windows.h>using namespace std;//函数薪资(现薪资,加薪)void Pay_rise(int current_salary, int multiple_salary) {current_salary += multiple_salary;cout << “加薪中:” << curre...
2019-11-23 10:30:21 133
原创 C++输入输出异常错误的优化,cin.fail(),cin.sync();,缓冲区
#include //输出输入的头文件#include <Windows.h>//windouws控制台命令的头文件using namespace std;void Empty_input_buffer() {//代替cin.sync();,清空输入缓冲区char tmp;while ((tmp = getchar()) != ‘\n’);/*getchar()是c语言中的...
2019-11-12 11:07:46 390
原创 C语言字符串的输入,输出(异常处理)
#include #include <Windows.h>#include <string.h>//使用C语言的strlen();需要用到的头文件using namespace std;int main(void) {char girl_name[16];char girl_home[64];printf("姑娘芳名?\n");/*scanf特点:输入 小芳...
2019-11-12 10:35:28 606
原创 C语言字符串的存储与初始化和异常
#include #include <Windows.h>#include <stdio.h>//C的头文件#include //C++的string字符串的头文件using namespace std;int main(void) {char name[]="rock";//这样c语言编译器会自主添加'\0'结束符//"rook"/*name[0] = '...
2019-11-12 09:40:29 133
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人