首页| 新闻| 娱乐| 游戏| 科普| 文学| 编程| 系统| 数据库| 建站| 学院| 产品| 网管| 维修| 办公| 热点
来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩。)
注意: 总时间限制: 1000ms 内存限制: 65536kB
下面程序的输出是:
3+4i
5+6i
请补足Complex类的成员函数。不能加成员变量。
12345678910111213141516171819#include <iostream>#include <cstring>#include <cstdlib>using namespace std;class Complex {PRivate: double r,i;public: void Print() { cout << r << "+" << i << "i" << endl; }// 在此处补充你的代码};int main() { Complex a; a = "3+4i"; a.Print(); a = "5+6i"; a.Print(); return 0;}输入无输出3+4i5+6i样例输入1无样例输出123+4i5+6i代码:#include <iostream>#include <cstring>#include <cstdlib>using namespace std;class Complex {private: double r, i;public: void Print() { cout << r << "+" << i << "i" << endl; } // 在此处补充你的代码 //重载赋值运算符‘=’ //赋值运算符 “=” 只能重载为成员函数 //返回值类型应该为 Complex& Complex& Operator = (const char* s) { string str = s; int pos = str.find("+", 0); string strReal = str.substr(0, pos);//分离出代表实部的字符串 r = atof(strReal.c_str());//atof库函数能将const char*指针指向的内容转换成float string strImaginary = str.substr(pos + 1, str.length() - pos - 2);//分离出虚部代表的字符串 i = atof(strImaginary.c_str()); return *this; }};int main() { Complex a; a = "3+4i"; a.Print(); a = "5+6i"; a.Print(); return 0;}
无
1无样例输出123+4i5+6i代码:#include <iostream>#include <cstring>#include <cstdlib>using namespace std;class Complex {private: double r, i;public: void Print() { cout << r << "+" << i << "i" << endl; } // 在此处补充你的代码 //重载赋值运算符‘=’ //赋值运算符 “=” 只能重载为成员函数 //返回值类型应该为 Complex& Complex& Operator = (const char* s) { string str = s; int pos = str.find("+", 0); string strReal = str.substr(0, pos);//分离出代表实部的字符串 r = atof(strReal.c_str());//atof库函数能将const char*指针指向的内容转换成float string strImaginary = str.substr(pos + 1, str.length() - pos - 2);//分离出虚部代表的字符串 i = atof(strImaginary.c_str()); return *this; }};int main() { Complex a; a = "3+4i"; a.Print(); a = "5+6i"; a.Print(); return 0;}
123+4i5+6i代码:#include <iostream>#include <cstring>#include <cstdlib>using namespace std;class Complex {private: double r, i;public: void Print() { cout << r << "+" << i << "i" << endl; } // 在此处补充你的代码 //重载赋值运算符‘=’ //赋值运算符 “=” 只能重载为成员函数 //返回值类型应该为 Complex& Complex& Operator = (const char* s) { string str = s; int pos = str.find("+", 0); string strReal = str.substr(0, pos);//分离出代表实部的字符串 r = atof(strReal.c_str());//atof库函数能将const char*指针指向的内容转换成float string strImaginary = str.substr(pos + 1, str.length() - pos - 2);//分离出虚部代表的字符串 i = atof(strImaginary.c_str()); return *this; }};int main() { Complex a; a = "3+4i"; a.Print(); a = "5+6i"; a.Print(); return 0;}
代码:
#include <iostream>#include <cstring>#include <cstdlib>using namespace std;class Complex {private: double r, i;public: void Print() { cout << r << "+" << i << "i" << endl; } // 在此处补充你的代码 //重载赋值运算符‘=’ //赋值运算符 “=” 只能重载为成员函数 //返回值类型应该为 Complex& Complex& Operator = (const char* s) { string str = s; int pos = str.find("+", 0); string strReal = str.substr(0, pos);//分离出代表实部的字符串 r = atof(strReal.c_str());//atof库函数能将const char*指针指向的内容转换成float string strImaginary = str.substr(pos + 1, str.length() - pos - 2);//分离出虚部代表的字符串 i = atof(strImaginary.c_str()); return *this; }};int main() { Complex a; a = "3+4i"; a.Print(); a = "5+6i"; a.Print(); return 0;}
索泰发布一款GTX 1070 Mini迷
AMD新旗舰显卡轻松干翻NVIDIA
索泰发布一款GTX 1070 Mini迷你版本:小机
芭蕾舞蹈表演,真实美到极致
下午茶时间,悠然自得的休憩
充斥这繁华奢靡气息的城市迪拜风景图片
从山间到田野再到大海美丽的自然风景图片
肉食主义者的最爱美食烤肉图片
夏日甜心草莓美食图片
人逢知己千杯少,喝酒搞笑图集
搞笑试卷,学生恶搞答题
新闻热点
疑难解答
图片精选
网友关注