
笔记
文章平均质量分 73
319天考研上岸
这个作者很懒,什么都没留下…
展开
-
运算符重载
实验目的:1.掌握C++语言多态性的基本概念2.掌握运算符重载函数的声明和定义方法实验结果如下:1.类外定义运算符重载函数2.友元运算符重载函数3.类内定义运算符重载函数代码如下:1.#includeusing namespace std;class Complex{public:double real;double imag;Complex(double real1=0,double imag1=0){real = real1;imag = imag1;}};C原创 2021-12-13 11:24:11 · 684 阅读 · 0 评论 -
6.继承下的构造函数域析构函数
实验目的:1.掌握派生类的声明方法和派生类构造函数的定义方法2.掌握不同方式下,构造函数与析构函数的执行顺序与构造规则运行结果:结果很明显:基类的构造函数先运行,派生类的构造函数后运行结束时,派生类的析构函数先运行,基类的析构函数后运行。代码如下:#include#includeusing namespace std;class MyArray{public:MyArray(int length);~MyArray();void Input();void Display(str原创 2021-12-13 10:27:15 · 868 阅读 · 0 评论 -
上机5继承派生
在这里插入图片描述在这里插入图片描述](https://img-blog.csdnimg.cn/4aabdf9a304541baa0c9eec5794e105f.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAbTBfNTM5OTcyMDg=,size_20,color_FFFFFF,t_70,g_se,x_16)1 无论哪种继承方式,基类中的私有成员在派生类中是不可以直接访问的2 派生属性=从严(原创 2021-12-06 11:23:13 · 491 阅读 · 0 评论 -
【无标题】
第四次实验代码:Part a:#includeusing namespace std;class Tr {public:Tr(int n){i = n;}void set_i(int n){i = n;}int get_i(){return i;}private:int i;};void sqr_it(Tr ob){ob.set_i(ob.get_i()ob.get_i());cout << “在函数sqr_it内,形参对象ob的数据成员的值为:原创 2021-11-29 00:05:28 · 86 阅读 · 0 评论 -
C++3-2实验
#include#includeusing namespace std;class Score {public:Score(){times = 2;}Score(int times1){times = times1;}-~Score(){}void InputScore(){cout <<times << endl;for (int i=0; i<times; i++){cout << “请输入学生姓名:” <<原创 2021-11-22 00:32:13 · 745 阅读 · 0 评论 -
第三次实验
第三次实验内容一本次实验学习了类和对象的基本应用,深刻理解了析构函数的含义和用法。代码如下:using namespace std;class Coordinate {public:Coordinate()//构造函数{times = 2; //默认值cout << “Coordinate construction1 called!” << endl; //标记}Coordinate(int times1)//构造函数的重载 带参数的构造函数{原创 2021-11-15 10:46:09 · 661 阅读 · 0 评论