[問題] C++問題

看板C_and_CPP (C/C++)作者 (尊)時間16年前 (2009/04/26 23:17), 編輯推噓3(304)
留言7則, 5人參與, 最新討論串3/3 (看更多)
題目是這樣: 假設銀行帳號之class宣告如下: class BankAccount { public: BankAccount(char n[],double b, int t); // 設定帳號名稱,本金金額及其數 static void setInterestRate(double ir); // 設定利率,各帳號共用 double getNewBalance(); // 結算期末金額 void printAccount(); // 列印期初及滿期本金 private: static int count; //帳號個數統計 static double interestRate; //利率,以年利率計算 char name[20]; //帳號名稱 double balance; //本金 int term; //期數,以月計算 }; 試撰寫程式,利用上述class完成以下計算: 銀行利率之預設值為0.08(8%),Alice、Bob及Henry三人分別定存存入900、800及700元, 期數分別為10年、15年及20年,請在螢幕顯示帳號資料及滿期本金。若利率調整為 0.12(12%)情形又如何? 這是我寫的程式: #include <iostream> #include <cmath> using namespace std; class BankAccount { public: BankAccount(char n[],double b, int t); // 設定帳號名稱,本金金額及其數 static void setInterestRate(double ir); // 設定利率,各帳號共用 double getNewBalance(); // 結算期末金額 void printAccount(); // 列印期初及滿期本金 private: static int count; //帳號個數統計 static double interestRate; //利率,以年利率計算 char name[20]; //帳號名稱 double balance; //本金 int term; //期數,以月計算 }; int main(int argc, char *argv[]) { BankAccount Alice,Bob,Henry; cout<<"Alice存入900元,10年後為:"<<endl; Alice.BankAccount(Alice , 900 , 120 ); Alice.setInterestRate(0.08); cout<<Alice.getNewBalance(); cout<<"Bob存入800元,15年後為:"<endl; Bob.BankAccount(Bob , 800 , 180); Bob.setInterestRate(0.08); cout<<Bob.printAccount(); cout<<"Henry存入700元,20年後為:"<endl; Henry.BankAccount(Henry , 700, 240); Henry.setInterestRate(0.08); cout<<Henry.printAccount(); system("PAUSE"); return EXIT_SUCCESS; } BankAccount::BankAccount(char n[],double b, int t) { strcpy(name,n); balance=b; term=t; } static void BankAccount::setInterestRate(double ir) { interestRate = ir; } double BankAccount::getNewBalance() { double newBalance=0; newBalance = balance * pow( (1 + interestRate/12) , term); return newBalance; } void BankAccount::printAccount() { cout<<"帳號:"<<name<<"本金:"<<balance<<endl; } 都一直出錯想請教C++高手能否幫我解決一下謝謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 115.165.206.15

04/26 23:29, , 1F
cout<<Henry.printAccount();
04/26 23:29, 1F

04/26 23:29, , 2F
what's this ???
04/26 23:29, 2F

04/26 23:30, , 3F
直接放code上來找人幫看 說出錯 也不說錯在哪
04/26 23:30, 3F

04/26 23:37, , 4F
他說錯誤是no matching function for call to `BankAccoun
04/26 23:37, 4F

04/26 23:46, , 5F
你誤用了建構子
04/26 23:46, 5F

04/27 15:12, , 6F
建構子不是這樣用的
04/27 15:12, 6F

04/27 16:09, , 7F
在宣告的時候就要把引數丟進去了
04/27 16:09, 7F
文章代碼(AID): #19z7iDsW (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #19z7iDsW (C_and_CPP)