类与对象
ZengqiangChen
这个作者很懒,什么都没留下…
展开
-
定义一个MyString类,实现两个字符串相加。要求定义类的数据成员为字符指针,实现深拷贝函数。
#include using namespace std;class MyString{public:MyString(chars1, char s2);void add_str1_and_str2();void disp();private:char *str1;char str2;char str3;};MyString::MyString(char s1, char...原创 2019-04-19 12:18:30 · 4163 阅读 · 0 评论 -
两种方法:友元函数和一般函数 定义一个Point类,求两点之间的距离。
一般函数:#include #include using namespace std;class Point{public:Point(double a, double b);double Getx(){return x;};double Gety(){return y;};private:double x;double y;};Point::Point(double ...原创 2019-04-19 12:19:42 · 5194 阅读 · 0 评论 -
定义一个Book(图书)类,在该类定义中包括: (1)数据成员:bookname(书名)、price(价格)和number(存书数量)。 (2)成员函数:display(显示图书的情况;borrow(
#include #includeusing namespace std;class Book{public:Book(string name,int p,int n);//构造函数void borrow();//借书void restore();//还书void disp();//显示剩余产品数量private:string bookname;//书名int price;...原创 2019-04-19 12:21:22 · 32527 阅读 · 0 评论