![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Cpp
新鲜感~
这个作者很懒,什么都没留下…
展开
-
一元多项式加法
#include<iostream> using namespace std; struct ployn { float coef; //系数 int exp; //指数 ployn* next; }; //创建多项式 /* 创建带头结点的链表(多项式) 且无论按什么顺序输入,或是有相同指数项 最终在多项式中都是升幂顺序! */ void CreatePolyn(ployn*& P, int m) { ployn* pre, * paixv, * q, *原创 2021-04-12 21:59:53 · 160 阅读 · 0 评论 -
STL标准容器 (list)
案例 -评委打分 #include<iostream> using namespace std; #include"string" #include<vector> #include<deque> #include<algorithm> #include<ctime> class Person { public: Person(string name, int score) { this->m_Name = name; this原创 2020-12-26 01:10:04 · 107 阅读 · 0 评论 -
2020-12-23
001 deque 容器_排序 sort 算法非常使用 ,使用时包含文件algorithm即可 #include<iostream> #include<deque> using namespace std; #include<algorithm> void printDeque(const deque<int>& d) { for (deque<int>::const_iterator it = d.begin(); it != d.原创 2020-12-23 23:47:47 · 77 阅读 · 0 评论 -
STL string 容器
string 插入和删除 #include<iostream> #include<string> using namespace std; void test01() { string str = "hello"; //插入 str.insert(1, "111"); cout << str << endl; //删除 str.erase(1, 3); cout << str << endl; } int mai原创 2020-12-23 17:20:24 · 71 阅读 · 0 评论 -
STL vector 容器
01 vector 容器 #include<iostream> using namespace std; #include<vector> void printVector(vector<int>& v) { for (vector<int>::iterator it = v.begin(); it != v.end(); it++) { cout << *it << " "; } cout << e原创 2020-12-23 17:16:14 · 64 阅读 · 0 评论 -
STL(STL初识--vector存放内置数据类型,STL 初识-vector存放自定义数据类型,STL 初识 _容器嵌套容器)
01 STL初识–vector存放内置数据类型 #include<iostream> using namespace std; #include<vector> #include <algorithm> //标准算法的头文件 /* 容器:vector 算法:for_each 迭代器:vector<int>::iterator */ void MyPrint(int val) { cout << val << endl;原创 2020-12-22 17:18:49 · 141 阅读 · 0 评论 -
模板 (函数模板语法 ,类模板与函数模板的区别,:函数模板案例,普通函数与函数模板的区别,普通函数与函数模板调用规则,模板的局限性,类模板分文件编写.cpp,Person.hpp,类模板与友元)
01:函数模板语法: #include<iostream> using namespace std; //交换两个整型函数 void swapInt(int &a ,int & b) { int temp = a; a = b; b = temp; } //交换两个浮点型函数 void swapDouble(double& a, double& b) { double temp = a; a = b; b = temp; } //函数模原创 2020-12-22 13:52:07 · 120 阅读 · 0 评论 -
cpp (基于多态的职工管理系统)
源文件: 职工管理系统.cpp: #include<iostream> #include"WorkerManager.h" #include<string> #include"worker.h" #include"employee.h" #include "manager.h" #include"boss.h" using namespace std; int main() { //测试代码 /*Worker* worker = NULL; worker = new Emp原创 2020-12-19 23:54:30 · 472 阅读 · 3 评论 -
cpp文本文件(读文件,写文件)
文本文件: 1:文件操作必须包含头文件fstream 2: 创建流对象:写文件可以利用ofstream,或者fstream类 ( 读文件 用 ifstream 或者 fstream) 3:打开文件时候需要指定操作文件的路径 ,以及打开方式 格式: ofs.open(“文件路径” , 打开方式) 4:利用<<可以向文件中写数据 格式: ofs <<“写入数据” 5:操作完毕,要关闭文件 格式:ofs.close(); 打开方式: ios::in 为读文件而原创 2020-12-17 20:32:06 · 2845 阅读 · 0 评论 -
多态 案例三 (电脑组装)
#include<iostream> using namespace std; //抽象不同零件类 //抽象CPU类 class CPU { public: virtual void calculate() = 0; }; class VideoCard { public: virtual void display() = 0; }; class Memory { public: virtual void storage () = 0; }; class Compu原创 2020-12-17 13:49:06 · 230 阅读 · 0 评论 -
cpp多态 (虚析构,纯虚函数)
01: #include<iostream> using namespace std; //制作饮品 class AbstactDrinking { public: //煮水 virtual void Boil() = 0; //冲泡 virtual void Brew() = 0; //倒入水中 virtual void PourInCup() = 0; //加入辅料 virtual void PutSomething() = 0; //制作饮品 void makeDr原创 2020-12-16 13:42:13 · 311 阅读 · 0 评论 -
cpp 多态 (虚函数 纯虚函数 抽象类)
1: 地址早绑定 在编译阶段确定函数地址 如果想执行让猫说话,那么这个函数地址就不能提前绑定,需要在运行阶段进行绑定,地址晚绑定 动态多态满足条件 1:有继承关系 2:子类重写父类的虚函数 重写:返回值类型相同 函数名 参数列表 完全相同 动态多态的使用: 父类的指针或者引用 指向子类对象 #include<iostream> using namespace std; class Animal { public: //虚函数 virtual void speak() { cout &原创 2020-12-15 18:10:17 · 234 阅读 · 0 评论 -
C++继承与派生
1: 子类 需要继承Base和Base2 语法: class 子类:继承方式 父类1,继承方式 父类2 当父类中出现同名成员,需要加作用域区分 #include<iostream> using namespace std; class Base1 { public : int m_A; Base1() { m_A = 100; } }; class Base2 { public: int m_A; Base2() { m_A = 200; } }; //子类 需要继承原创 2020-12-14 23:36:58 · 92 阅读 · 0 评论 -
CPP中的继承关系
//继承的好处:减少代码的重复率 /* * 语法:class 子类 :继承方式 父类 子类 也称为派生类 基类 也称为基类 */ //继承中的对象模型 #include<iostream> using namespace std; class Base { public: int m_A; protected: int m_B; private: int m_C; }; class Son :public Base { public: int m_D; }; void原创 2020-12-10 22:55:33 · 434 阅读 · 0 评论 -
内存模型 new运算符操作
1:new运算符操作 #include<iostream> using namespace std; int* func() { //堆区创建整型数据 //new返回是 该数据类型的指针 int* p = new int(10); return p; } void test01() { int* p = func(); cout << *p << endl; cout << *p << endl; cout << *p原创 2020-11-27 22:34:48 · 121 阅读 · 1 评论 -
通讯录管理系统
#include<iostream> #define MAX 1000 using namespace std; #include<string> //设计联系人结构体 struct Person { string m_Name; string m_phone; int m_Sex; int m_Age; string m_Address; }; //设计通讯录结构体 struct Addressbooks { //保存联系人数组 struct Person pers原创 2020-11-26 23:56:40 · 152 阅读 · 0 评论 -
结构体案例二:英雄
#include<iostream> using namespace std; #include<string> //创建结构体 struct Hero { string name; int age; string sex; }; void bubbleSort(struct Hero HeroArray[],int len) {//冒泡排序 for (int i = 0; i < len-1; i++) { for (int j = 0; j < le原创 2020-11-25 22:45:22 · 150 阅读 · 0 评论 -
指针
//const的使用场景 //#include // using namespace std; // // struct student // { // int age; // }; // // //const使用场景 // void printStudent(const student *s) //使用指针可以减少内存的开销,不用复制全部数据。加const防止函数体中的误操作 // { // cout << “年龄为” << s->age << endl;原创 2020-11-25 13:40:21 · 49 阅读 · 0 评论 -
C++(值传递,引用传递,地址传递 指针配合函数和数组 结构体 结构体指针)
一:值传递,引用传递,地址传递 #include<iostream> using namespace std; //值传递 void swap(int a, int b) { int temp = a; a = b; b = temp; cout << "使用值传递a的值为:" << a << endl; cout << "使用值传递b的值为:" << b << endl; cout << "----原创 2020-11-23 22:58:48 · 926 阅读 · 0 评论 -
分文件编写
在源文件中创建.cpp的源文件 #include<iostream> #include"swap.h" using namespace std; void swap(int a, int b)//在源文件中写函数的定义 { int temp = a; a = b; b = temp; cout << "a=" << a << endl; cout << "b=" << b << endl; } int mai.原创 2020-11-21 18:09:01 · 267 阅读 · 0 评论 -
C++(遍历数组,找最值,交换元素,统计分数)
//三只小猪称体重 /* #include<iostream> using namespace std; int main() { int arr[5] = { 12,18,11,16,10 }; int max = 0; for (int i = 0; i < 5; i++) { if (arr[i] > max) { max = arr[i]; } } cout << "最重的猪的体重为:" << max <原创 2020-11-20 22:31:12 · 455 阅读 · 0 评论 -
2020-11-17
#include<iostream> using namespace std; const float PI = 3; class Circle { public: Circle(float r); //构造函数 float area(); //成员函数 private: float radius; }; float Circle::Circle(float r){//成员函数的实现 float radius; radius = r; retur原创 2020-11-17 21:40:22 · 46 阅读 · 0 评论 -
2020-11-16
/* 静态成员变量两种访问方式 1:通过对象 类名 对象名; 对象名.函数名; 2:通过类名 类名::函数名; */ #include <iostream> using namespace std; class Person { public : static int m_A; int m_B; /*静态成员函数的特点 * 1:程序共享一个函数 * 2:静态成员函数只能访问静态成员变量 */ static void func() { cout << "fu原创 2020-11-16 17:39:44 · 41 阅读 · 0 评论 -
C++
/* //4-9 #include<iostream> using namespace std; class Rectangle { // 设计一个矩形类 public: void setX1(int x1) { m_X1 = x1; } int getX1() { return m_X1; } void setY1(int y1) { m_Y1 = y1; } int getY1() { return m_Y1; } void setX2(int x2)原创 2020-11-15 23:43:25 · 90 阅读 · 0 评论