
c++
那就等雨停吧
-
展开
-
c++ STL中unique函数的模拟实现
切记:传入unique函数中的数组必须有序!vector<int>::iterator unique(vector<int> &a){ int j = 0; for (int i = 0; i < a.size(); i++) { if (!i || a[i] != a[i - 1]) // !i 作用:第一个元素直接放到数组中 a[j++] = a[i]; } return a.begin() + j;}...原创 2021-10-24 15:33:07 · 1834 阅读 · 0 评论 -
日期类(仅提供类的实现,主函数没写)
#include<iostream>using namespace std;int Year[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };class Date{public: Date(int year1 = 1900, int month1 = 1, int day1 = 1) // 全缺省的构造函数 { if (year1 >= 0 && month >= 1 &.原创 2021-07-17 14:17:20 · 94 阅读 · 0 评论 -
c++类和对象(二)(this指针,默认成员函数)
隐藏的this指针#include<iostream>using namespace std;class Date{public: //编译会增加一个隐含的参数->void Init(Date* this,int year,int month,int day) void Init(int year, int month, int day) { _year = year; _month = month; _day = day; }private: int原创 2021-07-13 11:13:35 · 225 阅读 · 0 评论 -
c++类和对象(一)(面向对象与面向过程的区别,写一个类,计算类的大小)
1.面向过程和面向对象的初步认识c语言是面向过程的,关注的是过程,分析出求解问题的步骤,通过函数调用逐步解决问题。c++是基于面向对象的,关注的是对象,将一件事情拆分成不同的对象,靠对象之间的交互完成。举个栗子:外卖系统面向过程:下单、接单、送餐(关注的是这三个过程,实现这三个过程的函数)面向对象:客户、商家、骑手(关注的是这三个对象之间的关系)//c语言//比如定义一个栈struct Stack{ STDataType* a; int size;..原创 2021-06-14 19:48:43 · 121 阅读 · 0 评论 -
c++ point类(含输入和输出的重载)
【问题描述】定义类point,其中包括两个数据成员,均为int类型,为点的横坐标和纵坐标。类的成员函数如下:构造函数:包括两个参数,其两个参数的默认值为0。重载运算符+、-、==、!=+:两个点相应的坐标相加,比如(1,1)+(2,2)=(3,3)-:两个点相应的坐标相减,比如(2,2)-(1,1)=(1,1)==:两个点相应坐标如果相等,则结果为true,否则结果为false!=:两个点的两个坐标只要有一个不相等,则结果为true,否则结果为false...原创 2021-06-13 13:50:56 · 12480 阅读 · 0 评论 -
c++矩阵类
【问题描述】用指向指针的指针实现矩阵类matrix,成员方法如下:构造函数matrix(int m, int n):m为矩阵的行数,n为矩阵的列数,矩阵元素值按规律生成,即第i行第j列的元素赋值为按行优先顺序存放的元素的序号;例如,m=3,n=4, 则3行4列矩阵构造为:1 2 3 45 6 7 89 10 11 12m=2,n=5, 则2行5列矩阵构造为:1 2 3 4 56 7 8 9 10其他成员函数有3个(1)at(int i):返回按行...原创 2021-06-13 13:26:52 · 1292 阅读 · 0 评论 -
c++继承多态 年级类
//【C++继承多态】年级类#include<iostream>#include<string>using namespace std;int N;class student{public: void set(string name, int age, int score) { Name = name; Age = age; Score = score; } void display() { cout << Name << '.原创 2021-06-01 20:51:41 · 167 阅读 · 0 评论 -
【c++运算符重载】时间类(24小时)可实现秒数前缀--和后缀--
#include<iostream>using namespace std;class time24{public: time24(int h = 0, int m = 0, int s = 0) :hours(h), minutes(m), seconds(s){} void set(int h, int m, int s); void get(int &h, int &m, int &s); time24 operator-(const int &a.原创 2021-05-22 10:35:10 · 447 阅读 · 0 评论