当前位置: 首页 > news >正文

0901作业+思维导图梳理

一、作业

1、代码

#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
class Mystring
{
public://无参构造Mystring():size(128),len(0){str = new char[size];cout<<"无参构造完成"<<endl;}//有参构造Mystring(const char *s):size(128),len(0){this->str = new char[size];strcpy(str,s);len=strlen(str);cout<<"有参构造完成"<<endl;}//析构函数~Mystring(){clear();  //释放指针的空间cout<<"析构函数"<<endl;}//operator=,赋值函数Mystring &operator=(const char* s){strcpy(this->str,s);this->len = strlen(s);return *this;}//at函数char at(int n){return str[n];}//operator[],访问指定字符char operator[](int n){return str[n];}//data函数,返回指向字符串首字符的指针char* data(){return &str[0];}//c_str函数string c_str(){return str;}//判空函数bool empty(){if(this->str==NULL){return true;}return false;}//size函数int mysize(){return len;}//length函数int length(){return len;}//capacity函数int capacity(){return size;}//clear函数void clear(){delete str;}//push_back函数void push_back(const char s){str[len]=s;len++;}//pop_back函数void pop_back(){this->str[len-1]=0;len--;}//operator+=Mystring &operator+=(const Mystring &s){this->len =this->len+s.len;strcat(this->str,s.str);return *this;}//operator+const Mystring operator+(const Mystring &s)const{Mystring temp;temp.len=this->len+s.len;temp.str = strcat(this->str,s.str);return temp;}//operator==bool operator==(const Mystring &s)const{return strcmp(this->str,s.str);}//operator!=bool operator!=(const Mystring &s)const{return ~strcmp(this->str,s.str);}//operator<bool operator<(const Mystring &s)const{int num = strcmp(this->str,s.str);if(num<0){return 1;}return 0;}//operator>bool operator>(const Mystring &s)const{int num = strcmp(this->str,s.str);if(num>0){return 1;}return 0;}//operator>=bool operator>=(const Mystring &s)const{int num = strcmp(this->str,s.str);if(num>=0){return 1;}return 0;}//operator<=bool operator<=(const Mystring &s)const{int num = strcmp(this->str,s.str);if(num<=0){return 1;}return 0;}//operator<<friend ostream & operator<<(ostream &L,const Mystring &R);//operator>>friend istream & operator>>(istream &L,Mystring &R);void show(){cout<<str<<endl;cout<<len<<endl;cout<<size<<endl;}
private:char *str;     //记录c风格的字符串int size  ;      //记录字符串的实际长度int len;    //记录字符串的实际长度
};//operator<<
ostream & operator<<(ostream &L,const Mystring &R)
{L<<R.str<<endl;return L;
}
//operator>>
istream & operator>>(istream &L,Mystring &R)
{L>>R.str;R.len=(int)strlen(R.str);return L;
}int main()
{Mystring s1;  //无参构造Mystring s2;       //无参构造cin>>s1;  //输入函数s2=s1;    //赋值函数cout<<s2; //输出函数Mystring s3("hello");  //无参构造s3+=s2;cout<<s3;cout<<(s3>s2)<<endl; //关系运算符验证Mystring s4 = (s2+s3);//算术运算符验证cout<<s4;return 0;
}

2、运行结果

二、思维导图


http://www.mrgr.cn/news/18505.html

相关文章:

  • Windows记事本打开某些文件后假死如何处理
  • Halcon基于相关性的模板匹配
  • Linux如何关闭终端不中断任务
  • yolo-world开放词汇检测onnxruntime和tensorrt推理
  • DL/T645-2007_Part2(负荷记录数据标识编码表)
  • 传统CV算法——图像特征算法之角点检测算法
  • Nmap使用教程图文教程(超详细)零基础入门到精通,收藏这一篇就够了
  • GCViT实战:使用GCViT实现图像分类任务(一)
  • 深入理解Python OpenCV图像处理
  • 捷邻系统小程序的设计
  • 华为 HCIP-Datacom H12-821 题库 (4)
  • KingbaseES 在K8s中部署报错:invalid value for parameter “port“
  • 人生不将就:互联网时代的探索者
  • 关于CUDA版本查看的问题
  • 【机器学习】图像处理与深度学习利器:OpenCV实战攻略全面解析
  • Python | Leetcode Python题解之第392题判断子序列
  • 手机播放DVD:VLC播放器(直接下载apk)
  • PTA整数的分类处理
  • 接口调用方式 -- 总结
  • Cortex-A7的运行模式和寄存器组详解