Nup=up*r1.up;
i=Maxdivisor(Nup,Ndown);
return Rational(Nup/i,Ndown/i); }
void Rational::showNomal() {
cout< main() { Rational r1(4,14); Rational r2(5,8); Rational r; cout<<\ r1.showNomal(); cout<<\ r2.showNomal(); r=r1*r2; cout<<\ r.showNomal(); return 0; } 作业五 定义包含时、分、秒信息的时间类Time,并实现时间对象的流输入输出,格式为 时:分:秒,如23:35:18。 (本题总分10分,类结构4分,输入输出函数实现各2分,主函数2分。程序结构完整,有不妥之处,酌情扣分。) #include \ #include class Time { friend ostream & operator<<(ostream &output, Time &t); friend istream & operator>>(istream &input, Time &t); public: Time(int h=0, int m=0, int s=0); private: int hour, minute, second; }; Time::Time (int h, int m, int s) { hour=h; minute=m; second=s; } ostream & operator<<(ostream &output, Time &t) { output << t.hour << \ return output; } istream & operator>>(istream &input, Time &t) { char a,b; input >> t.hour >> a >> t.minute >> b >> t.second ; return input; } int main() { Time t; cout << \:mm:ss: \cin >> t;//调用自己定义的运算符重载函数operator>>(cin,t) cout << \ cout << t << endl;//调用自己定义的运算符重载函数operator<<(cout,t) return 0; } 作业六 对于下面的类MyString,要求重载一些运算符后可以计算表达式:a = b + c, 其中a、b、c都是类MyString的对象,+用以实现两个字符串对象的连接。 请重载相应的运算符并编写程序测试。(本题总分10分,类结构4分,重载函数实现4分,主函数2分。程序结构完整,有不妥之处,酌情扣分。) class MyString { public: MyString(char *s) { str = new char[strlen(s)+1]; strcpy(str, s); } ~MyString() { delete []str; } private: char *str; }; 标记单词或重新标记。