c++
清欢0581
社会底层码农正一步步往上爬
展开
-
stack 栈容器的使用 满足的 数据结构是先进后出
#include<iostream>using namespace std;#include<stack>void test01(){ //创建一个stack容器 stack<int>s; //入栈 s.push(0); s.push(10); s.push(20); s.push(30); cout << "栈的大小:" << s.size() << endl;;// 栈满足先进后出 先放进去的元素在栈的底部原创 2021-06-02 19:18:01 · 140 阅读 · 1 评论 -
有五名歌唱选手参加比赛,共有十个评委对其打分 去掉其中最高分和最低分 利用随机数对其打分 并且输出得分最高者
#include<iostream>using namespace std;#include<vector>#include<string>#include<algorithm>#include<deque>#include<ctime>//评委打分案例//有五名歌唱选手参加比赛,共有十个评委对其打分 去掉其中最高分和最低分 获取其均值 均值大的人获胜class person{public: //构造函数 .原创 2021-06-01 21:26:29 · 1106 阅读 · 0 评论 -
deque容器 用法(ps:基本语法跟vector一样)
deque容器跟vector容器的区别:deque容器是双端容器 不存在容量大小 !(https://img-blog.csdnimg.cn/20210525203521679.png)#include<iostream>using namespace std;#include<deque>#include<algorithm>//deque容器跟vector容器差不多 deque容器是一个队列结构void printdeque(const deque&原创 2021-05-25 20:35:41 · 69 阅读 · 0 评论 -
vector容器的用法
#include<iostream>using namespace std;//vector容器初识 vector相当于一个数组容器#include<vector>#include<string>//创建一个vecto容器void test01(){ vector<int> v; //向容器中插入数据 v.push_back(10); v.push_back(20); v.push_back(30); v.push_back(40);原创 2021-05-24 21:03:02 · 278 阅读 · 0 评论 -
string容器的使用方法
#include<iostream>using namespace std;#include<string>#include<string>//string容器的赋值//string容器的补长 通过+=实现void test01(){ string str1 = "zhang"; str1 += "xiang"; cout << str1 << endl; string str2; str2.assign("pppp原创 2021-05-20 20:31:44 · 81 阅读 · 0 评论 -
职工管理系统之添加职工
//workermanager.h#pragma once//防止头文件重复使用#include<iostream>#include"worker0.h"#include"manager.h"#include"boss.h"#include"employ.h"using namespace std;class workermanger{public: //workermanger();//构造函数 ~workermanger();//析构函数 void exitsys原创 2021-05-18 20:18:42 · 263 阅读 · 2 评论 -
计算机运行(多态语法总结)
//多态语法总结 父类指针指向子类成员 子类成员重写父类虚函数#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()原创 2021-04-29 20:23:05 · 68 阅读 · 0 评论 -
多态实现编写一个计算器
//多态实现一个计算器//多态实现计算器的好处//1.不用改动源码//2.只需对源码进行扩充或删除 不需要改动//3.多态的实习语法//父类的指针或引用指向子类的函数//base *s=new 子类名//通过s->访问子类的成员和子类的函数//用完记得销毁new栈区的内存 防止内存泄漏#include<iostream>using namespace std;#include<string>#include<cmath>class Abst原创 2021-04-26 21:23:07 · 620 阅读 · 0 评论 -
自制简单计算器
//写一个计算器//注释的部分为不是自定义输入数据时的计算器#include<iostream>using namespace std;#include<string>class calculator{public: void printin(); /*void printout();*/ friend void test01(); float getrusult(string oper);private:float a; float b; float s原创 2021-04-27 20:33:14 · 121 阅读 · 0 评论 -
重载加号运算符使其能进行矩阵相加
//重载+号运算符 使其两个矩阵相加//矩阵的输入输出都需要使用for循环 行和列的循环#include<iostream>using namespace std;class mix{public: friend mix operator+(mix&, mix&); void printin(); void printout();private: int arr[2][3];};//输入数据void mix::printin(){ cout <原创 2021-04-27 20:30:07 · 522 阅读 · 1 评论 -
运算符的重载
#include<iostream>using namespace std;class integer{public: friend ostream& operator<<(ostream& cout, integer myint); //重载自增运算符++a integer& operator++()//为什么返回的是引用 引用的好处形成链接 为了一直对一个数据进行递增 { m_a++; return *this; } //重载原创 2021-04-27 20:28:20 · 34 阅读 · 0 评论 -
分别用引用和指针指向多态的子类成员
//多态实现一个饮料制作//n的全排列#include<iostream>using namespace std;class abstract{public:virtual void makedrinking() = 0;};class makecoffee :public abstract{public: virtual void makedrinking() { cout << "第一步:烧水" << endl; cout <&l原创 2021-04-27 19:53:00 · 54 阅读 · 0 评论 -
判断点与圆的位置关系
#include<iostream>using namespace std;//创建一个点类class point{public: //设置点的坐标 void setm_x(int x) { m_x = x; } //获得点的坐标 int getm_x() {return m_x; } void setm_y(int y) { m_y = y; } //获得点的坐标 int getm_y() { return m_y; }private: //原创 2021-04-27 20:27:38 · 677 阅读 · 0 评论 -
n的全排列
//n的全排列#include<iostream>using namespace std;const int s = 10;//全排列的收纳盒int n;int arr[s]; int hashtable[s] = { false };//整型数组 与布尔数组相互转化void GE(int index){ //跳出循环的条件//递归求全排列 for (int x = 1; x <= n; x++) { if (hashtable[x] == false)//第一个原创 2021-04-27 20:31:02 · 131 阅读 · 0 评论 -
计算平方
#include<iostream>using namespace std;int main(){ //a代表我输入的数 int a; cin >> a; //i表示循环 i且代表数的指数 通过这个我能求某个数的某个次方 for (int i = 1; i < 20; i++) { //static为静态变量 初值为1,第一次之后变成2,不会释放 static long sum = 1; // static long sum=2;第二次循环后原创 2021-04-27 20:31:42 · 59 阅读 · 0 评论 -
商品售价问题
#include<iostream>using namespace std;class shop{public: shop(char n, int q, int p) :num(n), quantity(q), price(p) {}; friend float sum(shop& s);private: char num; int quantity; int price;};float sum(shop& s){ int sum = 0; if (原创 2021-04-27 20:29:01 · 157 阅读 · 0 评论