共享知识 分享快乐
}
string & string ::operator=(const string &s) { if(this==&s) return *this; delete xstring; xstring=new char [strlen(s.xstring)+1]; strcpy(xstring,s.xstring); return *this; } //6-4
#include 
String() { p=NULL;} String(char *str);
friend bool operator==(String &string1,String &string2); void display(); private: char *p; };
String::String(char *str) { p=str; }
void String::display()
{ cout<
bool operator==(String &string1,String &string2) { if(strcmp(string1.p,string2.p)==0) return true; else
return false; }
void compare(String &string1,String &string2) {
if(operator==(string1,string2)==0) { string1.display(); cout<<\ string2.display();
书籍是人类知识的总结,书籍是全世界的营养品。——莎士比亚
共享知识 分享快乐
} else cout<<\ }
int main()
{ String string1(\ compare(string1,string2); return 0; } //6-5
#include void main() {  String Str1(\ Str3=Str1+\ cout< 书籍是人类知识的总结,书籍是全世界的营养品。——莎士比亚  共享知识  分享快乐  #include class SmallCar:private Car {  int s_cnum; public:  SmallCar(int a,float b,int c):Car(a,b),s_cnum(c){}  void Sshow()  {   Cshow();   cout<<\载客量: \人次\ } };  class BigCar:private Car {  int b_cnum;  float b_cweight; public:  BigCar(int a,float b,int c,float d):Car(a,b),b_cnum(c),b_cweight(d){}  void Bshow()  {   Cshow();   cout<<\载客量: \人次\载重量T\ } };  int main() {  Car car(4,8);  SmallCar smallcar(8,16,8);  BigCar bigcar(16,32,16,32);  cout<<\汽车: \ 书籍是人类知识的总结,书籍是全世界的营养品。——莎士比亚  \ 共享知识  分享快乐   car.Cshow();  cout<<\小车: \ smallcar.Sshow();  cout<<\卡车: \ bigcar.Bshow();  return 0; } //7-2  #include class Rec:virtual public Shape {  float high,width; public:  Rec(float a,float b,float c,float d):Shape(a,b),high(c),width(d){}  void show()  {   cout<<\矩形 : \\n\  Shape::show();   cout<<\矩形宽、高: \ }  float GetArea()  {   show();   return high*width;  } };  class Ell:virtual public Shape {  float xx,yy; public:  Ell(float a,float b,float c,float d):Shape(a,b),xx(c),yy(d){}  书籍是人类知识的总结,书籍是全世界的营养品。——莎士比亚  共享知识  分享快乐   void show()  {   cout<<\椭圆 : \\n\  Shape::show();   cout<<\椭圆x轴,y轴: \ }  float GetArea()  {   show();   return 4*atan(1)*xx*yy;  } };  int main() {  Rec rec(5,5,5,5);  Ell ell(8,8,12,10);  Shape *s;  s=&rec;  cout<<\矩形的面积: \ s=ℓ  cout<<\椭圆的面积: \ return 0; } //7-3  #include          cout<<\ } };  class cat:public mammal {    int c; public:  cat(int j=0):c(j)  书籍是人类知识的总结,书籍是全世界的营养品。——莎士比亚