填空题 C++
题号 #2657322

本程序调用构造函数实现字符串对象的初始化。调用重载运算符”+”把两个字符串拼接,并通过重载运算符“>”来实现字符串的比较运算。
#include<iostream.h>
#include<string.h>
class string
{     char *str;
public:
       string(char *s=0)
       {
              if(_(14)_){str=new char[strlen(s)+1]; strcpy(__(15)__);}
              else str=0;
       }
       friend string operator+(string &,string &);
       int operator>(string &);
       void show(){ if(str)cout<<str<<'\n'; }
};
string operator+(string &s1,string &s2)
{
       string t;
       t.str=____(16)_____;
       strcat(t.str,s2.str);
       ______(17)_______;
}
int string::operator>(string &s)
{
       if(strcmp(____(18)_____)>0)return 1;
       else return 0;
}
void main(void)

{
       string s1("southeast university"),s2("mechanical department");
       string s3; s3=s1+s2;
       s1.show(); s2.show(); s3.show();
       cout<<(s1>s2)<<'\n';
}

进入在线模考

参考答案

暂无

答案解析

(14) s
(15) str,s
(16) s1.str
(17) return t
(18) str,s.str

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考