C++
喜欢唱跳有错吗
这个作者很懒,什么都没留下…
展开
-
【C++】员工排序,vector、multimap
#include<iostream>using namespace std;#include"list"#include<algorithm>#include"vector"#include"string.h"#include"map"#include"ctime"#define CEHUA 0 #define MEISHU 1 #define YANFA 2class Worker {public: string m_name; int m_salar原创 2022-05-31 15:46:17 · 208 阅读 · 0 评论 -
[STL]选手得分
#include<iostream>using namespace std;#include"vector"#include"deque"#include"string.h"#include<algorithm>#include"ctime"class Person {public: Person(string name, int score) { this->m_name = name; this->m_score = score; }pu原创 2022-05-26 22:30:54 · 141 阅读 · 0 评论 -
【C++】模板,数组排序
#include<iostream>using namespace std;template<typename T>void myswap(T& a, T& b) { T temp = a; a = b; b = temp;}template<class T>void mysort(T a[],int len) { for (int i = 0; i < len; i++) { int max = i; for (int原创 2022-05-05 20:56:34 · 199 阅读 · 0 评论 -
【C++】关系符号运算重载
#include<iostream>using namespace std;#include <string.h>class person {public: person(string name, int age) { m_name = name; m_age = age; } //重载关系运算符 bool operator==(person& p) { if (this->m_name == p.m_name && t原创 2022-03-22 19:21:04 · 333 阅读 · 0 评论 -
【C++】赋值运算符重载(堆区开辟内存,深拷贝)
#include<iostream>using namespace std;#include <string.h>class person {public: person(int age) { m_age=new int(age); } ~person() { if (m_age != NULL) { delete m_age; m_age = NULL; } } //重载赋值运算符 person& operator=(pers原创 2022-03-22 19:06:26 · 756 阅读 · 0 评论 -
【C++】递增运算符重载
在这里插入#include<iostream>using namespace std;#include <string.h>class Integer { friend ostream& operator<<(ostream& cout, Integer inter);public: Integer() { m_Num = 0; } //重载前置++运算符 Integer& operator++() { m_Num++;原创 2022-03-22 18:26:24 · 692 阅读 · 0 评论 -
【C++】类和对象,加号运算符重载
#include<iostream>using namespace std;#include <string.h>class Person {public: //Person operator+(Person& p) {//通过成员函数实现 + 号运算符重载 // Person temp; // temp.m_A = this->m_A + p.m_A; // temp.m_B = this->m_B + p.m_B; // return tem原创 2022-03-22 15:46:49 · 1065 阅读 · 0 评论 -
【C++】设计类来判断点和圆的位置关系
头文件circle.h#pragma once#include <iostream>using namespace std;#include "point.h"class circle {//圆类//行为:设置半径,获取半径,设置圆心,获取圆心public:void setR(int r);int getR(); void setcenter(point center);point getcenter();private:int m_r;point m_center.原创 2022-01-08 17:34:36 · 636 阅读 · 0 评论 -
【C++】结构体定义中进行冒泡排序
#include <iostream>using namespace std;#include <string.h>struct hero { string name; int age;};void bubblesort(struct hero s[], int len) {//冒泡升序排列 for (int i = 0; i < len-1; i++) { for (int j = 0; j < len - 1 - i; j++) { if原创 2022-01-05 11:26:57 · 415 阅读 · 0 评论 -
【C++】指针进行数组冒泡排序
#include <iostream>using namespace std;#include <string.h>void bubbleSort(int* a, int len) { for (int i = 0; i < len - 1; i++) { for (int j = 0; j < len - 1 - i; j++) { if (a[j] > a[j + 1]) { int temp = a[j + 1]; a[j原创 2022-01-04 23:38:29 · 353 阅读 · 0 评论 -
【C++】二维数组求每一行之和
#include <iostream>using namespace std;int main() { int a[3][3] = { {100,99,98}, {100,97,98}, {100,96,98}, }; cout << "二维数组" << endl; for (int i = 0; i <3; i++) {//外层控制行数 for (int j = 0; j < 3; j++) {//内层控制列数 cout原创 2022-01-04 15:59:21 · 2442 阅读 · 1 评论 -
【C++】冒泡排序
#include <iostream>using namespace std;int main() { int a[] = { 1,2,8,9,5,4 }; cout << "排序前数组" << endl; for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++) { cout << a[i] << endl; } //比较相邻的两个元素,如果第一个比第二个大,交换两个元素,.原创 2022-01-04 15:42:01 · 330 阅读 · 0 评论 -
【C++】一维数组数据逆置
#include <iostream>using namespace std;int main() { int a[] = { 1 ,2, 3, 5, 4 }; cout << "原始数据" << endl; for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++) { cout << a[i] << endl; } int start = 0;//第一位数下角标 int e原创 2022-01-04 15:13:24 · 257 阅读 · 0 评论 -
【C++】通过全局函数、成员函数判断立方体是否相等,并计算体积、面积
#include<iostream>using namespace std;class cu{ //创建立方体类public: //行为 //设置获取长宽高 void setm_L(int L) {//设置长 m_L = L; } int getm_L() {//获取长 return m_L; } void setm_W(int W) {//设置宽 m_W = W; } int getm_W() {//获取宽 return m_W; }.原创 2021-11-01 16:20:47 · 368 阅读 · 0 评论 -
【C++】通过类显示学号和姓名
#include<iostream>using namespace std;#include<string>class student //设计一个类{public://访问权限 int m_number;//属性 string name; //行为 //展示学号和姓名 void showstudent(){ cout << "姓名" << name << endl; cout << "学号" &l原创 2021-11-01 11:05:52 · 2715 阅读 · 0 评论 -
【C++】通过类来计算圆的周长
#include<iostream>using namespace std;const double PI = 3.14;class circle //设计一个类{public://访问权限 int m_r;//半径为属性 //行为 //获取圆周长 double zhouchang() { return 2 * PI * m_r; }};int main() { //设计一个圆类,求圆周长 circle c1;//通过圆类创建具体的圆(对象) c1.原创 2021-11-01 10:34:48 · 477 阅读 · 0 评论 -
【C++】通信录管理系统
“1.添加联系人”“2.显示联系人”“3.删除联系人”“4.查找联系人”“5.修改联系人”“6.清空联系人”“7.退出通信录”#include<iostream>#include<string>#define Max 1000using namespace std;//联系人结构体struct Person{ //姓名 string H_Name; //性别 int H_Sex;//采用整形为防止输入出男性女性外的词 //年龄 in原创 2021-10-29 11:03:38 · 79 阅读 · 0 评论 -
【C++】函数的分文件编写举例
#include<iostream>using namespace std;#include"swap.h"int main() { int a = 2; int b = 3; swap(a, b); system("pause"); return 0;}//1.创建.h头文件//2.创建.cpp源文件//3.头文件中写函数声明//4.源文件写函数定义#include"swap.h"void swap(int a, int b) {//函数的定义 int .原创 2021-10-28 15:46:01 · 101 阅读 · 0 评论 -
【C++】 switch语句实际举例
#include<iostream>using namespace std;int main() { //switch语句 //电影打分 cout << "请打分" << endl; int score = 0; cin >> score; cout << "打的分数为" << score << endl; switch (score) { case 10: cout << "您原创 2021-10-28 15:10:28 · 1259 阅读 · 0 评论