首頁| 新聞| 娛樂| 游戲| 科普| 文學| 編程| 系統| 數據庫| 建站| 學院| 產品| 網管| 維修| 辦公| 熱點
來源: 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迷你版本:小機
芭蕾舞蹈表演,真實美到極致
下午茶時間,悠然自得的休憩
充斥這繁華奢靡氣息的城市迪拜風景圖片
從山間到田野再到大海美麗的自然風景圖片
肉食主義者的最愛美食烤肉圖片
夏日甜心草莓美食圖片
人逢知己千杯少,喝酒搞笑圖集
搞笑試卷,學生惡搞答題
新聞熱點
疑難解答
圖片精選
網友關注